Stochastic

Stochastic compares the closing price with its price range over a given period to identify overbought and oversold levels.

Role in the strategy

SlotAvailableRole
Entry PointNo—
Entry RuleYesFilters entries by the %K line direction or its level position.
Exit PointNo—
Exit RuleYesTriggers exits by the %K line direction or its level position.

The Stochastic produces conditions, not order prices. As an entry rule it is ANDed with the entry point and the other entry rules; as an exit rule it is ORed with the other exit rules. See Indicators for the slot semantics.

Logic rules

The indicator offers the standard oscillator rule set, evaluated on the %K line:

RuleLong signal is 1 whenShort signal is 1 when
Stochastic rises%K rose on the previous bar%K fell on the previous bar
Stochastic falls%K fell on the previous bar%K rose on the previous bar
Stochastic is higher than the Level line%K is above Level%K is below 100 − Level
Stochastic is lower than the Level line%K is below Level%K is above 100 − Level
Stochastic crosses the Level line upward%K crossed above Level from below%K crossed below 100 − Level from above
Stochastic crosses the Level line downward%K crossed below Level from above%K crossed above 100 − Level from below
Stochastic changes its direction upward%K formed a valley (down then up)%K formed a peak (up then down)
Stochastic changes its direction downward%K formed a peak (up then down)%K formed a valley (down then up)

The Level parameter sets the long threshold; the short threshold is always 100 − Level. With the default Level of 20, the long side uses 20 and the short side uses 80.

Parameters

ParameterTypeDefaultRangePurpose
%K Periodnumber51 to 1000Bars of the price range for the raw %K
%D Periodnumber31 to 1000Smoothing period of the %D (signal) line
Slowingnumber31 to 1000Additional smoothing of the %K line
Levelnumber200 to 100Long threshold; the short threshold is 100 − Level

Calculation

tech.Stochastic in engine/indicator-engine/tech.ts computes:

  • Raw %K = (Close − Lowest Low) / (Highest High − Lowest Low) × 100 over the %K Period, smoothed over the Slowing period.
  • %D = moving average of the %K over the %D Period.

The %K line is drawn in a separate chart pane; the rules use the %K line.

Backtesting

  • The rule is evaluated on the previous (closed) bar with the standard dead zone (SIGMA = 0.000001).
  • The indicator contributes only long/short signal arrays — it never changes the entry or exit order price.
  • An entry happens only when the entry point allows the direction and every entry rule passes; an exit happens when the exit point is reached and any exit rule passes.