pub struct ChartPatterns { /* private fields */ }Expand description
Automatic chart patterns: the formations of a PatternFamily, each with a toggle,
detected from swing pivots and marked on the bar that confirms them. Read the formations,
with their anchors, boundaries, direction and confirmation bar, from
formations.
§Rules
A swing pivot is a bar whose high (low) is greater (lower) than those of the strength
bars before it and at least (at most) those of the strength bars after it. It is known
strength bars later, and consecutive pivots of one kind keep the more extreme. A
formation is built from the last pivots, so it exists only once its last pivot is known.
A line through two pivots is projected forward. A formation is confirmed on the first bar
from the one that completes it onward whose close lies beyond its breakout boundary, and
is dropped if the close first crosses the opposite guard or the formation is older than
max_length bars. A bar with a non-finite price is skipped as if absent, and lengths
count the other bars. Every rule reads bars up to the confirmation bar only, so results
on a prefix of the history equal those of the full history up to that bar.
| Formation | Pivots | Rule |
|---|---|---|
| Bull flag | low, high, low, high, low | pole from the first to the second rises at least pole percent; the highs and the lows after the pole fall along nearly parallel lines (the end width within a quarter of the start width); both lows stay above the pole’s middle |
| Bear flag | mirror | the pole falls and the flag rises |
| Bull pennant | as the bull flag | the highs fall, the lows rise and the end width is at most three quarters of the start width |
| Bear pennant | as the bear flag | the same converging lines |
| Rectangle | 2 * touches alternating pivots | each boundary through its first and last pivot is flat, all its pivots within tolerance percent of it, and the height at least twice the tolerance |
| Ascending triangle | as the rectangle | flat upper boundary, rising lower boundary |
| Descending triangle | as the rectangle | falling upper boundary, flat lower boundary |
| Symmetrical triangle | as the rectangle | falling upper and rising lower boundary |
| Cup and handle | high, low, high, low | the rims differ by at most tolerance percent of their mean; the cup is at least depth percent deep below the mean rim, lasts between min_length and max_length bars and has its low in the middle half of that time; the handle pulls back from the right rim by at most handle percent of the cup depth over at most half the cup’s duration; confirms bullish above the higher rim, fails below the cup’s low |
| Inverted cup and handle | mirror | confirms bearish below the lower rim |
| Double top | high, low, high | the tops differ by at most tolerance percent; at least min_length bars apart; the valley at least depth percent below them; the neckline is the valley’s low; confirms bearish below it, fails above the higher top by more than tolerance percent |
| Double bottom | mirror | the neckline is the valley’s high; confirms bullish above it |
| Triple top | high, low, high, low, high | as the double top for all three tops and both valleys; the neckline is the lower valley |
| Triple bottom | mirror | the neckline is the higher valley |
| Head and shoulders | high, low, high, low, high | the shoulders differ by at most tolerance percent, the head is at least depth percent above each, each valley lies below its shoulder, the shoulders are between min_length and max_length bars apart; the neckline runs through the valleys and may slope; confirms bearish below it, fails above the head |
| Inverse head and shoulders | mirror | confirms bullish above the neckline |
A boundary is flat when it moves at most tolerance percent between the first and last
pivot. A flag or pennant spans at least min_length bars from its pole’s top and at most
max_length bars from the pole’s start; the others span between min_length and
max_length bars from their first pivot. A bull flag, bull pennant and ascending triangle
confirm bullish above their upper boundary; a bear flag, bear pennant and descending
triangle confirm bearish below their lower boundary. A
rectangle and a symmetrical triangle confirm in the direction of the break. A pennant’s
last four pivots also form a symmetrical triangle, which is then not reported, and a triple
top or bottom follows the double top or bottom of its first two tops. Each pivot
belongs to at most one formation of a kind. At most 16 pivots, 8 developing and 64
confirmed formations are kept.
§Outputs
Line 0 marks a bullish confirmation at the low of its bar, line 1 a bearish one at the high, each labelled with the abbreviations of the formations it confirms. Boundaries are also generated as drawings, dashed while developing; a reversal formation draws only its neckline or breakout level.
Implementations§
Source§impl ChartPatterns
impl ChartPatterns
Sourcepub fn new(family: PatternFamily) -> Self
pub fn new(family: PatternFamily) -> Self
Detect every formation of family with its conventional parameters.
Sourcepub fn with_patterns(self, keep: impl Fn(&str) -> bool) -> Self
pub fn with_patterns(self, keep: impl Fn(&str) -> bool) -> Self
Detect only the formations whose label, such as "Bull Flag", keep accepts.
Sourcepub fn with_geometry(
self,
strength: usize,
length: RangeInclusive<usize>,
tolerance: f64,
touches: usize,
) -> Self
pub fn with_geometry( self, strength: usize, length: RangeInclusive<usize>, tolerance: f64, touches: usize, ) -> Self
Set the bars on each side of a pivot (at least 1), the shortest and longest formation in bars, the price tolerance in percent and the pivots per boundary (2 to 8). Bounds are clamped, NaN to the bottom.
Sourcepub fn with_pole(self, percent: f64) -> Self
pub fn with_pole(self, percent: f64) -> Self
The smallest rise or fall of a flag or pennant pole, in percent; NaN counts as zero.
Sourcepub fn with_depth(self, depth: f64, handle: f64) -> Self
pub fn with_depth(self, depth: f64, handle: f64) -> Self
The smallest depth of a cup, of a valley between tops and of a head above its shoulders, in percent, and the largest pullback of a cup’s handle, in percent of the cup’s depth, each clamped into 0 to 100, NaN to 0.
Sourcepub fn formations(&self) -> Vec<Formation>
pub fn formations(&self) -> Vec<Formation>
The confirmed formations, oldest first, then the developing ones, from the last calculation. Developing formations are re-evaluated on every bar.
Trait Implementations§
Source§impl Clone for ChartPatterns
impl Clone for ChartPatterns
Source§fn clone(&self) -> ChartPatterns
fn clone(&self) -> ChartPatterns
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Indicator for ChartPatterns
impl Indicator for ChartPatterns
Source§fn inputs(&self) -> Vec<StudyInput>
fn inputs(&self) -> Vec<StudyInput>
Source§fn set_input(&mut self, id: &str, value: InputValue) -> Result<(), StudyError>
fn set_input(&mut self, id: &str, value: InputValue) -> Result<(), StudyError>
super::StudyError::UnknownInput
and wrong types and invalid values with super::StudyError::InvalidInput.
On success cached values are cleared; calculate again or let the chart refresh.Source§fn plot_style(&self, line: usize) -> PlotStyle
fn plot_style(&self, line: usize) -> PlotStyle
line_count, which renderers do not draw, still gets a style, so an
implementation must not panic on it. The default takes the line’s colour from
colors, white for a line without one, and its width from
line_style.Source§fn plot_text(&self, line: usize, bar: usize) -> Option<String>
fn plot_text(&self, line: usize, bar: usize) -> Option<String>
Source§fn name(&self) -> &str
fn name(&self) -> &str
"SMA", "RSI", "MACD").Source§fn desc(&self) -> &str
fn desc(&self) -> &str
Source§fn calculate(&mut self, data: &[Bar])
fn calculate(&mut self, data: &[Bar])
Source§fn update(&mut self, data: &[Bar], from: usize)
fn update(&mut self, data: &[Bar], from: usize)
values up to date after data[from..] changed or grew,
given that data[..from] is unchanged since the previous call. The values equal those of
calculate on the same data, bit for bit. After bars are
prepended, or after a setting of the study changed, pass 0; after bars are removed from
the end pass the new length. Read moreSource§fn is_incremental(&self) -> bool
fn is_incremental(&self) -> bool
false.Source§fn values(&self) -> &IndicatorValues
fn values(&self) -> &IndicatorValues
Source§fn drawings(&self) -> &[Drawing]
fn drawings(&self) -> &[Drawing]
calculate; use tools whose renderer needs only their anchors
and settings, such as trend lines, parallel channels, Fibonacci levels and pitchforks.Source§fn colors(&self) -> Vec<Color32>
fn colors(&self) -> Vec<Color32>
Source§fn set_colors(&mut self, colors: Vec<Color32>)
fn set_colors(&mut self, colors: Vec<Color32>)
Source§fn is_overlay(&self) -> bool
fn is_overlay(&self) -> bool
Source§fn line_names(&self) -> Vec<String>
fn line_names(&self) -> Vec<String>
Source§fn is_visible(&self) -> bool
fn is_visible(&self) -> bool
Source§fn set_visible(&mut self, visible: bool)
fn set_visible(&mut self, visible: bool)
Source§fn clone_box(&self) -> Box<dyn Indicator>
fn clone_box(&self) -> Box<dyn Indicator>
Box<dyn Indicator>. Read moreSource§fn projections(&self) -> &[StudyProjection]
fn projections(&self) -> &[StudyProjection]
Source§fn table(&self) -> Option<&StudyTable>
fn table(&self) -> Option<&StudyTable>
Source§fn has_settings(&self) -> bool
fn has_settings(&self) -> bool
Source§fn projection_fill_color(&self, projection: &StudyProjection) -> Color32
fn projection_fill_color(&self, projection: &StudyProjection) -> Color32
Source§fn plot_label_colors(&self, _line: usize) -> Option<(Color32, Color32)>
fn plot_label_colors(&self, _line: usize) -> Option<(Color32, Color32)>
Source§fn marker_style(&self) -> Option<PlotStyle>
fn marker_style(&self) -> Option<PlotStyle>
Source§fn level_style(&self, _value: f64) -> LineStyle
fn level_style(&self, _value: f64) -> LineStyle
Source§fn level_fill_color(&self) -> Color32
fn level_fill_color(&self) -> Color32
Source§fn legend_visible(&self, line: usize) -> bool
fn legend_visible(&self, line: usize) -> bool
line appears in the legend. Defaults to plot visibility; a study can
retain a labelled readout for a quantity excluded from its plot and scale by default.Source§fn plot_tagged(&self, line: usize) -> bool
fn plot_tagged(&self, line: usize) -> bool
line shows its last value in a tag on the price scale while the chart
shows study values. By default every plot of a study with up to four plots does and no
plot of a study with more, whose values stay in the legend, so that the tags leave the
scale’s tick labels readable. A study on a chart starts from this choice and keeps the
user’s in StudySettings::untagged_plots.Source§fn plot_output(&self, line: usize) -> usize
fn plot_output(&self, line: usize) -> usize
line, for a plot past
line_count that draws zones or candles for one of the outputs. The
default is line itself.Source§fn plot_offset(&self, line: usize) -> isize
fn plot_offset(&self, line: usize) -> isize
Source§fn plot_color(&self, line: usize, bar: usize) -> Option<Color32>
fn plot_color(&self, line: usize, bar: usize) -> Option<Color32>
Source§fn provisional_after(&self, line: usize) -> Option<usize>
fn provisional_after(&self, line: usize) -> Option<usize>
None, the
default, draws the whole line as styled.Source§fn fills(&self) -> Vec<StudyFill>
fn fills(&self) -> Vec<StudyFill>
Source§fn plot_value(&self, line: usize, bar: usize) -> Option<f64>
fn plot_value(&self, line: usize, bar: usize) -> Option<f64>
Source§fn settings(&self) -> StudySettings
fn settings(&self) -> StudySettings
Source§fn snapshot_settings(&self) -> StudySettingsSnapshot
fn snapshot_settings(&self) -> StudySettingsSnapshot
super::StudySettingsSnapshot::capture with their
global visibility toggle to do the same.Source§fn restore_settings(
&mut self,
snapshot: &StudySettingsSnapshot,
) -> Result<(), StudyError>
fn restore_settings( &mut self, snapshot: &StudySettingsSnapshot, ) -> Result<(), StudyError>
Self::apply_settings.
Returns an error if the snapshot is no longer accepted.Source§fn apply_settings(
&mut self,
inputs: &[(String, InputValue)],
settings: StudySettings,
) -> Result<(), StudyError>
fn apply_settings( &mut self, inputs: &[(String, InputValue)], settings: StudySettings, ) -> Result<(), StudyError>
ConfiguredStudy,
which validates inputs on a clone before replacing the calculation and presentation.Source§fn set_visible_range(&mut self, range: Range<usize>) -> bool
fn set_visible_range(&mut self, range: Range<usize>) -> bool
Source§fn set_timeframe(&mut self, timeframe: Timeframe)
fn set_timeframe(&mut self, timeframe: Timeframe)
Source§fn set_bar_clock(&mut self, clock: &BarClock) -> bool
fn set_bar_clock(&mut self, clock: &BarClock) -> bool
Source§fn value_format(&self) -> StudyFormat
fn value_format(&self) -> StudyFormat
Source§fn scale(&self) -> StudyScale
fn scale(&self) -> StudyScale
is_overlay.Source§fn scale_mapping(&self) -> Option<PriceMap>
fn scale_mapping(&self) -> Option<PriceMap>
Source§fn set_scale_mapping(&mut self, mapping: Option<PriceMap>)
fn set_scale_mapping(&mut self, mapping: Option<PriceMap>)
None restores the ordinary pane mapping.Source§fn set_value_formatter(
&mut self,
formatter: Option<Arc<dyn PriceFormatter>>,
) -> bool
fn set_value_formatter( &mut self, formatter: Option<Arc<dyn PriceFormatter>>, ) -> bool
None restores the
declared units and precision. Returns false when this study owns its formatting.Source§fn format_value(&self, value: f64) -> String
fn format_value(&self, value: f64) -> String
Source§fn format_plot_value(&self, line: usize, value: f64) -> String
fn format_plot_value(&self, line: usize, value: f64) -> String
format_value.Source§fn precision(&self) -> Option<usize>
fn precision(&self) -> Option<usize>
Source§fn data_requests(&self) -> Vec<StudyDataRequest>
fn data_requests(&self) -> Vec<StudyDataRequest>
Source§fn data_start(&self, request: &StudyDataRequest) -> Option<DateTime<Utc>>
fn data_start(&self, request: &StudyDataRequest) -> Option<DateTime<Utc>>
request, one of its
data_requests. A connected feed stops loading older
history of that series once it holds a bar at or before the earliest such time of the
studies reading it, and loads more when that time moves earlier. None, the default,
and a time before the chart’s first bar load the series back to that bar. Price-based
chart types such as Renko do not use the times and always load it back to that bar.Source§fn update_data(&mut self, data: &[Bar], from: usize, sources: &[StudyData<'_>])
fn update_data(&mut self, data: &[Bar], from: usize, sources: &[StudyData<'_>])
from retains the same requested
histories and follows update’s unchanged-prefix contract.Source§fn source(&self) -> Option<StudySource>
fn source(&self) -> Option<StudySource>
None for OHLC or multi-source studies.
Configured studies expose this as a Source input. Study references use chart ids and
undisplaced output columns; missing or cyclic references produce missing values.Source§fn update_source(&mut self, data: &[Bar], from: usize, source: &[f64])
fn update_source(&mut self, data: &[Bar], from: usize, source: &[f64])
Source§fn order_flow_inputs(&self) -> &[OrderFlowInput]
fn order_flow_inputs(&self) -> &[OrderFlowInput]
OrderFlowInputs of
fixed aggregations, footprints or books. A chart with a feed connects them before its
updates are coalesced, gives them its instrument’s tick size, applies the trade store’s
retention and the replay cutoff, and updates the study from the first bar that changed.
Hosts without a feed push events through the handles and recalculate. Several studies may
return the same source; it receives each event once.Source§fn needs_order_flow(&self) -> bool
fn needs_order_flow(&self) -> bool
order_flow_inputs, so that it cannot be calculated on the bars
of another interval or symbol, whose order flow the chart does not hold. The default is
whether it names any. A study that builds its results from the bars and refines them with
order flow where the chart holds it returns false, and keeps its Interval input.Source§fn set_instrument(&mut self, instrument: Option<&Instrument>) -> bool
fn set_instrument(&mut self, instrument: Option<&Instrument>) -> bool
true
if calculation settings changed and the caller must recalculate from bar 0.
The chart calls this on add and before calculation after its symbol or metadata changes.
None clears chart metadata and restores the study’s own settings.
Studies independent of instrument metadata keep the default.Source§fn set_time_scale_events(&mut self, events: &[TimeScaleEvent]) -> bool
fn set_time_scale_events(&mut self, events: &[TimeScaleEvent]) -> bool
Chart::set_time_scale_events, in the order supplied. Returns true if calculation
settings changed and the caller must recalculate from bar 0. The chart calls this on add
and before calculation. Studies that read no events keep the default.Source§fn line_style(&self, line: usize) -> IndicatorLineStyle
fn line_style(&self, line: usize) -> IndicatorLineStyle
plot_style.Source§fn candles(&self) -> &[StudyCandle]
fn candles(&self) -> &[StudyCandle]
Source§fn tpo(&self) -> Option<&TPOConfig>
fn tpo(&self) -> Option<&TPOConfig>
to_tpo_profiles and draws on the price pane, beside
each session’s bars, as it does for the TPO chart type. None by default.Source§fn zones(&self) -> &[StudyZone]
fn zones(&self) -> &[StudyZone]
Source§fn zones_cover_whole_bars(&self) -> bool
fn zones_cover_whole_bars(&self) -> bool
zones spans its bars from the left edge of the first to
the right edge of the last, as study candles do, rather than from the centre of the first
to the centre of the last. Off by default.Source§fn labels(&self) -> &[StudyLabel]
fn labels(&self) -> &[StudyLabel]
bar. The chart draws the labels near the visible
bars, in the colour of their plot, inside the plot area, so they never run under the
price axis. Empty by default. Keep the text from the last calculation: it is drawn every
frame.Source§fn labels_on_price(&self) -> bool
fn labels_on_price(&self) -> bool
labels on the main price chart, even when the study has its
own pane. Label prices use the main series’ scale. Off by default.Source§fn set_label_precision(&mut self, precision: Option<usize>)
fn set_label_precision(&mut self, precision: Option<usize>)
labels, None when they set none and the instrument’s decimals apply.
The text is written when the study calculates, so calculate again afterwards, as a chart
does after any settings edit. Studies without price labels keep the default.Source§fn volume_profiles(&self, visible: Range<usize>) -> Vec<StudyProfile>
fn volume_profiles(&self, visible: Range<usize>) -> Vec<StudyProfile>
Source§fn markers(&self) -> &[IndicatorMarker]
fn markers(&self) -> &[IndicatorMarker]
Source§fn extend_right(&self) -> bool
fn extend_right(&self) -> bool
Source§fn plot_label(&self) -> Option<(usize, String)>
fn plot_label(&self) -> Option<(usize, String)>
Source§fn set_color(&mut self, line_idx: usize, color: Color32)
fn set_color(&mut self, line_idx: usize, color: Color32)
Source§fn pane(&self) -> StudyPane
fn pane(&self) -> StudyPane
ConfiguredStudy returns its levels where its settings place
them, in their colours, and a hidden level in Color32::TRANSPARENT, which still bounds
the fill.Source§fn set_overlay(&mut self, _overlay: bool) -> bool
fn set_overlay(&mut self, _overlay: bool) -> bool
Source§fn set_scale(&mut self, _scale: StudyScale) -> bool
fn set_scale(&mut self, _scale: StudyScale) -> bool
scale used in the study’s pane.
Returns whether this study supports the change. The chart’s presentation wrapper does.Source§fn is_volume(&self) -> bool
fn is_volume(&self) -> bool
Source§fn line_count(&self) -> usize
fn line_count(&self) -> usize
0..line_count(). Read moreAuto Trait Implementations§
impl Freeze for ChartPatterns
impl RefUnwindSafe for ChartPatterns
impl Send for ChartPatterns
impl Sync for ChartPatterns
impl Unpin for ChartPatterns
impl UnsafeUnpin for ChartPatterns
impl UnwindSafe for ChartPatterns
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more