DocsStrategy APIindicators

OBV (On-Balance Volume)

OBV is a cumulative volume indicator that adds volume on up-days and subtracts volume on down-days. Rising OBV confirms an uptrend; divergence between OBV and price warns of potential reversals.

Declaration

function init(ctx) { ctx.indicator('obv', 'OBV', {}); }

Options

OBV requires no options. It uses close and volume data automatically.

Output

Returns a single number[] series (cumulative volume).

Accessing Values

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

Use Cases

Trend Confirmation

function init(ctx) { ctx.indicator('obv', 'OBV', {}); ctx.indicator('ema', 'EMA', { period: 21 }); } function onBar(ctx, i) { const priceUp = ctx.series.close[i] > ctx.series.close[i - 10]; const obvUp = ctx.ind.obv[i] > ctx.ind.obv[i - 10]; // Price and OBV both rising = confirmed uptrend if (priceUp && obvUp) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'obv_confirmed' }); } // Price rising but OBV falling = bearish divergence if (priceUp && !obvUp) { ctx.order.close('ASSET', { signal: 'sell', reason: 'obv_divergence' }); } }

Calculation

  • If Close > Previous Close: OBV = Previous OBV + Volume
  • If Close < Previous Close: OBV = Previous OBV - Volume
  • If Close = Previous Close: OBV = Previous OBV

Related

  • ADL - Accumulation/Distribution Line
  • MFI - Volume-weighted RSI
  • VWAP - Volume Weighted Average Price
indicatorobvvolumetrendaccumulationqsl