StochasticD
StochasticD in ProBuilder returns the %D signal line of the Stochastic oscillator, a smoothed 0 to 100 momentum measure. Syntax, parameters, examples.
Syntax
StochasticD[period, %Kperiod, %Dperiod](price1, price2, price3)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
period | integer | 14 | Lookback window used to compute the underlying %K line. |
%Kperiod | integer | 3 | Smoothing applied to %K. A value of 1 gives a Fast Stochastic; 3 or 5 gives a Slow Stochastic. |
%Dperiod | integer | 3 | Moving-average period applied to the smoothed %K to produce the %D line. |
price1, price2, price3 | price sources | high, low, close | Optional price series used in the range calculation. When omitted, the bar's high, low, and close are used. |
Formula
%K = 100 * (close - Lowest[period](low)) / (Highest[period](high) - Lowest[period](low))
%K smoothed = Average[%Kperiod](%K)
%D = Average[%Dperiod](%K smoothed)%D is therefore a moving average of a moving average of the raw range position, which keeps it inside 0 to 100 while filtering most single-bar noise.
How it works
The Stochastic oscillator consists of two lines. %K measures where the close sits inside the high-low range of the last period bars, from 0 (at the low) to 100 (at the high). %D, the line this function returns, is a moving average of %K and acts as its signal line.
Because %D lags %K by construction, crossings between the two lines are the oscillator's classic trigger: %K crossing above %D in the oversold zone is read as a buy-side signal, %K crossing below %D in the overbought zone as a sell-side signal. StochasticD provides the slower half of that pair; the faster half comes from the Stochastic function.
The %Kperiod parameter decides the flavour. With a value of 1 the underlying line is the raw Fast Stochastic; with 3 or 5 the result matches the Slow Stochastic convention, which most charting defaults use.
Examples
Example 1, Plotting %D with fixed thresholds (Indicator)
// Signal line of the stochastic with standard 14, 3, 3 settings
myD = StochasticD[14,3,3](close, high, low)
RETURN myD AS "%D", 80 AS "Overbought", 20 AS "Oversold"Computes the %D line from the closing, high, and low prices and plots it against the conventional 80 and 20 levels.
Example 2, %K and %D crossover strategy (ProBacktest)
// Classic stochastic crossover in the oversold zone
k = Stochastic[14,3](close)
d = StochasticD[14,3,3](close, high, low)
IF NOT OnMarket THEN
IF d < 20 AND k CROSSES OVER d THEN
BUY 1 CONTRACT AT MARKET
ENDIF
ELSIF k CROSSES UNDER d AND d > 80 THEN
SELL AT MARKET
ENDIFBuys when %K crosses above %D while the signal line is oversold and exits on the opposite crossing in the overbought zone.
Example 3, Overbought watchlist (ProScreener)
d = StochasticD[14,3,3](close, high, low)
// %D overbought and already curling down
turning = d < d[1]
SCREENER[d > 80 AND turning](d AS "Stoch %D")Lists instruments whose %D line is above 80 and has started to decline, candidates for exhaustion of the current advance.
Interpretation
| Zone | Range | Reading |
|---|---|---|
| Oversold | below 20 | Price has been closing near its range lows. %K crossing above %D here is the traditional buy trigger. |
| Neutral | 20 to 80 | No extreme. Crossings in this zone are weaker signals. |
| Overbought | above 80 | Price has been closing near its range highs. %K crossing below %D here is the traditional sell trigger. |
Divergences. A new price high unconfirmed by a new %D high, or a new price low unconfirmed by a new %D low, is read as momentum failing to keep pace with price. Because %D is smoothed, its divergences are fewer but generally more significant than those of raw %K.
Common errors and gotchas
- Price argument order. The optional price arguments replace the default high, low, and close series. Passing them in an unintended order changes the range calculation without any compiler error, so keep the source example's ordering when adapting it.
- Comparing %D against a differently parameterised %K. Crossover logic only makes sense if both lines share
periodand%Kperiod. MixingStochastic[14,3]withStochasticD[14,5,3]produces crossings with no standard meaning. - Overbought does not mean sell. In strong trends %D can hold above 80 for extended stretches. Acting on the zone alone, without a crossing or trend filter, fights the prevailing move.
- Extra smoothing on top of %D. %D is already a double-smoothed series. Wrapping it in another
Averageadds lag with little noise reduction left to gain.
Related instructions
Stochastic, the %K line that %D smooths.SmoothedStochastic, slow stochastic variant computed with summed ranges.SMI, stochastic momentum index centred on zero.RSI, momentum oscillator with the same 0 to 100 scale.Williams, %R oscillator, an inverted range-position measure.Average, the moving average used to derive %D from %K.DynamicZoneStochasticUp, adaptive overbought boundary.DynamicZoneStochasticDown, adaptive oversold boundary.
