# Conditions reference

> All 8 conditions in AlgoBarsX, each with its parameters, defaults, ranges and an example: crosses_above, crosses_below, crosses, starts, ends, bars_since, was, held.

Source: https://algobarsx.com/docs/ref-fn-conditions/

### `crosses_above(a, b)` → series<bool>

True on the bar where a crosses above b.

#### Parameters

| Name | Type | Default | What it is |
| --- | --- | --- | --- |
| `a` | series<number> | required | Series that crosses. |
| `b` | series<number> | required | Series or level crossed. |

```algobarsx
long_signal = crosses_above(close, ema(close, 20))
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `crosses_below(a, b)` → series<bool>

True on the bar where a crosses below b.

#### Parameters

| Name | Type | Default | What it is |
| --- | --- | --- | --- |
| `a` | series<number> | required | Series that crosses. |
| `b` | series<number> | required | Series or level crossed. |

```algobarsx
short_signal = crosses_below(close, ema(close, 20))
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `crosses(a, b)` → series<bool>

True on the bar where a crosses b in either direction.

#### Parameters

| Name | Type | Default | What it is |
| --- | --- | --- | --- |
| `a` | series<number> | required | First series. |
| `b` | series<number> | required | Second series. |

```algobarsx
any_cross = crosses(ema(close, 20), ema(close, 50))
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `starts(condition)` → series<bool>

True on the bar a condition becomes true.

#### Parameters

| Name | Type | Default | What it is |
| --- | --- | --- | --- |
| `condition` | series<bool> | required | Condition to watch. |

```algobarsx
breakout = starts(close > highest(high, 20)[1])
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `ends(condition)` → series<bool>

True on the bar a condition stops being true.

#### Parameters

| Name | Type | Default | What it is |
| --- | --- | --- | --- |
| `condition` | series<bool> | required | Condition to watch. |

```algobarsx
trend_over = ends(ema(close, 20) > ema(close, 50))
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `bars_since(condition)` → series<int>

Bars since a condition was last true.

#### Parameters

| Name | Type | Default | What it is |
| --- | --- | --- | --- |
| `condition` | series<bool> | required | Condition to watch. |

```algobarsx
age = bars_since(crosses_above(close, ema(close, 20)))
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `was(condition, within = 5 bars)` → series<bool>

True if a condition was true at some point in recent bars.

#### Parameters

| Name | Type | Default | What it is |
| --- | --- | --- | --- |
| `condition` | series<bool> | required | Condition to watch. |
| `within` | bars | `5 bars` | How far back to look. |

```algobarsx
recent = was(crosses_above(close, ema(close, 20)), within: 5 bars)
```

Works in: strategy, indicator, alert, library. Since 1.0.

### `held(condition, for = 3 bars)` → series<bool>

True if a condition has been true for consecutive bars.

#### Parameters

| Name | Type | Default | What it is |
| --- | --- | --- | --- |
| `condition` | series<bool> | required | Condition to watch. |
| `for` | bars | `3 bars` | Bars in a row. |

```algobarsx
steady = held(close > open, for: 3 bars)
```

Works in: strategy, indicator, alert, library. Since 1.0.
