VariablePeriodFastStochastic
Background
The Stochastic Oscillator, developed by George Lane, asks a simple question: where does the current price sit within its recent high-low range? The fast %K line is calculated as the position of price between the lowest low and the highest high over a look-back window, scaled to run from 0 to 100. A reading near 100 means price is closing at the top of its range (strength), and near 0 means it is closing at the bottom (weakness). It is widely used to spot overbought / oversold conditions and momentum divergences.
This is the fast, un-smoothed %K line. A standard stochastic uses a fixed
look-back; VariablePeriodFastStochastic takes a
period for each bar, so the range window adapts to market conditions.
The per-bar periods often come from an adaptor such as the
DominantCycle.
Included formula
The toolbox ships a ready-made Adaptive Smoothed Stochastic indicator built on this function, so you can use it without writing any code. In AmiBroker open the Charts window, expand the WiseTraderToolbox group and drag Adaptive Smoothed Stochastic onto a chart.
It plots the fast %K line in its own pane below price, with an optional signal line. The Adaptor you pick is what produces the per-bar period this function needs — so the range window adapts to the market — and an optional Smoother cleans up the input first. The adaptor's bounds, the smoothing and the colours are all set from the indicator's parameters.
The exported function
If you would rather build your own formula, the toolbox exports the calculation as a single AFL function you can call directly — it is the engine inside that indicator.
VariablePeriodFastStochastic(Price, Periods)
| Parameter | Description |
|---|---|
| Price | The price array the oscillator is calculated on. The Close is the usual choice. |
| Periods | An array (or value) giving the range look-back to use at each bar. Most often
this is fed from an adaptor such as the DominantCycle. |
Usage
periods = DominantCycle( Close );
fastK = VariablePeriodFastStochastic( Close, periods );
Plot( fastK, "Adaptive Fast %K", colorRed );
Plot( 80, "", colorGrey40, styleDashed | styleNoLabel );
Plot( 20, "", colorGrey40, styleDashed | styleNoLabel );
%K ranges from 0 to 100. Readings above 80 are generally considered overbought and below 20 oversold. Because this is the fast line it can be choppy; many traders smooth it (for example with a short moving average) before acting on it.