ADX (Average Directional Index)
The ADX measures trend strength on a 0-100 scale regardless of trend direction. It is accompanied by +DI and -DI lines that indicate the direction of the trend.
Declaration
function init(ctx) { ctx.indicator('adx', 'ADX', { period: 14 }); }
Options
| Option | Type | Default | Description |
|---|---|---|---|
period | number | 14 | Smoothing period for DI and ADX |
Output
Returns an object with three series, accessed via underscore naming:
| Property | Description |
|---|---|
adx | ADX value (trend strength, 0-100) |
pdi | +DI (positive directional indicator) |
mdi | -DI (minus directional indicator) |
Accessing Values
function onBar(ctx, i) { const adxValue = ctx.ind.adx[i]; // Just the ADX (no prefix for primary) const plusDI = ctx.ind.adx_pdi[i]; const minusDI = ctx.ind.adx_mdi[i]; }
Use Cases
Trend Strength Filter
function onBar(ctx, i) { const adxValue = ctx.ind.adx[i]; // Only trade when trend is strong if (adxValue > 25) { // Strong trend - use trend-following strategies if (q.crossOver(ctx.ind.fast, ctx.ind.slow, i)) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'strong_trend_entry' }); } } // ADX < 20: range-bound, use mean-reversion }
Directional Movement Crossover
function onBar(ctx, i) { const adxValue = ctx.ind.adx[i]; if (adxValue > 20) { if (q.crossOver(ctx.ind.adx_pdi, ctx.ind.adx_mdi, i)) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'pdi_cross_up' }); } if (q.crossUnder(ctx.ind.adx_pdi, ctx.ind.adx_mdi, i)) { ctx.order.close('ASSET', { signal: 'sell', reason: 'pdi_cross_down' }); } } }
Value Ranges
| ADX Value | Trend Strength |
|---|---|
| 0 - 20 | Absent or weak trend |
| 20 - 40 | Developing trend |
| 40 - 60 | Strong trend |
| 60 - 100 | Extremely strong trend |
Related
indicatoradxtrendstrengthdirectionalqsl