Indicators/probuilder · probacktest · proorder · proscreener

Stochastic

Stochastic in ProBuilder returns the %K line of the stochastic oscillator, a 0 to 100 momentum indicator. Syntax, parameters, formula, and worked examples.

Syntax

probuilder
Stochastic[N,K](price)

The source documentation also lists an extended form with up to three price series:

probuilder
Stochastic[N,K](price1, price2, price3)

By default the close is used for the %K calculation and the high and low bound the range.

Parameters

NameTypeDefaultDescription
Ninteger14Number of bars used to establish the high-low range for %K.
Kinteger3Smoothing period applied to %K. K = 1 gives the Fast Stochastic; K = 3 or 5 gives the Slow Stochastic.
priceprice sourcecloseThe series compared against the range. Optional additional series can replace the default high and low bounds.

Formula

code
raw %K = 100 * (price - Lowest[N](low)) / (Highest[N](high) - Lowest[N](low))
%K     = K-period moving average of raw %K

The raw value expresses the current price as a percentage of the N-bar range: 0 means price sits at the range low, 100 at the range high. The K parameter then smooths that series. The companion %D signal line is a further moving average of %K, available through StochasticD.

How it works

George Lane's stochastic oscillator rests on the observation that in upward momentum, closes tend to settle near the top of the recent range, while in downward momentum they settle near the bottom. Stochastic quantifies that tendency as a bounded 0 to 100 series, which makes readings comparable across instruments and timeframes.

Sensitivity is controlled from two directions: a shorter N makes the range window more reactive, and a larger K filters out more noise from the resulting line. The common presets are [14,3] for the slow variant and [14,1] for the fast one.

Because the function returns %K only, crossover logic against %D requires either StochasticD or a manual moving average of the %K output, as in the first example below.

Examples

Example 1, Overbought cross-down signal (Indicator)

probuilder
// Compare the stochastic to a 5-period average of itself
sto = Stochastic[10,3](close)
signal = average[5](sto)
if(sto > 80 AND sto[1] > signal[1] AND sto < signal) THEN
  overboughtSignal = 1
ELSE
  overboughtSignal = 0
ENDIF
RETURN overboughtSignal

Computes a 10-period stochastic smoothed over 3 bars, then flags the moment the line drops back below its own 5-period average while still in the overbought zone, a common exhaustion pattern.

Example 2, Oversold pullback entry in an uptrend (ProOrder)

probuilder
// Buy oversold stochastic readings above the long-term trend
trend = Average[200](close)
sto = Stochastic[14,3](close)

IF NOT LongOnMarket THEN
  IF close > trend AND sto < 20 THEN
    BUY 1 CONTRACT AT MARKET
  ENDIF
ELSE
  IF sto > 80 THEN
    SELL AT MARKET
  ENDIF
ENDIF

The 200-period average restricts entries to uptrends, the stochastic times the pullback, and the position exits once momentum swings to the opposite extreme.

Example 3, Oversold scan (ProScreener)

probuilder
// List instruments with a stochastic reading under 20
sto = Stochastic[14,3](close)
SCREENER[sto < 20](sto AS "Stochastic")

Returns every instrument in the watchlist currently in the oversold zone, with the stochastic value shown as a sortable column.

Interpretation

ZoneRangeReading
Oversold%K < 20Price is closing near the bottom of its recent range. In ranging markets this often precedes a bounce.
Neutral20 to 80No range extreme. The 50 line is sometimes used as a directional bias filter.
Overbought%K > 80Price is closing near the top of its recent range. Can persist for long stretches in strong uptrends.

Crossovers. %K crossing above %D inside the oversold zone is the textbook bullish trigger; crossing below %D in the overbought zone is the bearish counterpart.

Divergences. A new price high without a new stochastic high, or a new price low without a new stochastic low, is read by some traders as an early sign of fading momentum.

Common errors and gotchas

  • Missing second bracket argument. The function expects both values: Stochastic[14] is incomplete. Use Stochastic[14,3](close) or Stochastic[14,1](close) for the fast variant.
  • Confusing %K with %D. Stochastic returns the %K line only. Crossover strategies need StochasticD or a manual average of the output; comparing %K to itself produces no signal.
  • Extremes are not reversals. In a strong trend the oscillator can pin above 80 or below 20 for dozens of bars. Fading every extreme reading is the most common way stochastic systems fail live.
  • Range compression distortion. When the N-bar high and low are nearly equal, the denominator approaches zero and the line whipsaws violently. Very quiet markets produce unreliable readings.
  • StochasticD, the %D signal line for crossover logic.
  • SmoothedStochastic, pre-smoothed variant of the oscillator.
  • DynamicZoneStochasticUp, adaptive upper threshold instead of the fixed 80 line.
  • DynamicZoneStochasticDown, adaptive lower threshold instead of the fixed 20 line.
  • SMI, stochastic momentum index, a refinement centred on the range midpoint.
  • RSI, alternative bounded momentum oscillator.
  • Williams, %R oscillator, an inverted close relative of the stochastic.
  • Average, used to build custom signal lines from %K.