VariablePeriodHHV
Background
AmiBroker's built-in HHV returns the highest value of an array over a
fixed number of bars. It is a basic building block for breakout systems, Donchian
channels, trailing stops and many other rules that need to know the recent high-water
mark.
VariablePeriodHHV works the same way but accepts a
period for each bar instead of a single fixed look-back, so the
window can widen or narrow as conditions change — for instance using a longer
look-back in trending markets and a shorter one when cycles are fast. The per-bar
periods often come from an adaptor such as the DominantCycle.
Included formula
This function is one of the building blocks behind the toolbox's Adaptive Smoothed Choppiness Index indicator, which uses it for the highest-high term of the calculation. To see that indicator, open the Charts window in AmiBroker, expand the WiseTraderToolbox group and drag Adaptive Smoothed Choppiness Index onto a chart. It plots the adaptive Choppiness Index in its own pane below price, with the adaptor (which sets the per-bar period) and the smoother set from its parameters.
The exported function
You can also call this function directly in your own formulas — it works just like
AmiBroker's built-in HHV but with a look-back that can change on every
bar.
VariablePeriodHHV(DataArray, PeriodsArray)
| Parameter | Description |
|---|---|
| DataArray | The array to find the highest value of. |
| PeriodsArray | An array (or value) giving the look-back to use at each bar when calculating the highest high value. |
Usage
periods = DominantCycle( Close );
upper = VariablePeriodHHV( High, periods );
Plot( Close, "Price", colorDefault, styleBar );
Plot( upper, "Adaptive HHV", colorGreen );