VariablePeriodDMI
Background
The Directional Movement Index (DMI), developed by J. Welles Wilder, describes both
the direction and the strength of a trend. It produces three lines: +DI
(positive directional indicator) measures upward movement, -DI (negative
directional indicator) measures downward movement, and the ADX (Average
Directional Index) measures how strong the trend is regardless of direction. A common
reading is that the trend is tradeable when ADX is rising above about 20–25, with
direction given by whichever DI line is on top.
VariablePeriodDMI computes all three lines with a
period for each bar, so the smoothing adapts to market conditions
rather than being fixed. The per-bar periods often come from an adaptor such as the
DominantCycle. Internally the directional movement and the ADX
are smoothed with Wilder's moving average, exactly as in the classic DMI.
Included formula
The toolbox ships a ready-made Adaptive Smoothed ADX 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 ADX onto a chart.
It plots the ADX together with the +DI and -DI lines in its own
pane, and marks a buy where +DI crosses above -DI and a sell
where it crosses below. The Adaptor you pick is what produces the per-bar
period this function needs — so the smoothing 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.
VariablePeriodDMI(High, Low, Close, Periods)
| Parameter | Description |
|---|---|
| High | The high price array. May be smoothed before input. |
| Low | The low price array. May be smoothed before input. |
| Close | The close price array. May be smoothed before input. |
| Periods | An array (or value) giving the DMI period to use at each bar. Most often this
is fed from an adaptor such as the DominantCycle. |
Usage
periods = DominantCycle( Close );
// The function returns nothing; it exports its results as AFL variables.
VariablePeriodDMI( High, Low, Close, periods );
Plot( PDI_Array, "+DI", colorGreen );
Plot( MDI_Array, "-DI", colorRed );
Plot( ADX_Array, "ADX", colorBlue, styleThick );
This indicator returns nothing. Instead it exports its three result lines as the AFL
array variables PDI_Array (+DI), MDI_Array (−DI) and
ADX_Array (ADX), which you can read after calling it.