Skip to main content

KDJ

Struct KDJ 

Source
pub struct KDJ { /* private fields */ }
Expand description

KDJ, the stochastic oscillator as used in Chinese securities analysis.

The raw stochastic value of each bar is RSV = (close - lowest low) / (highest high - lowest low) * 100 over the last period bars, or 50 when that window has no range. K and D are smoothed recursively, both starting from 50: K = ((k_smooth - 1) * K[-1] + RSV) / k_smooth and D = ((d_smooth - 1) * D[-1] + K) / d_smooth, so the default lengths of 3 weight the new value by a third. J = 3K - 2D. The first value is on bar period - 1; earlier bars are None. A bar with a non-finite high, low or close has no value and is left out: the windows span usable bars only, so every other bar is that of the series without it.

Implementations§

Source§

impl KDJ

Source

pub fn new(period: usize, k_smooth: usize, d_smooth: usize) -> Self

Create with period, k_smooth, d_smooth in bars, each clamped to at least one.

Source

pub fn with_colors(self, colors: Vec<Color32>) -> Self

Set plot colors in the order returned by Indicator::line_names.

Trait Implementations§

Source§

impl Clone for KDJ

Source§

fn clone(&self) -> KDJ

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for KDJ

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Indicator for KDJ

Source§

fn inputs(&self) -> Vec<StudyInput>

Current editable inputs. A host study can supply the same schema as built-ins.
Source§

fn set_input(&mut self, id: &str, value: InputValue) -> Result<(), StudyError>

Change a calculation input, rejecting unknown ids with 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 name(&self) -> &str

Return the short display name of this indicator (e.g. "SMA", "RSI", "MACD").
Source§

fn desc(&self) -> &str

Return a human-readable description of what this indicator measures. Read more
Source§

fn calculate(&mut self, data: &[Bar])

Compute the indicator’s output from the given bar data. Read more
Source§

fn update(&mut self, data: &[Bar], from: usize)

Bring 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 more
Source§

fn is_incremental(&self) -> bool

Whether live updates avoid recomputing unaffected history. Causal studies do work independent of the series length; studies that redraw earlier legs or periods also revisit the bars whose output changes. Earlier corrections may recompute in full. Defaults to false.
Source§

fn values(&self) -> &IndicatorValues

Return the computed output columns, with NaN for missing values. Read more
Source§

fn colors(&self) -> Vec<Color32>

Return the plot colours and any extra palette entries used by fills or per-bar colouring. Read more
Source§

fn set_colors(&mut self, colors: Vec<Color32>)

Replace all line colors at once. Read more
Source§

fn is_overlay(&self) -> bool

Whether this indicator is drawn on the main price chart (overlay) or in a separate sub-pane. Read more
Source§

fn is_visible(&self) -> bool

Whether this indicator should currently be rendered. Read more
Source§

fn set_visible(&mut self, visible: bool)

Show or hide this indicator.
Source§

fn clone_box(&self) -> Box<dyn Indicator>

Clone this indicator into a new Box<dyn Indicator>. Read more
Source§

fn line_count(&self) -> usize

The number of output columns this indicator plots. Renderers draw lines 0..line_count(). Read more
Source§

fn line_names(&self) -> Vec<String>

Return display names for each line, used in chart legends. Read more
Source§

fn projections(&self) -> &[StudyProjection]

Sparse projected price bands, with fractional endpoints in future whitespace.
Source§

fn table(&self) -> Option<&StudyTable>

A labelled table of the latest study statistics, drawn independently of the plots.
Source§

fn has_settings(&self) -> bool

Whether this study stores presentation edits itself. Charts wrap other studies once.
Source§

fn projection_fill_color(&self, projection: &StudyProjection) -> Color32

Colour inside a projected price band.
Source§

fn plot_label_colors(&self, _line: usize) -> Option<(Color32, Color32)>

Optional background and text colours for captions on plotted markers.
Source§

fn marker_style(&self) -> Option<PlotStyle>

Optional presentation of crossing markers; absent uses directional triangles.
Source§

fn level_style(&self, _value: f64) -> LineStyle

Stroke pattern for a pane level at the given value.
Source§

fn level_fill_color(&self) -> Color32

Colour of the band between the outer pane levels.
Source§

fn plot_style(&self, line: usize) -> PlotStyle

Presentation defaults for a zero-based output line. Any line is accepted: one at or past 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 legend_visible(&self, line: usize) -> bool

Whether output 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

Whether plot 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

The output whose visibility in the style tab also applies to plot 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

Horizontal displacement in bars. Positive values draw into future whitespace. Values remain indexed by their source bar; missing bars still occupy a position.
Source§

fn plot_color(&self, line: usize, bar: usize) -> Option<Color32>

Optional per-bar colour, overriding the plot colour at a source bar.
Source§

fn provisional_after(&self, line: usize) -> Option<usize>

The last source bar whose value on a zero-based line is final. The segments after it can still move with later bars and are drawn dashed when the line is solid. None, the default, draws the whole line as styled.
Source§

fn plot_text(&self, line: usize, bar: usize) -> Option<String>

Optional text beside the shape a circle, cross or triangle plot draws at a source bar: under an upward triangle and over the other shapes, in the shape’s colour.
Source§

fn fills(&self) -> Vec<StudyFill>

Filled bands, painted beneath this study’s plots. Missing endpoints break a band.
Source§

fn plot_value(&self, line: usize, bar: usize) -> Option<f64>

Value at a displayed bar, accounting for the plot’s displacement.
Source§

fn settings(&self) -> StudySettings

Current applied presentation, initialized from the study’s own defaults.
Source§

fn snapshot_settings(&self) -> StudySettingsSnapshot

Capture editable inputs and presentation without copying calculated values. The chart presentation wrapper also retains visibility before interval filtering. Custom presentations can use super::StudySettingsSnapshot::capture with their global visibility toggle to do the same.
Source§

fn restore_settings( &mut self, snapshot: &StudySettingsSnapshot, ) -> Result<(), StudyError>

Restore a snapshot from this study. Recalculate against current data afterwards. The default applies changed inputs and presentation through 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>

Apply a complete edit atomically. Charts wrap studies in ConfiguredStudy, which validates inputs on a clone before replacing the calculation and presentation.
Source§

fn set_visible_range(&mut self, range: Range<usize>) -> bool

Visible source bars, end exclusive, supplied after pan, zoom and resize and before autoscaling. Returns whether values need recalculation. Direct callers may supply it too.
Source§

fn set_timeframe(&mut self, timeframe: Timeframe)

The chart’s current interval, supplied when added and when the interval changes.
Source§

fn set_bar_clock(&mut self, clock: &BarClock) -> bool

Source bar calendar, including the chart’s selected timezone and session anchor. Returns whether cached values must be recalculated. Direct callers default to UTC.
Source§

fn value_format(&self) -> StudyFormat

Units of this study’s values. Placement defaults preserve price overlays and numeric panes.
Source§

fn scale(&self) -> StudyScale

Scale used in the pane selected by is_overlay.
Source§

fn scale_mapping(&self) -> Option<PriceMap>

Price mapping supplied by the chart for a shared scale, independent of pane bounds. Custom presentation implementations can retain it to support shared scales.
Source§

fn set_scale_mapping(&mut self, mapping: Option<PriceMap>)

Updates the chart’s shared-scale mapping. None restores the ordinary pane mapping.
Source§

fn set_value_formatter( &mut self, formatter: Option<Arc<dyn PriceFormatter>>, ) -> bool

Replaces value formatting when supported by the presentation. None restores the declared units and precision. Returns false when this study owns its formatting.
Source§

fn format_value(&self, value: f64) -> String

Format a value using the declared units and current precision override.
Source§

fn format_plot_value(&self, line: usize, value: f64) -> String

Formats one output, including readouts whose units differ from the study’s scale. The default uses format_value.
Source§

fn precision(&self) -> Option<usize>

Decimal places for study readouts, or the format’s default precision.
Source§

fn data_requests(&self) -> Vec<StudyDataRequest>

Additional histories this study needs. The chart resolves defaults, requests history and live updates from its feed, and supplies them before recalculating the study.
Source§

fn data_start(&self, request: &StudyDataRequest) -> Option<DateTime<Utc>>

The oldest time this study reads from 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<'_>])

Update with requested histories. Studies using only chart bars keep the default. Pass 0 when a requested history changes; nonzero from retains the same requested histories and follows update’s unchanged-prefix contract.
Source§

fn source(&self) -> Option<StudySource>

The single price series this study reads, or 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])

Update using an aligned source column. Missing source values remain gaps. The default substitutes the source for OHLC and retains the bar’s other fields.
Source§

fn order_flow_inputs(&self) -> &[OrderFlowInput]

Order-flow sources this study reads: 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

Whether the study has results only with its 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

Apply the chart instrument’s time zone and trading session. Returns 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

The typed events the chart holds for its symbol, those given to 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

Rendering style of an overlay line. Defaults to a 1 px line in its configured colour. Any line is accepted, as for plot_style.
Source§

fn candles(&self) -> &[StudyCandle]

Candle bodies and wicks, rendered in place of line plots when nonempty. Source ranges and OHLCV remain available to hosts for per-bar readouts.
Source§

fn drawings(&self) -> &[Drawing]

Drawing geometry generated by this study, styled as plot 0, empty by default. Calculations belong in calculate; use tools whose renderer needs only their anchors and settings, such as trend lines, parallel channels, Fibonacci levels and pitchforks.
Source§

fn tpo(&self) -> Option<&TPOConfig>

Market Profile settings of a study whose session profiles the chart builds with 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]

Price bands painted beneath this study’s plots, stored per zone rather than per bar. Empty by default.
Source§

fn zones_cover_whole_bars(&self) -> bool

Whether each of 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]

Text beside study values, in order of 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

Draw 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>)

The decimal places the study’s presentation settings set for the prices in 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>

Price-row volume profiles intersecting a half-open visible source-bar range. Fixed and calendar profiles include their whole selected span, even offscreen bars. Visible-range studies recompute for this range; ordinary studies return no profiles.
Source§

fn markers(&self) -> &[IndicatorMarker]

Shapes attached to study values, empty by default.
Source§

fn extend_right(&self) -> bool

Extend the last two values of each overlay line to the plot’s right edge.
Source§

fn plot_label(&self) -> Option<(usize, String)>

An annotation beside the latest value of a zero-based overlay line.
Source§

fn set_color(&mut self, line_idx: usize, color: Color32)

Set the color of a single line by its zero-based index. Read more
Source§

fn pane(&self) -> StudyPane

Default separate-pane layout and reference levels, independent of the study name. 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

Changes placement between the main chart and a separate pane. Returns whether this study supports the change. The chart’s presentation wrapper does.
Source§

fn set_scale(&mut self, _scale: StudyScale) -> bool

Changes the 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

Volume plots use an independent zero-based scale: up columns, down columns and MA. Renderers size columns to 80% of the bar pitch and format values as volume.

Auto Trait Implementations§

§

impl Freeze for KDJ

§

impl RefUnwindSafe for KDJ

§

impl Send for KDJ

§

impl Sync for KDJ

§

impl Unpin for KDJ

§

impl UnsafeUnpin for KDJ

§

impl UnwindSafe for KDJ

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send + Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.