Values, units and types

Percent, pips, R and money are real types, not bare numbers.

Most mistakes in trading code are unit mistakes. AlgoBarsX makes the unit part of the value, and the compiler checks it.

AlgoBarsX
stop_distance = 20 pips
tick_buffer = 5 points
risk_now = 1%
cash_risk = $200
wait = 30m
opens_at = 08:00
level = high + 2 pips
two_percent = 2% of account.balance
You writeIt means
1%, 0.5%A percent. No space before the sign. Use 2% of account.balance to say what it is a percent of. Where the base is unclear the compiler asks: “1% of what?” (AS0305)
20 pips, 5 pointsA distance, converted with each market's own pip and point size.
2R, 1.5RA multiple of the trade's initial stop distance. Valid only where a trade has a stop.
$200Money in the account currency.
1 lot, 0.3 lotsPosition size.
10 barsA count of bars.
30s 15m 4h 1d 1w 1MA length of time. The same words are bar sizes.
08:00, 2026-01-15A time of day and a date.
#22c55e, green.fade(80)A colour. Named colours can fade and blend.
1_000_000A number. Underscores are allowed between digits.
naNo value. Test with is_na, replace with nz.

A stop written as a bare number is caught before anything runs: “stop 25 has no unit. Did you mean 25 pips?” (AS0302). A price level and a distance are different things, and the compiler knows which one an option expects.

Text with live values

Text in double quotes can include any expression in braces, with an optional format after a colon. Write {{ for a literal brace.

AlgoBarsX
on bar close:
log "RSI {rsi(close, 14):0.0} on {market.symbol}"

Units follow the value, not the text

The engine works a unit out from the code. It does not look for the word “pips” in what you typed.

  • A price with a distance taken off it is still a price. stop: lowest(low, 10) - 3 pips is a level on the chart.
  • One price taken from another is a distance.
  • A distance stays a distance when you scale it, as in atr(14) * 2.
  • A unit held in an input travels with it. After input risk = 1%, the order risk: risk risks one percent, exactly as if you had written 1%.

All eight units are listed under Units.

Try this in the Terminal. AlgoBars is free: $0 a month, no card needed.

Create my free account