Syntax
public static StochK Series(Bars source, int period)
public StochK(Bars source, int period, string description)
Parameter Description
source |
The Bars object |
period |
Indicator period |
Description
StochK returns the Stochastic Oscillator %K. The Stochastic Oscillator measures how much price tends to close in the upper or lower areas of its trading range. 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.
Interpretation
The classic way to interpret the Stochastic is to wait for %K to reach an extreme level. A level above 70 typically indicates an overbought condition, while below 30 indicates an oversold level. While these penetrations of extreme levels indicate a warning, the actual buy/sell signals occur when %K crosses %D,
StochD.
- 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.
Calculation
n |
= Number of periods, normally 5 |
HHn |
= Highest High over n periods |
LLn |
= Lowest Low over n periods |
C |
= PriceClose today |
%K |
= Stochastic K = 100 * ( C - LLn ) / ( HHn - LLn ) |
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()
{
//A system based on Fast Stochastic Extreme Levels
DataSeries stK = StochK.Series( Bars, 14 );
ChartPane StochPane = CreatePane( 30, true, true );
PlotSeries( StochPane, stK, Color.Purple, LineStyle.Solid, 2 );
for(int bar = 14; bar < Bars.Count; bar++)
{
if( CrossUnder( bar, stK, 20 ) )
BuyAtMarket( bar+1 );
if ( ( ActivePositions.Count > 0 ) && CrossOver( bar, stK, 20 ) )
{
// Let's work directly with the list of active positions, introduced in WL5
for( int p = ActivePositions.Count - 1; p > -1 ; p-- )
SellAtMarket( bar+1, ActivePositions[p] );
}
}
}
}
}