# Market structure reference

> All 8 market structure in AlgoBarsX, each with its parameters, defaults, ranges and an example: highest, lowest, pivots, swing_high, swing_low, fractals, zigzag, support_resistance.

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

### `highest(source = high, length = 20)` → like source

Highest value over the last bars.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `high` |  | Series to calculate from. |
| `length` | int | `20` | 1 to 5000 | Number of bars in the calculation. |

```algobarsx
top = highest(high, 20)
```

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

### `lowest(source = low, length = 20)` → like source

Lowest value over the last bars.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `source` | series<number> | `low` |  | Series to calculate from. |
| `length` | int | `20` | 1 to 5000 | Number of bars in the calculation. |

```algobarsx
bottom = lowest(low, 20)
```

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

### `pivots(left = 5, right = 5, on = bars())` → Pivots

Confirmed pivot highs and lows; each fires on its confirmation bar, never the pivot bar.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `left` | int | `5` | 1 to 500 | Bars to the left. |
| `right` | int | `5` | 1 to 500 | Bars to the right. |
| `on` | BarSet | `bars()` |  | Bars to calculate on; defaults to the script's own bars. |

#### Outputs, read with a dot

| Name | Type | What it is |
| --- | --- | --- |
| `high` | series<price> | Latest confirmed pivot high. |
| `low` | series<price> | Latest confirmed pivot low. |

```algobarsx
pv = pivots(left: 5, right: 5)
```

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

### `swing_high(left = 5, right = 5, on = bars())` → series<price>

Latest confirmed swing high.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `left` | int | `5` | 1 to 500 | Bars to the left. |
| `right` | int | `5` | 1 to 500 | Bars to the right. |
| `on` | BarSet | `bars()` |  | Bars to calculate on; defaults to the script's own bars. |

```algobarsx
last_swing_high = swing_high(left: 5, right: 5)
```

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

### `swing_low(left = 5, right = 5, on = bars())` → series<price>

Latest confirmed swing low.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `left` | int | `5` | 1 to 500 | Bars to the left. |
| `right` | int | `5` | 1 to 500 | Bars to the right. |
| `on` | BarSet | `bars()` |  | Bars to calculate on; defaults to the script's own bars. |

```algobarsx
last_swing_low = swing_low(left: 5, right: 5)
```

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

### `fractals(periods = 2, on = bars())` → Fractals

Williams fractals.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `periods` | int | `2` | 1 to 50 | Bars on each side. |
| `on` | BarSet | `bars()` |  | Bars to calculate on; defaults to the script's own bars. |

#### Outputs, read with a dot

| Name | Type | What it is |
| --- | --- | --- |
| `up` | series<bool> | Up fractal confirmed. |
| `down` | series<bool> | Down fractal confirmed. |

```algobarsx
fr = fractals(2)
```

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

### `zigzag(deviation = 5%, depth = 10, on = bars())` → list<Swing>

Zigzag swing points.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `deviation` | percent | `5%` |  | Smallest reversal. |
| `depth` | int | `10` | 1 to 500 | Fewest bars between points. |
| `on` | BarSet | `bars()` |  | Bars to calculate on; defaults to the script's own bars. |

```algobarsx
swings = zigzag(deviation: 5%, depth: 10)
```

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

### `support_resistance(length = 200, touches = 2, on = bars())` → list<Level>

Support and resistance levels.

#### Parameters

| Name | Type | Default | Range | What it is |
| --- | --- | --- | --- | --- |
| `length` | int | `200` | 1 to 5000 | Bars to scan. |
| `touches` | int | `2` | 1 to 100 | Fewest touches for a level. |
| `on` | BarSet | `bars()` |  | Bars to calculate on; defaults to the script's own bars. |

```algobarsx
key_levels = support_resistance(200, touches: 2)
```

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