# A trading language that takes correctness seriously.

> If you write trading code for a living, you know where the bugs hide: units, look-ahead, fills and drift between research and live. AlgoBarsX was built around those four.

Source: https://algobarsx.com/for/developers/

## What gets in your way.

- **Unit bugs** A percent read as dollars. A distance read as a price. They compile fine elsewhere.
- **Look-ahead** One wrong index and the backtest has seen the future.
- **Research and live drift apart** Two code paths means two results.

## How AlgoBarsX helps.

- **Units are types** Percent, distance, price, money, R and duration are tracked through inputs and arithmetic. The engine works units out from the code, not the text. [Read more](https://algobarsx.com/docs/values-and-units/)
- **No look-ahead, and tested** The tests rewrite the future and check that the past did not move. [Read more](https://algobarsx.com/docs/terminal-tools/)
- **Same answer every time** Same script, inputs and bars give the same result to the last digit. Live uses the same runner as replay. [Read more](https://algobarsx.com/docs/deployments/)
- **A real language underneath** Functions, types, enums, lists, lambdas, pattern matching, state and versioned libraries. [Read more](https://algobarsx.com/docs/functions-and-types/)
- **Published grammar** Full EBNF for building highlighters, linters and tools. [Read more](https://algobarsx.com/docs/grammar/)
- **Stable error codes** 50 diagnostic codes. A code is never reused for a new meaning. [Read more](https://algobarsx.com/docs/#diagnostics)

## Not just rules. A language.

Types, functions that may trade, and functions that may not. A plain `fn` that tries to place an order is a compile error.

```algobarsx
type Level:
    price: price
    touched: int = 0
    formed_at: time

enum Regime: trending, ranging, volatile

fn swing_strength(len: int) -> number:
    up = highest(high, len) - close
    down = close - lowest(low, len)
    return (down - up) / atr(14)

action fn enter_long(size_risk: percent = 1%) -> bool:
    buy risk: size_risk, stop: 20 pips, target: 2R
    return true
```


## Go straight to the detail.

- [Reference: 297 built-ins](https://algobarsx.com/docs/#reference)
- [Execution rules](https://algobarsx.com/docs/#execution-rules)
- [Compiler messages](https://algobarsx.com/docs/#diagnostics)
- [The formal grammar](https://algobarsx.com/docs/grammar/)
- [Coming from Python](https://algobarsx.com/convert/python/)
- [All docs as one Markdown file](https://algobarsx.com/llms-full.txt)

> **What is missing today.** There is no public API, SDK or command-line tool yet. They are planned. The optimiser and walk-forward code exists in the engine but has no screen yet. The language is in beta and may still change.

## Good questions.

**Can I run the compiler in my own pipeline?** Not yet. A public API and a command-line tool are planned. Today the language runs inside the AlgoBars Terminal.

**How are fills modelled?** By 24 written, numbered rules. Market orders fill at the next bar's open. Inside a bar the 1-minute path is used, and when it cannot tell, the stop fills first. See the [execution rules](https://algobarsx.com/docs/#execution-rules).

**Are costs modelled?** No. Fills carry no spread, commission, fees, swaps or slippage, and the docs say so plainly.

## Important

Trading is risky and you can lose money. AlgoBars is software, not a broker or an adviser. Backtests are hypothetical and leave out spread, fees, swaps and slippage. AlgoBarsX is in beta.
