StochD

Modified on 2017/08/22 13:31 by Eugene — Categorized as: Standard Indicators

Syntax

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

Description

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.

Remarks

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

Interpretation


Calculation

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.

Example

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 ) & ( SlowK[bar-1] < 20 ) ) BuyAtMarket( bar+1); } else { if( CrossOver( bar, SlowK, 80 ) ) SellAtMarket( bar+1, LastPosition ); } } } } }