Log in to see Cloud of Tags

Wealth-Lab Wiki


public static StochD Series(Bars bars, int period, int smooth) public StochD(Bars bars, int period, int smooth, string description)

Parameter Description

bars The Bars object
smooth The length of smoothing
period Indicator period


StochD returns the Stochastic %D indicator. StochD is a smoothed version of the Stochastic %K, StochK. Specify the length of smoothing desired in the smooth parameter. The indicator can range from 0 to 100. Values near 0 indicate that most of the recent price action closed near the days lows, and readings near 100 indicate that prices are closing near the upper range.

The Stochastic is a momentum indicator. The closing price tends to close near the high in an uptrend and near the low in a downtrend. If the closing price then slips away form the high or the low, then momentum is slowing. Stochastics are most effective in broad trading ranges or slow moving trends.

The %K and %D combination is called the fast stochastic. You can use the StochD indicator as the basis for creating a "Slow Stochastic" %K. To create a Slow Stochastic signal line, just take a moving average of the StochD.


StochD is not valid until Bar Number period + Smooth - 1.


  • StochD is used as a signal line for StochK. A buy is triggered when StochK crosses above StochD from a level typically below 30. A sell is triggered when StochK crosses below StochD from typically above 70.
  • Ranging markets, go long on bullish divergences, especially where the first trough is below 30.
  • Ranging markets, go short on bearish divergences, especially where the first peak is above 70.
  • Trending market, when either Stochastic line crosses below 30 (signal day), place a stop order to go long if prices rise above the high of the signal day or any subsequent day with a lower low. Place stop order below the low of the same day.
  • Trending markets, when either Stochastic line crosses above 70 (signal day), place a stop order to go short if prices falls below the low of the signal day or any subsequent day with a higher high. Place a stop loss order above the high of the same day.
  • Trending markets, Use trend following indicators to exit. Can take profits on divergences, if confirmed by the trend following indicator.


n = Number of periods, normally 5
S = Number of smoothing intervals, normally 3
%D = Slow Stochastic K, smoothed over S periods (not SMA smoothing)

HH[bar-j] = Highest High at [bar-j] over n periods
LL[bar-j] = Lowest Low at [bar-j] over n periods
C[bar-j] = Close at [bar-j]
∑ = Summation from j = 0 to S - 1 periods
Sum1 = ∑( C[bar-j] - LL[bar-j] )
Sum2 = ∑( HH[bar-j] - LL[bar-j] )
%D = 100 * Sum1 / Sum2

Known issues

(55091) Calculating StochD gets slower in geometric progression depending on smoothing. Building StochD using shorter lookback and smoothing period (e.g. 14,3) is fast, but slows down in geometric progression when larger periods are selected.
  • Workaround (for code-based Strategies):
    //DataSeries stochd = StochD.Series(Bars,period,smooth);
    DataSeries stochd = SMA.Series( StochK.Series(Bars,period), smooth);
  • Workaround (for rule-based Strategies):
    When speed matters, replace your long-term StochD(period,smooth) with corresponding StochK(period) used with SMA(smooth)


using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { // Simple system based on Slow Stochastic ChartPane StochPane = CreatePane( 30, true, true ); DataSeries SlowK = StochD.Series( Bars, 10, 3 ); DataSeries SlowD = SMA.Series( SlowK, 3 ); PlotSeries( StochPane, SlowK, Color.Purple, WealthLab.LineStyle.Solid, 2 ); PlotSeries( StochPane, SlowD, Color.Black, WealthLab.LineStyle.Solid, 2 ); for(int bar = 20; bar < Bars.Count; bar++) { if (!IsLastPositionActive) { if( CrossOver( bar, SlowK, SlowD ) & ( SlowKbar-1 < 20 ) ) BuyAtMarket( bar+1); } else { if( CrossOver( bar, SlowK, 80 ) ) SellAtMarket( bar+1, LastPosition ); } } } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.

ScrewTurn Wiki. Some of the icons created by FamFamFam.