Reference: Events

Vex reference: events.

For AI tools: this page as Markdown · the whole language in one file

NameWhat
crosses_aboveTrue on the bar a goes from at or below b to above it.
crosses_belowTrue on the bar a goes from at or above b to below it.
risingTrue when x is above every value of the last n bars before it.
fallingTrue when x is below every value of the last n bars before it.
countHow many of the last n bars cond was true on.
bars_sinceBars since cond was last true (0 on a bar where it is true; empty before it ever was).
whenx on the most recent bar where cond was true (k = 1 for the one before that, ...).

crosses_above

1crosses_above(a, b)

True on the bar a goes from at or below b to above it.

Arguments

  • a: a number per bar
  • b: a number per bar

Returns: a yes/no per bar

In Pine Script: ta.crossover(a, b)

Example

1fast = ema(close, 9)2slow = ema(close, 21)3plot(fast)4plot(slow)5mark(crosses_above(fast, slow), "B", where = below)

See also: crosses_below, Marks, finished bars and alerts

crosses_below

1crosses_below(a, b)

True on the bar a goes from at or above b to below it.

Arguments

  • a: a number per bar
  • b: a number per bar

Returns: a yes/no per bar

In Pine Script: ta.crossunder(a, b)

Example

1fast = ema(close, 9)2slow = ema(close, 21)3plot(fast)4plot(slow)5mark(crosses_below(fast, slow), "S", where = above)

See also: crosses_above, Marks, finished bars and alerts

rising

1rising(x, n)

True when x is above every value of the last n bars before it.

Arguments

  • x: a number per bar
  • n: a whole number of bars, 1 to 5000, fixed: a number or a setting

Returns: a yes/no per bar

In Pine Script: ta.rising(source, length)

Example

1plot(close)2mark(rising(close, 3), where = below, shape = dot)

falling

1falling(x, n)

True when x is below every value of the last n bars before it.

Arguments

  • x: a number per bar
  • n: a whole number of bars, 1 to 5000, fixed: a number or a setting

Returns: a yes/no per bar

In Pine Script: ta.falling(source, length)

Example

1plot(close)2mark(falling(close, 3), where = above, shape = dot)

count

1count(cond, n)

How many of the last n bars cond was true on.

Arguments

  • cond: a yes/no per bar
  • n: a whole number of bars, 1 to 5000, fixed: a number or a setting

Returns: a number per bar

In Pine Script: math.sum(cond ? 1 : 0, length)

Example

1plot(count(close > open, 10), "Up bars of the last 10")

bars_since

1bars_since(cond)

Bars since cond was last true (0 on a bar where it is true; empty before it ever was).

Arguments

  • cond: a yes/no per bar

Returns: a number per bar

In Pine Script: ta.barssince(condition)

Example

1plot(bars_since(crosses_above(close, ema(close, 20))), "Bars since the cross")

when

1when(cond, x, k = 0)

x on the most recent bar where cond was true (k = 1 for the one before that, ...).

Arguments

  • cond: a yes/no per bar
  • x: a number per bar
  • k: a whole number, 0 to 5000, fixed: a number or a setting; 0 when left out

Returns: a number per bar

In Pine Script: ta.valuewhen(condition, source, occurrence)

Example

1name("Last cross price", where = chart)2 3plot(when(crosses_above(close, ema(close, 20)), close), "Price at the last cross", style = steps)