George Lane’s Stochastic is a famous oscillator, measuring the position of a financial instrument’s price compared to its recent trading range. A momentum indicator can also be considered because it compares the current price position with respect to the previous position. Displays the current day’s price as a percentage of the stock’s trading interval (maximum / minimum) over the specified time period.
In Amibroker you will find at least two instructions dedicated to the stochastic oscillator:
- StochK ( range, Ksmooth )
- StockD ( range, Ksmooth, Dsmooth)
StockD is a Moving Average over Dsmooth periods of StochK.
StockK is a moving average over range periods of the following formula:
FastStochK = 100 * ( C – LLV( L, range ) ) / ( HHV( H, range ) – LLV( L, range ) );
In short this is the AFL to build both the StochK and StockD and compare them with the integrated ones.
range = 14; Ksmooth = 3; Dsmooth = 3; FastStochK = 100 * ( C - LLV( L, range ) ) / ( HHV( H, range ) - LLV( L, range ) ); SlowStochK = MA( FastStochK, Ksmooth ); SlowStochD = MA( SlowStochK, Dsmooth ); Plot( SlowStochK, "%K", colorRed ); Plot( StochK( range , Ksmooth ), "%K (built-in", colorBlue ); Plot( SlowStochD, "%D", colorGreen ); Plot( StochD( range, Ksmooth, Dsmooth ), "%D (built-in", colorBrown );
Here is the graph of the AFL code above to view the output, you can also see how the oscillator identifies the conditions of overbought and oversold.
You can download the script here