DocsStrategy APIindicators

DEMA (Double Exponential Moving Average)

DEMA reduces the lag inherent in traditional moving averages by applying the EMA formula twice and adjusting. It is more responsive to price changes than a standard EMA.

Declaration

function init(ctx) { ctx.indicator('dema', 'DEMA', { period: 21, source: 'close' }); }

Options

OptionTypeDefaultDescription
periodnumber20Lookback period
sourcestring'close'Price source (open, high, low, close, hl2, hlc3, ohlc4)

Output

Returns a single number[] series.

Accessing Values

function onBar(ctx, i) { const demaValue = ctx.ind.dema[i]; }

Use Cases

Fast Trend Detection

function init(ctx) { ctx.indicator('dema', 'DEMA', { period: 21 }); ctx.indicator('ema', 'EMA', { period: 21 }); } function onBar(ctx, i) { // DEMA turns before EMA at trend reversals if (q.crossOver(ctx.ind.dema, ctx.ind.ema, i)) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'dema_leads' }); } }

Calculation

$$DEMA = 2 \times EMA(Price) - EMA(EMA(Price))$$

Related

  • EMA - Standard exponential moving average
  • TEMA - Triple EMA for even less lag
  • SMA - Simple moving average
indicatordemamoving-averagetrendqsl