Skip to main content

ta.crossover#

True when series a crosses ABOVE series b at bar i — i.e.

SYNTAX#

function ta.crossover(a: (number | null)[], b: (number | null)[], i: number): boolean

ARGUMENTS#

  • a ((number | null)[]) — Primary series.
  • b ((number | null)[]) — Reference series. Same length as a.
  • i (number) — Current bar index. First valid output at i = 1.

RETURNS#

boolean — true on the bar of the crossover, false otherwise.

REMARKS#

Pure event detector — emits true only on the bar where the crossover happens, not while a > b is sustained. Use ta.crossunder for the opposite direction.

EXAMPLE#

const closes = [], emaArr = [];
function onBar(i, ctx) {
  closes[i] = candles[i].close;
  emaArr[i] = ta.ema(closes, 20, i);
  if (ta.crossover(closes, emaArr, i)) {
    plot.marker('cross-up', candles[i].low, { color: '#26a69a', shape: 'triangle' });
  }
}

SEE ALSO#

ta.crossunder, ta.change