Stochastic
Stochastic compares the closing price with its price range over a given period to identify overbought and oversold levels.
Role in the strategy
| Slot | Available | Role |
|---|---|---|
| Entry Point | No | — |
| Entry Rule | Yes | Filters entries by the %K line direction or its level position. |
| Exit Point | No | — |
| Exit Rule | Yes | Triggers 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:
| Rule | Long signal is 1 when | Short 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
| Parameter | Type | Default | Range | Purpose |
|---|---|---|---|---|
| %K Period | number | 5 | 1 to 1000 | Bars of the price range for the raw %K |
| %D Period | number | 3 | 1 to 1000 | Smoothing period of the %D (signal) line |
| Slowing | number | 3 | 1 to 1000 | Additional smoothing of the %K line |
| Level | number | 20 | 0 to 100 | Long 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) × 100over 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.