# Vex reference: Events

| Name | What |
| --- | --- |
| [`crosses_above`](#crosses-above) | True on the bar a goes from at or below b to above it. |
| [`crosses_below`](#crosses-below) | True on the bar a goes from at or above b to below it. |
| [`rising`](#rising) | True when x is above every value of the last n bars before it. |
| [`falling`](#falling) | True when x is below every value of the last n bars before it. |
| [`count`](#count) | How many of the last n bars cond was true on. |
| [`bars_since`](#bars-since) | Bars since cond was last true (0 on a bar where it is true; empty before it ever was). |
| [`when`](#when) | x on the most recent bar where cond was true (k = 1 for the one before that, ...). |

## crosses_above

```vex
crosses_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**

```vex
fast = ema(close, 9)
slow = ema(close, 21)
plot(fast)
plot(slow)
mark(crosses_above(fast, slow), "B", where = below)
```

See also: [crosses_below](/documentation/vex/reference/events#crosses-below), [Marks, finished bars and alerts](/documentation/vex/marks-finished-bars-and-alerts)

## crosses_below

```vex
crosses_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**

```vex
fast = ema(close, 9)
slow = ema(close, 21)
plot(fast)
plot(slow)
mark(crosses_below(fast, slow), "S", where = above)
```

See also: [crosses_above](/documentation/vex/reference/events#crosses-above), [Marks, finished bars and alerts](/documentation/vex/marks-finished-bars-and-alerts)

## rising

```vex
rising(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**

```vex
plot(close)
mark(rising(close, 3), where = below, shape = dot)
```

## falling

```vex
falling(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**

```vex
plot(close)
mark(falling(close, 3), where = above, shape = dot)
```

## count

```vex
count(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**

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

## bars_since

```vex
bars_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**

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

## when

```vex
when(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**

```vex
name("Last cross price", where = chart)

plot(when(crosses_above(close, ema(close, 20)), close), "Price at the last cross", style = steps)
```
