DocsStrategy APIindicators

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

OptionTypeDefaultDescription
periodnumber14Smoothing period for DI and ADX

Output

Returns an object with three series, accessed via underscore naming:

PropertyDescription
adxADX 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 ValueTrend Strength
0 - 20Absent or weak trend
20 - 40Developing trend
40 - 60Strong trend
60 - 100Extremely strong trend

Related

  • MACD - Trend and momentum indicator
  • PSAR - Parabolic SAR for trend direction
  • ATR - Volatility measure, often used with ADX
indicatoradxtrendstrengthdirectionalqsl