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.
stop_distance = 20 pipstick_buffer = 5 pointsrisk_now = 1%cash_risk = $200wait = 30mopens_at = 08:00level = high + 2 pipstwo_percent = 2% of account.balance| You write | It 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 points | A distance, converted with each market's own pip and point size. |
2R, 1.5R | A multiple of the trade's initial stop distance. Valid only where a trade has a stop. |
$200 | Money in the account currency. |
1 lot, 0.3 lots | Position size. |
10 bars | A count of bars. |
30s 15m 4h 1d 1w 1M | A length of time. The same words are bar sizes. |
08:00, 2026-01-15 | A time of day and a date. |
#22c55e, green.fade(80) | A colour. Named colours can fade and blend. |
1_000_000 | A number. Underscores are allowed between digits. |
na | No 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.
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 pipsis 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 orderrisk: riskrisks one percent, exactly as if you had written1%.
All eight units are listed under Units.