# Types reference

> All 18 types in AlgoBarsX, each with its parameters, defaults, ranges and an example: Bar, BarState, BarSet, Zone, Level, Swing, Cell, Trade, Order, Trades and 8 more.

Source: https://algobarsx.com/docs/ref-types/

### `Bar`

One bar.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `open` | price | Open. |
| `high` | price | High. |
| `low` | price | Low. |
| `close` | price | Close. |
| `volume` | number | Volume, or tick count on range, x-ray and renko bars. |
| `time` | time | Bar time. |
| `index` | int | Bar index. |

```algobarsx
first_high = intrabar(1m).first().high
```

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

### `BarState`

Status of a bar set.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `fresh` | bool | false when this symbol had no bar in the latest interval. |
| `index` | int | Bar index. |
| `confirmed` | bool | true once the bar has closed. |

```algobarsx
gold_fresh = bars(XAUUSD).bar.fresh
```

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

### `BarSet`

Bars of a symbol and bar type, aligned to the script.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `open` | price | Open. |
| `high` | price | High. |
| `low` | price | Low. |
| `close` | price | Close. |
| `volume` | number | Volume, or tick count on range, x-ray and renko bars. |
| `time` | time | Bar time. |
| `bar` | BarState | Bar status. |

```algobarsx
h4_close = bars(bars: 4h).close
```

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

### `Zone`

A price zone, such as an order block or fair value gap.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `id` | string | Stable id. |
| `top` | price | Upper bound. |
| `bottom` | price | Lower bound. |
| `mid` | price | Midpoint. |
| `bullish` | bool | true for bullish zones. |
| `mitigated` | bool | true once price has traded back into it. |
| `formed_bar` | int | Bar index where it formed. |
| `formed_time` | time | When it formed. |
| `touches` | int | Times price has returned to it. |
| `status` | string | active, mitigated or broken. |

```algobarsx
fresh_blocks = order_blocks().filter(z => not z.mitigated)
```

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

### `Level`

A support or resistance level.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `price` | price | Level price. |
| `touches` | int | Touches. |
| `formed_bar` | int | Bar index where it formed. |
| `strength` | number | Relative strength from 0 to 1. |

```algobarsx
strong_levels = support_resistance().filter(l => l.touches >= 3)
```

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

### `Swing`

A swing point.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `price` | price | Swing price. |
| `bar` | int | Bar index. |
| `time` | time | Time. |
| `direction` | int | 1 for a swing high, -1 for a swing low. |

```algobarsx
last_turn = zigzag().last().price
```

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

### `Cell`

One heatmap or footprint cell.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `bar` | int | Bar index. |
| `price` | price | Price. |
| `value` | number | Value shown. |

```algobarsx
hot_cells = liquidity_cells.filter(c => c.value > 0)
```

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

### `Trade`

An open or closed trade.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `id` | string | Trade id. |
| `symbol` | symbol | Symbol. |
| `side` | string | long or short. |
| `size` | lots | Size. |
| `entry_price` | price | Entry price. |
| `entry_time` | time | Entry time. |
| `exit_price` | price | Exit price, once closed. |
| `stop` | price | Current stop. |
| `target` | price | Current target. |
| `r` | number | Current R multiple. |
| `pnl` | money | Profit or loss. |
| `pnl_pct` | percent | Profit or loss as a share of balance. |
| `mae` | money | Maximum adverse excursion. |
| `mfe` | money | Maximum favorable excursion. |
| `bars_open` | int | Bars since entry. |
| `tag` | string | Tag. |
| `reason` | string | Why it closed: target, stop, rule, manual or management. |

```algobarsx
best_r = trades.closed().map(t => t.r).max()
```

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

### `Order`

A pending or filled order.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `id` | string | Order id. |
| `type` | string | market, limit, stop or stop_limit. |
| `side` | string | buy or sell. |
| `symbol` | symbol | Symbol. |
| `price` | price | Order price. |
| `size` | lots | Size. |
| `expires` | time | Expiry time. |
| `tag` | string | Tag. |

```algobarsx
grid_count = orders.pending(tag: "grid").len
```

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

### `Trades`

The strategy's own trades.

#### Methods

| Method | Returns | What it does |
| --- | --- | --- |
| `open(tag, side, market)` | list<Trade> | Open trades. |
| `closed(tag, side, market)` | list<Trade> | Closed trades. |
| `last(tag, side, market)` | Trade | The most recent trade. |

```algobarsx
open_longs = trades.open(side: long).len
```

Works in: strategy. Since 1.0.

### `Orders`

Pending orders on the account.

#### Methods

| Method | Returns | What it does |
| --- | --- | --- |
| `pending(tag, side, market)` | list<Order> | Pending orders. |

```algobarsx
waiting_count = orders.pending().len
```

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

### `HistoryPeriod`

Aggregates of closed trades for a period.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `count` | int | Closed trades. |
| `pnl` | money | Net profit or loss. |
| `win_rate` | percent | Share of winning trades. |
| `profit_factor` | number | Gross profit divided by gross loss. |
| `expectancy` | money | Average result per trade. |
| `max_drawdown` | money | Largest peak-to-trough decline. |
| `avg_r` | number | Average R multiple. |

```algobarsx
week_pnl = history.this_week.pnl
```

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

### `History`

Closed trades on the account.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `today` | HistoryPeriod | Today. |
| `this_week` | HistoryPeriod | This week. |
| `this_month` | HistoryPeriod | This month. |
| `count` | int | Closed trades. |
| `pnl` | money | Net profit or loss. |
| `win_rate` | percent | Share of winning trades. |
| `profit_factor` | number | Gross profit divided by gross loss. |
| `expectancy` | money | Average result per trade. |
| `max_drawdown` | money | Largest peak-to-trough decline. |
| `avg_r` | number | Average R multiple. |

#### Methods

| Method | Returns | What it does |
| --- | --- | --- |
| `last(period)` | HistoryPeriod | A trailing period. |

```algobarsx
month_win_rate = history.last(30d).win_rate
```

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

### `Session`

A trading session.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `name` | string | Session name. |
| `open` | time | Open time. |
| `close` | time | Close time. |
| `timezone` | string | Time zone. |

```algobarsx
opens_at = market.session.open
```

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

### `LeverageTier`

Leverage for a band of position sizes.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `max_size` | lots | Largest size in the band. |
| `leverage` | number | Leverage. |

```algobarsx
tier_count = market.leverage_tiers.len
```

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

### `Canvas`

The vector canvas passed to on render.

#### Fields

| Name | Type | What it is |
| --- | --- | --- |
| `last_bar` | int | Index of the last bar. |
| `visible_from` | int | First visible bar. |
| `visible_to` | int | Last visible bar. |
| `price_min` | price | Lowest visible price. |
| `price_max` | price | Highest visible price. |
| `width` | number | Width in pixels. |
| `height` | number | Height in pixels. |

#### Methods

| Method | Returns | What it does |
| --- | --- | --- |
| `path()` | Path | Start a new shape. |
| `text(text, at, align, color, size)` | void | Draw text. |
| `rect(from, to, fill, border)` | void | Draw a rectangle. |
| `line(from, to, color, width)` | void | Draw a line. |

```algobarsx
on render(canvas):
    canvas.text("Hi", at: (canvas.last_bar, close))
```

Works in: strategy, indicator. Since 1.0.

### `Path`

A vector shape being drawn.

#### Methods

| Method | Returns | What it does |
| --- | --- | --- |
| `move_to(bar, price)` | Path | Move without drawing. |
| `line_to(bar, price)` | Path | Draw a straight segment. |
| `curve_to(bar, price, control_bar, control_price)` | Path | Draw a curved segment. |
| `close()` | Path | Close the shape. |
| `fill(style)` | Path | Fill the shape. |
| `stroke(color, width)` | Path | Outline the shape. |

```algobarsx
on render(canvas):
    shape = canvas.path()
```

Works in: strategy, indicator. Since 1.0.

### `color`

Functions available on every color.

#### Methods

| Method | Returns | What it does |
| --- | --- | --- |
| `fade(amount)` | color | The same color with transparency. |

```algobarsx
soft_green = green.fade(80)
```

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