# AlgoBarsX: complete documentation > AlgoBarsX is the trading language of the AlgoBars platform. One readable script defines a strategy, an indicator, an alert or a library, and the same script is used by the chart, the backtester, alerts and live automation. The compiler also translates every script back into plain English. AlgoBars is free to use ($0 a month, no card). # What AlgoBarsX is > One language for strategies, indicators, alerts and libraries. Source: https://algobarsx.com/docs/what-is-algobarsx/ AlgoBarsX is the language AlgoBars runs on. You describe a strategy, an indicator or an alert in a few readable lines, and the same script is used by the chart, the backtester, the alerts engine and live automation. There is one definition of what your rule means, so you never rewrite it for a different tool. There are four kinds of script. The first word of the file says which one it is. | Kind | What it is for | What comes back when you run it | | --- | --- | --- | | `strategy` | Places and manages trades. | A backtest, a report and a chart. It can be deployed to a demo or live account. | | `indicator` | Calculates and draws. It can publish values for other scripts to use. | The chart it draws and the values it exports. | | `alert` | Watches a condition and sends a message. | The messages it would have sent, and the ones it held back because of its own repeat and cooldown settings. | | `library` | Holds functions and constants you reuse. | It is checked and described. Other scripts import it by name and version. | Every script is also translated back into plain English by the compiler, so you can check that it says what you meant. That text is generated from the compiled code. If the English is wrong, the code is wrong. > **You do not have to write code.** The AI strategy builder and the generator both produce AlgoBarsX. This documentation is for reading what they wrote, changing it, and building your own from scratch. --- # Your first strategy > Write it, read it back, run it. Source: https://algobarsx.com/docs/first-strategy/ > **Would you rather describe it?** Type what you want in plain English in the editor. When the text reads as a description and not as code, a **Convert to AlgoBarsX** button appears and writes the script for you. 1. Open the **Terminal** in AlgoBars and start a new strategy. You get a working starter script, not a blank page. 2. Replace it with the script below. It buys when a fast average crosses above a slow one, risks 1% of the balance with a 25-pip stop and a target of twice the risk, and closes everything on the opposite cross. ```algobarsx strategy "EMA Cross" market: EURUSD bars: 15m input fast = 20 input slow = 50 when crosses_above(ema(close, fast), ema(close, slow)): buy risk: 1%, stop: 25 pips, target: 2R when crosses_below(ema(close, fast), ema(close, slow)): close_all ``` 1. Open the **description** tab. The compiler reads the script back to you: What this script says EMA Cross is a strategy that trades EURUSD on 15-minute bars. You can change 2 inputs: `fast` (default 20) and `slow` (default 50). When the EMA of the close over `fast` bars crosses above the EMA of the close over `slow` bars, it buys at market, risking 1% of the balance, with a stop 25 pips from the entry and with a target 2R from the entry. When the EMA of the close over `fast` bars crosses below the EMA of the close over `slow` bars, it closes all trades. 1. Press **Run**. A small panel asks what to test on: market, bars, bar type, how far back (1 week to 1 year), lot size and starting balance. The market and bars come filled in from your script, so you are confirming, not retyping. 2. You get results, a report, a chart and a **replay**. The replay plays the finished test back so you can watch each trade open and close and the balance move. Every run is kept under **versions** with the code that produced it, so you can always go back. 3. Change `fast` or the stop and run again. Nothing is lost by trying. > **About the numbers.** Backtest results are hypothetical. Fills carry no spread, commission, fees, swaps or slippage (execution rule [E12](https://algobarsx.com/docs/rules-prices-distances-and-size/#E12)), so live results will differ. Past performance does not guarantee future results. --- # The cheat sheet > Most of the language on one screen. It compiles. Source: https://algobarsx.com/docs/cheat-sheet/ One script that touches the header, inputs, constants, state, history, another bar size, confirmations, a rule with timing, a managed order, an event and a plot. Copy it into the Terminal and start deleting what you do not need. ```algobarsx algobarsx 1 strategy "Cheat Sheet" # or: indicator, alert, library market: EURUSD # several: markets: EURUSD, GBPUSD bars: 15m # 1m 5m 1h 4h 1d, or renko(5), xray(20) max_open: 1 max_daily_loss: 3% input length = 20, min: 5, max: 200 # a setting in the panel const BUFFER = 2 pips # fixed value state wins = 0 # survives between bars fast = ema(close, length) # worked out again on every bar prev_close = close[1] # history: one bar back h4 = bars(bars: 4h) # another bar size, closed candles only uptrend = h4.close > ema(h4.close, 50) confirmations setup: # named conditions trend: uptrend momentum: rsi(close, 14) between 50 and 70 require: all when setup.passed and crosses_above(close, fast) max 2 per day cooldown 30m: buy risk: 1%, stop: low - BUFFER, target: 2R: breakeven at: 1R partial 50% at: 1.5R trail by: atr(14) * 2, after: 1.5R when crosses_below(close, fast): close_all on exit(trade): if trade.r > 0: wins += 1 log "{trade.tag} closed at {trade.r:0.00}R, {wins} wins so far" plot fast, color: if uptrend then green else red ``` For the long version, see the [Language Tour](https://algobarsx.com/docs/ex-08-language-tour/) example, which uses nearly every construct in the language. --- # How a script is laid out > Header, inputs, calculations, rules, drawing. Source: https://algobarsx.com/docs/script-layout/ A script reads from top to bottom in five parts. Only the header is required. ```algobarsx algobarsx 1 # 1. Header: what kind of script this is, and its settings strategy "Layout" market: EURUSD bars: 15m # 2. Inputs: what the person running it may change input length = 20 # 3. Calculations: worked out on every bar trend_up = close > ema(close, length) # 4. Rules: when something is true, do something when starts(trend_up): buy risk: 1%, stop: 20 pips, target: 2R # 5. Drawing: what the chart shows plot ema(close, length), color: blue ``` - **Blocks are indented with spaces.** A line ending in a colon opens a block, and the lines under it are indented. Tabs are an error ([AS0003](https://algobarsx.com/docs/diag-text-and-layout/#AS0003)). - **Comments** start with `#` and run to the end of the line. - The optional first line `algobarsx 1` names the language version the script was written for. - Line breaks inside `( )`, `[ ]` or `{ }` are ignored, so long expressions can span lines there. - Names are case-sensitive. A short list of words is reserved, such as `when`, `on`, `if`, `state` and `input`. The full list is in the [grammar](https://algobarsx.com/docs/grammar/). At each bar close the runtime works in a fixed order: fills and management inside the bar, then `on fill` and `on exit`, then calculations, then confirmations and sequences, then rules in script order, then exports and drawing. Orders your rules create take effect from the next bar. See [E21](https://algobarsx.com/docs/rules-strategy-controls/#E21) and [E1](https://algobarsx.com/docs/rules-timing/#E1). --- # Coming from Pine Script > A real import, the ideas side by side, and the names that translate. Source: https://algobarsx.com/docs/from-pine-script/ This is a real run of the importer on a small Pine Script script. The result compiles. 8 lines were read: 5 carried over exactly, 2 were adapted and 2 came back as decisions for you. ```algobarsx //@version=5 strategy("RSI Dip", overlay=true) len = input.int(14, "RSI Length") r = ta.rsi(close, len) if ta.crossover(r, 30) strategy.entry("L", strategy.long) if ta.crossunder(r, 70) strategy.close("L") plot(ta.ema(close, 200), color=color.orange) ``` ```algobarsx strategy "RSI Dip" market: EURUSD bars: 1h input len = 14 r = rsi(close, len) when crosses_above(r, 30): buy size: 1 lot, tag: "L" when crosses_below(r, 70): close_all tag: "L" plot ema(close, 200), color: orange ``` ## Line by line | Status | Your line | What happened | | --- | --- | --- | | Exact | `strategy("RSI Dip", overlay=true)` | strategy() became the script header | | Exact | `len = input.int(14, "RSI Length")` | input() became an input | | Exact | `r = ta.rsi(close, len)` | a calculation was carried over | | Your call | `strategy.entry("L", strategy.long)` | strategy.entry() had no size of its own, so it became one lot: set the size or risk you want | | Adapted | `if ta.crossover(r, 30)` | an if that places orders became a rule | | Exact | `strategy.close("L")` | strategy.close() became close_all | | Adapted | `if ta.crossunder(r, 70)` | an if that places orders became a rule | | Exact | `plot(ta.ema(close, 200), color=color.orange)` | plot() became plot | | Your call | `strategy(...)` | Pine scripts carry no market or bar size, so EURUSD on 1h was filled in: set the ones you want | ## How the ideas translate | In Pine Script | In AlgoBarsX | | --- | --- | | `strategy("RSI Dip", overlay=true)` | strategy "RSI Dip" with market: and bars: stated. Pine takes both from the chart, so they come back as your decision. | | `len = input.int(14, "RSI Length")` | input len = 14 | | `ta.rsi(close, len)` | rsi(close, len) | | `if cond, then strategy.entry(...) under it` | when cond: with buy under it | | `strategy.close("L")` | close_all tag: "L" | | `plot(x, color=color.orange)` | plot x, color: orange | | `var count = 0` | state count = 0 | | `close[1]` | close[1], exactly the same | > **Tip.** Pine does not say how big the position is, so the import uses one lot and hands the choice back to you. Replace it with `risk: 1%` and a stop. ## Names the importer translates for you | Their name | AlgoBarsX | | --- | --- | | `ta.sma` | [`sma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-sma) | | `ta.ema` | [`ema`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-ema) | | `ta.rma` | [`rma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-rma) | | `ta.wma` | [`wma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-wma) | | `ta.hma` | [`hma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-hma) | | `ta.vwma` | [`vwma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-vwma) | | `ta.dema` | [`dema`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-dema) | | `ta.tema` | [`tema`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-tema) | | `ta.rsi` | [`rsi`](https://algobarsx.com/docs/ref-fn-momentum/#ref-rsi) | | `ta.cci` | [`cci`](https://algobarsx.com/docs/ref-fn-momentum/#ref-cci) | | `ta.roc` | [`roc`](https://algobarsx.com/docs/ref-fn-momentum/#ref-roc) | | `ta.mom` | [`momentum`](https://algobarsx.com/docs/ref-fn-momentum/#ref-momentum) | | `ta.stdev` | [`stdev`](https://algobarsx.com/docs/ref-fn-statistics/#ref-stdev) | | `ta.variance` | [`variance`](https://algobarsx.com/docs/ref-fn-statistics/#ref-variance) | | `ta.highest` | [`highest`](https://algobarsx.com/docs/ref-fn-structure/#ref-highest) | | `ta.lowest` | [`lowest`](https://algobarsx.com/docs/ref-fn-structure/#ref-lowest) | | `ta.median` | [`median`](https://algobarsx.com/docs/ref-fn-statistics/#ref-median) | | `ta.linreg` | [`linreg`](https://algobarsx.com/docs/ref-fn-trend/#ref-linreg) | | `ta.correlation` | [`correlation`](https://algobarsx.com/docs/ref-fn-statistics/#ref-correlation) | | `ta.atr` | [`atr`](https://algobarsx.com/docs/ref-fn-volatility/#ref-atr) | | `ta.tr` | [`true_range`](https://algobarsx.com/docs/ref-fn-volatility/#ref-true-range) | | `ta.mfi` | [`mfi`](https://algobarsx.com/docs/ref-fn-momentum/#ref-mfi) | | `ta.obv` | [`obv`](https://algobarsx.com/docs/ref-fn-volume/#ref-obv) | | `ta.vwap` | [`vwap`](https://algobarsx.com/docs/ref-fn-volume/#ref-vwap) | | `ta.barssince` | [`bars_since`](https://algobarsx.com/docs/ref-fn-conditions/#ref-bars-since) | | `ta.crossover` | [`crosses_above`](https://algobarsx.com/docs/ref-fn-conditions/#ref-crosses-above) | | `ta.crossunder` | [`crosses_below`](https://algobarsx.com/docs/ref-fn-conditions/#ref-crosses-below) | | `ta.cross` | [`crosses`](https://algobarsx.com/docs/ref-fn-conditions/#ref-crosses) | | `ta.cum` | `cum` | | `ta.trix` | [`trix`](https://algobarsx.com/docs/ref-fn-momentum/#ref-trix) | | `ta.cmo` | [`cmo`](https://algobarsx.com/docs/ref-fn-momentum/#ref-cmo) | | `math.abs` | [`abs`](https://algobarsx.com/docs/ref-fn-math/#ref-abs) | | `math.max` | [`max`](https://algobarsx.com/docs/ref-modifiers/#ref-max) | | `math.min` | [`min`](https://algobarsx.com/docs/ref-fn-math/#ref-min) | | `math.round` | [`round`](https://algobarsx.com/docs/ref-fn-math/#ref-round) | | `math.floor` | [`floor`](https://algobarsx.com/docs/ref-fn-math/#ref-floor) | | `math.ceil` | [`ceil`](https://algobarsx.com/docs/ref-fn-math/#ref-ceil) | | `math.sqrt` | [`sqrt`](https://algobarsx.com/docs/ref-fn-math/#ref-sqrt) | | `math.log` | [`log`](https://algobarsx.com/docs/ref-cmd-logging/#ref-log) | | `math.exp` | [`exp`](https://algobarsx.com/docs/ref-fn-math/#ref-exp) | | `math.pow` | [`pow`](https://algobarsx.com/docs/ref-fn-math/#ref-pow) | | `math.sign` | [`sign`](https://algobarsx.com/docs/ref-fn-math/#ref-sign) | | `bar_index` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) | | `syminfo.tickerid` | [`market.symbol`](https://algobarsx.com/docs/ref-var-market/#ref-market-symbol) | | `syminfo.ticker` | [`market.symbol`](https://algobarsx.com/docs/ref-var-market/#ref-market-symbol) | | `syminfo.mintick` | [`market.point_size`](https://algobarsx.com/docs/ref-var-market/#ref-market-point-size) | | `color.green` | [`green`](https://algobarsx.com/docs/ref-var-colors/#ref-green) | | `color.red` | [`red`](https://algobarsx.com/docs/ref-var-colors/#ref-red) | | `color.blue` | [`blue`](https://algobarsx.com/docs/ref-var-colors/#ref-blue) | | `color.orange` | [`orange`](https://algobarsx.com/docs/ref-var-colors/#ref-orange) | | `color.yellow` | [`yellow`](https://algobarsx.com/docs/ref-var-colors/#ref-yellow) | | `color.purple` | [`purple`](https://algobarsx.com/docs/ref-var-colors/#ref-purple) | | `color.teal` | [`teal`](https://algobarsx.com/docs/ref-var-colors/#ref-teal) | | `color.gray` | [`gray`](https://algobarsx.com/docs/ref-var-colors/#ref-gray) | | `color.grey` | [`gray`](https://algobarsx.com/docs/ref-var-colors/#ref-gray) | | `color.white` | [`white`](https://algobarsx.com/docs/ref-var-colors/#ref-white) | | `color.black` | [`black`](https://algobarsx.com/docs/ref-var-colors/#ref-black) | | `color.lime` | [`green`](https://algobarsx.com/docs/ref-var-colors/#ref-green) | | `color.maroon` | [`red`](https://algobarsx.com/docs/ref-var-colors/#ref-red) | | `color.silver` | [`gray`](https://algobarsx.com/docs/ref-var-colors/#ref-gray) | | `color.aqua` | [`teal`](https://algobarsx.com/docs/ref-var-colors/#ref-teal) | | `strategy.long` | `long` | | `strategy.short` | `short` | > **Read every import before you run it.** Compare the plain-English description with what your original did, settle each decision, and backtest before you deploy. --- # Coming from MQL4 and MQL5 > A real import, the ideas side by side, and the names that translate. Source: https://algobarsx.com/docs/from-mql4-and-mql5/ This is a real run of the importer on a small MQL4 and MQL5 script. The result compiles. 11 lines were read: 6 carried over exactly, 6 were adapted and 2 came back as decisions for you. ```algobarsx #property strict input int Fast = 20; input int Slow = 50; input double Lots = 0.10; void OnTick() { double f = iMA(NULL, 0, Fast, 0, MODE_EMA, PRICE_CLOSE, 0); double s = iMA(NULL, 0, Slow, 0, MODE_EMA, PRICE_CLOSE, 0); if (f > s && OrdersTotal() == 0) OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - 250 * Point, Ask + 500 * Point); } ``` ```algobarsx strategy "Imported expert advisor" market: EURUSD bars: 1h input Fast = 20 input Slow = 50 input Lots = 0.1 lots f = ema(close, Fast) s = ema(close, Slow) when f > s and trades.open().len == 0: buy size: Lots, stop: close - 250 * market.point_size, target: close + 500 * market.point_size ``` ## Line by line | Status | Your line | What happened | | --- | --- | --- | | Exact | `input int Fast = 20 ;` | an input carried over | | Exact | `input int Slow = 50 ;` | an input carried over | | Exact | `input double Lots = 0.10 ;` | an input carried over | | Adapted | `void OnTick ( )` | OnTick became the script body, which runs once per bar; add evaluate: tick to run on every tick | | Exact | `double f = iMA ( NULL , 0 , Fast , 0 , MODE_EMA` | a variable carried over | | Exact | `double s = iMA ( NULL , 0 , Slow , 0 , MODE_EMA` | a variable carried over | | Adapted | `f > s && OrdersTotal ( ) == 0` | OrdersTotal() became the number of open trades | | Your call | `Symbol ( )` | Symbol() has no equivalent yet | | Adapted | `Ask` | Ask became the close: a backtest here has one price per bar, and live trading uses the right side of the spread | | Adapted | `Ask - 250 * Point` | Ask became the close: a backtest here has one price per bar, and live trading uses the right side of the spread | | Adapted | `Ask + 500 * Point` | Ask became the close: a backtest here has one price per bar, and live trading uses the right side of the spread | | Exact | `OrderSend ( Symbol ( ) , OP_BUY , Lots , Ask , 3 ,` | the order carried over with its stop and target | | Adapted | `if ( f > s && OrdersTotal ( ) == 0 ) OrderSend (` | a condition that places orders became a rule | | Your call | `the script header` | an expert advisor runs on whatever chart it is attached to, so EURUSD on 1h was filled in: set the ones you want | ## How the ideas translate | In MQL4 and MQL5 | In AlgoBarsX | | --- | --- | | `input int Fast = 20;` | input Fast = 20 | | `input double Lots = 0.10;` | input Lots = 0.1 lots | | `iMA(NULL, 0, Fast, 0, MODE_EMA, PRICE_CLOSE, 0)` | ema(close, Fast) | | `OrdersTotal() == 0` | trades.open().len == 0 | | `OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, sl, tp)` | buy size: Lots, stop: …, target: … | | `Point` | market.point_size | | `PERIOD_H1, PERIOD_D1` | 1h, 1d | | `void OnTick()` | the body of the script. Add evaluate: tick to the header if it must run inside the bar. | > **Tip.** Stops written as `Ask - 250 * Point` carry over literally. They read better, and survive gaps better, as distances: `stop: 250 points`. ## Names the importer translates for you | Their name | AlgoBarsX | | --- | --- | | `mode_sma` | [`sma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-sma) | | `mode_ema` | [`ema`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-ema) | | `mode_smma` | [`smma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-smma) | | `mode_lwma` | [`wma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-wma) | | `price_close` | [`close`](https://algobarsx.com/docs/ref-var-bars/#ref-close) | | `price_open` | [`open`](https://algobarsx.com/docs/ref-var-bars/#ref-open) | | `price_high` | [`high`](https://algobarsx.com/docs/ref-var-bars/#ref-high) | | `price_low` | [`low`](https://algobarsx.com/docs/ref-var-bars/#ref-low) | | `price_median` | [`hl2`](https://algobarsx.com/docs/ref-var-bars/#ref-hl2) | | `price_typical` | [`hlc3`](https://algobarsx.com/docs/ref-var-bars/#ref-hlc3) | | `price_weighted` | [`ohlc4`](https://algobarsx.com/docs/ref-var-bars/#ref-ohlc4) | | `mathabs` | [`abs`](https://algobarsx.com/docs/ref-fn-math/#ref-abs) | | `mathmax` | [`max`](https://algobarsx.com/docs/ref-modifiers/#ref-max) | | `mathmin` | [`min`](https://algobarsx.com/docs/ref-fn-math/#ref-min) | | `mathround` | [`round`](https://algobarsx.com/docs/ref-fn-math/#ref-round) | | `mathfloor` | [`floor`](https://algobarsx.com/docs/ref-fn-math/#ref-floor) | | `mathceil` | [`ceil`](https://algobarsx.com/docs/ref-fn-math/#ref-ceil) | | `mathsqrt` | [`sqrt`](https://algobarsx.com/docs/ref-fn-math/#ref-sqrt) | | `mathlog` | [`log`](https://algobarsx.com/docs/ref-cmd-logging/#ref-log) | | `mathexp` | [`exp`](https://algobarsx.com/docs/ref-fn-math/#ref-exp) | | `mathpow` | [`pow`](https://algobarsx.com/docs/ref-fn-math/#ref-pow) | | `mathsign` | [`sign`](https://algobarsx.com/docs/ref-fn-math/#ref-sign) | | `_symbol` | [`market.symbol`](https://algobarsx.com/docs/ref-var-market/#ref-market-symbol) | | `symbol` | [`market.symbol`](https://algobarsx.com/docs/ref-var-market/#ref-market-symbol) | | `_point` | [`market.point_size`](https://algobarsx.com/docs/ref-var-market/#ref-market-point-size) | | `point` | [`market.point_size`](https://algobarsx.com/docs/ref-var-market/#ref-market-point-size) | | `bars` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) | | `period_m1` | `1m` | | `period_m5` | `5m` | | `period_m15` | `15m` | | `period_m30` | `30m` | | `period_h1` | `1h` | | `period_h4` | `4h` | | `period_d1` | `1d` | | `period_w1` | `1w` | | `period_mn1` | `1M` | > **Read every import before you run it.** Compare the plain-English description with what your original did, settle each decision, and backtest before you deploy. --- # Coming from NinjaScript > A real import, the ideas side by side, and the names that translate. Source: https://algobarsx.com/docs/from-ninjascript/ This is a real run of the importer on a small NinjaScript script. The result compiles. 26 lines were read: 5 carried over exactly, 1 were adapted and 4 came back as decisions for you. ```algobarsx namespace NinjaTrader.NinjaScript.Strategies { public class MacdMomentum : Strategy { protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "MACD Momentum"; } } protected override void OnBarUpdate() { if (CrossAbove(EMA(Close, 12), EMA(Close, 26), 1)) { SetStopLoss(CalculationMode.Ticks, 40); SetProfitTarget(CalculationMode.Ticks, 80); EnterLong(); } if (CrossBelow(EMA(Close, 12), EMA(Close, 26), 1)) { ExitLong(); } } } } ``` ```algobarsx strategy "MACD Momentum" market: EURUSD bars: 1h input risk = 1% when crosses_above(ema(close, 12), ema(close, 26)): buy risk: risk, stop: 40 points, target: 80 points when crosses_below(ema(close, 12), ema(close, 26)): close_all side: long ``` ## Line by line | Status | Your line | What happened | | --- | --- | --- | | Exact | `SetStopLoss ( CalculationMode.Ticks , 40 ) ;` | a stop in ticks became points | | Your call | `; SetProfitTarget ( CalculationMode.Ticks , 80 )` | this line has no equivalent yet | | Exact | `SetProfitTarget ( CalculationMode.Ticks , 80 ) ;` | a stop in ticks became points | | Your call | `; EnterLong ( ) ; }` | this line has no equivalent yet | | Adapted | `EnterLong ( ) ; } if` | NinjaTrader sizes an order by the strategy settings, so this one risks a set share of the balance | | Your call | `; } if ( CrossBelow (` | this line has no equivalent yet | | Exact | `if ( CrossAbove ( EMA ( Close ,` | a condition became a rule | | Exact | `ExitLong ( ) ; } }` | an exit carried over | | Your call | `; } } }` | this line has no equivalent yet | | Exact | `if ( CrossBelow ( EMA ( Close ,` | a condition became a rule | ## How the ideas translate | In NinjaScript | In AlgoBarsX | | --- | --- | | `OnBarUpdate()` | the body of the script | | `EMA(Close, 12)` | ema(close, 12) | | `CrossAbove(a, b, 1)` | crosses_above(a, b) | | `SetStopLoss(CalculationMode.Ticks, 40)` | stop: 40 points, on the order itself | | `SetProfitTarget(CalculationMode.Ticks, 80)` | target: 80 points | | `EnterLong()` | buy | | `ExitLong()` | close_all side: long | | `Instrument, TickSize` | market.symbol, market.point_size | > **Tip.** Set a stop with `SetStopLoss` before the entry. The import sizes the trade by risk, and a risk-based order needs a stop to measure from. The C# around the strategy (namespaces, State handling) comes back as notes, not code. ## Names the importer translates for you | Their name | AlgoBarsX | | --- | --- | | `currentbar` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) | | `instrument` | [`market.symbol`](https://algobarsx.com/docs/ref-var-market/#ref-market-symbol) | | `ticksize` | [`market.point_size`](https://algobarsx.com/docs/ref-var-market/#ref-market-point-size) | | `null` | `na` | > **Read every import before you run it.** Compare the plain-English description with what your original did, settle each decision, and backtest before you deploy. --- # Coming from EasyLanguage > A real import, the ideas side by side, and the names that translate. Source: https://algobarsx.com/docs/from-easylanguage/ This is a real run of the importer on a small EasyLanguage script. The result compiles. 6 lines were read: 3 carried over exactly, 3 were adapted and 1 came back as decisions for you. ```algobarsx Inputs: FastLen(20), SlowLen(50); Variables: FastAvg(0), SlowAvg(0); FastAvg = XAverage(Close, FastLen); SlowAvg = XAverage(Close, SlowLen); If FastAvg crosses over SlowAvg then Buy next bar at market; If FastAvg crosses under SlowAvg then Sell next bar at market; ``` ```algobarsx strategy "Imported EasyLanguage strategy" market: EURUSD bars: 1h input FastLen = 20 input SlowLen = 50 state FastAvg = 0 state SlowAvg = 0 FastAvg = ema(close, FastLen) SlowAvg = ema(close, SlowLen) when crosses_above(FastAvg, SlowAvg): buy size: 1 lot when crosses_below(FastAvg, SlowAvg): close_all side: long ``` ## Line by line | Status | Your line | What happened | | --- | --- | --- | | Exact | `FastAvg = XAverage ( Close , FastLen ) ;` | a calculation carried over | | Exact | `SlowAvg = XAverage ( Close , SlowLen ) ;` | a calculation carried over | | Exact | `Buy next bar at market ;` | an order at market carried over | | Adapted | `If FastAvg crosses over SlowAvg then Buy next bar at market ;` | a condition that places orders became a rule | | Adapted | `Sell next bar at market ;` | sell closed the open position, which became close_all on that side | | Adapted | `If FastAvg crosses under SlowAvg then Sell next bar at market ;` | a condition that places orders became a rule | | Your call | `the script header` | EasyLanguage carries no market or bar size, so EURUSD on 1h was filled in: set the ones you want | ## How the ideas translate | In EasyLanguage | In AlgoBarsX | | --- | --- | | `Inputs: FastLen(20);` | input FastLen = 20 | | `Variables: FastAvg(0);` | state FastAvg = 0 | | `XAverage(Close, FastLen)` | ema(close, FastLen) | | `Average, WAverage` | sma, wma | | `If a crosses over b then …` | when crosses_above(a, b): | | `Buy next bar at market;` | buy. Market orders already fill at the next bar's open. | | `Sell next bar at market;` | close_all side: long | | `CurrentBar` | bar.index | > **Tip.** EasyLanguage variables become `state` values. Where one is simply recalculated every bar, you can delete the `state` line and keep the assignment. ## Names the importer translates for you | Their name | AlgoBarsX | | --- | --- | | `average` | [`sma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-sma) | | `xaverage` | [`ema`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-ema) | | `waverage` | [`wma`](https://algobarsx.com/docs/ref-fn-moving-averages/#ref-wma) | | `stddev` | [`stdev`](https://algobarsx.com/docs/ref-fn-statistics/#ref-stdev) | | `standarddev` | [`stdev`](https://algobarsx.com/docs/ref-fn-statistics/#ref-stdev) | | `truerange` | [`true_range`](https://algobarsx.com/docs/ref-fn-volatility/#ref-true-range) | | `avgtruerange` | [`atr`](https://algobarsx.com/docs/ref-fn-volatility/#ref-atr) | | `absvalue` | [`abs`](https://algobarsx.com/docs/ref-fn-math/#ref-abs) | | `maxlist` | [`max`](https://algobarsx.com/docs/ref-modifiers/#ref-max) | | `minlist` | [`min`](https://algobarsx.com/docs/ref-fn-math/#ref-min) | | `squareroot` | [`sqrt`](https://algobarsx.com/docs/ref-fn-math/#ref-sqrt) | | `expvalue` | [`exp`](https://algobarsx.com/docs/ref-fn-math/#ref-exp) | | `power` | [`pow`](https://algobarsx.com/docs/ref-fn-math/#ref-pow) | | `ceiling` | [`ceil`](https://algobarsx.com/docs/ref-fn-math/#ref-ceil) | | `linearregvalue` | [`linreg`](https://algobarsx.com/docs/ref-fn-trend/#ref-linreg) | | `c` | [`close`](https://algobarsx.com/docs/ref-var-bars/#ref-close) | | `o` | [`open`](https://algobarsx.com/docs/ref-var-bars/#ref-open) | | `h` | [`high`](https://algobarsx.com/docs/ref-var-bars/#ref-high) | | `l` | [`low`](https://algobarsx.com/docs/ref-var-bars/#ref-low) | | `v` | [`volume`](https://algobarsx.com/docs/ref-var-bars/#ref-volume) | | `currentbar` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) | | `barnumber` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) | | `pi` | `3.14159265` | | `range` | [`bar.range`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-range) | | `avgprice` | [`ohlc4`](https://algobarsx.com/docs/ref-var-bars/#ref-ohlc4) | | `medianprice` | [`hl2`](https://algobarsx.com/docs/ref-var-bars/#ref-hl2) | | `typicalprice` | [`hlc3`](https://algobarsx.com/docs/ref-var-bars/#ref-hlc3) | > **Read every import before you run it.** Compare the plain-English description with what your original did, settle each decision, and backtest before you deploy. --- # Coming from thinkScript > A real import, the ideas side by side, and the names that translate. Source: https://algobarsx.com/docs/from-thinkscript/ This is a real run of the importer on a small thinkScript script. The result compiles. 8 lines were read: 7 carried over exactly, 1 were adapted and 0 came back as decisions for you. ```algobarsx input fastLength = 20; input slowLength = 50; def fast = ExpAverage(close, fastLength); def slow = ExpAverage(close, slowLength); plot FastLine = fast; plot SlowLine = slow; AddOrder(OrderType.BUY_TO_OPEN, fast crosses above slow); AddOrder(OrderType.SELL_TO_CLOSE, fast crosses below slow); ``` ```algobarsx strategy "Imported study" market: EURUSD bars: 1h input risk = 1% input fastLength = 20 input slowLength = 50 fast = ema(close, fastLength) slow = ema(close, slowLength) when crosses_above(fast, slow): buy risk: risk, stop: atr(14) * 2, target: 2R when crosses_below(fast, slow): close_all side: long plot fast as FastLine plot slow as SlowLine ``` ## Line by line | Status | Your line | What happened | | --- | --- | --- | | Exact | `input fastLength = 20` | the input fastLength carried over | | Exact | `input slowLength = 50` | the input slowLength carried over | | Exact | `def fast = ExpAverage(close, fastLength)` | fast carried over | | Exact | `def slow = ExpAverage(close, slowLength)` | slow carried over | | Exact | `plot FastLine = fast` | the plot FastLine carried over | | Exact | `plot SlowLine = slow` | the plot SlowLine carried over | | Adapted | `AddOrder(OrderType.BUY_TO_OPEN, fast crosses above slow)` | thinkorswim sizes an order by the chart settings, so this one risks a set share of the balance with an ATR stop: set the size you want | | Exact | `AddOrder(OrderType.SELL_TO_CLOSE, fast crosses below slow)` | a closing order carried over | ## How the ideas translate | In thinkScript | In AlgoBarsX | | --- | --- | | `input fastLength = 20;` | input fastLength = 20 | | `def fast = ExpAverage(close, fastLength);` | fast = ema(close, fastLength) | | `plot FastLine = fast;` | plot fast as FastLine | | `fast crosses above slow` | crosses_above(fast, slow) | | `AddOrder(OrderType.BUY_TO_OPEN, cond)` | when cond: with buy under it | | `AddOrder(OrderType.SELL_TO_CLOSE, cond)` | when cond: with close_all side: long under it | | `yes, no` | true, false | | `BarNumber()` | bar.index | > **Tip.** thinkScript orders carry no stop or size, so the import adds a `risk` input with a stop of two ATRs and a 2R target. Check those three numbers before anything else. ## Names the importer translates for you | Their name | AlgoBarsX | | --- | --- | | `yes` | `true` | | `no` | `false` | | `double` | `number` | | `barnumber` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) | | `bar_number` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) | | `getsymbol` | [`market.symbol`](https://algobarsx.com/docs/ref-var-market/#ref-market-symbol) | > **Read every import before you run it.** Compare the plain-English description with what your original did, settle each decision, and backtest before you deploy. --- # Coming from Python > A real import, the ideas side by side, and the names that translate. Source: https://algobarsx.com/docs/from-python/ This is a real run of the importer on a small Python script. The result compiles. 5 lines were read: 4 carried over exactly, 1 were adapted and 0 came back as decisions for you. ```algobarsx import pandas_ta as ta df["fast"] = ta.ema(df["close"], length=20) df["slow"] = ta.ema(df["close"], length=50) df["rsi"] = ta.rsi(df["close"], length=14) df["long"] = (df["fast"] > df["slow"]) & (df["rsi"] < 70) ``` ```algobarsx indicator "Imported Python script" pane: price fast = ema(close, 20) slow = ema(close, 50) rsi_value = rsi(close, 14) long = fast > slow and rsi_value < 70 ``` ## Line by line | Status | Your line | What happened | | --- | --- | --- | | Exact | `df["fast"] = ta.ema(df["close"], length=20)` | a calculation carried over | | Exact | `df["slow"] = ta.ema(df["close"], length=50)` | a calculation carried over | | Adapted | `df["rsi"] = ta.rsi(df["close"], length=14)` | rsi is the name of a built-in here, so it became rsi_value | | Exact | `df["rsi"] = ta.rsi(df["close"], length=14)` | a calculation carried over | | Exact | `df["long"] = (df["fast"] > df["slow"]) & (df["rsi"] < 70)` | a calculation carried over | ## How the ideas translate | In Python | In AlgoBarsX | | --- | --- | | `df["fast"] = ta.ema(df["close"], length=20)` | fast = ema(close, 20) | | `ta.rsi(df["close"], length=14)` | rsi(close, 14) | | `(a > b) & (c < 70)` | a > b and c < 70 | | `a column named rsi` | renamed to rsi_value, so it does not hide the function | | `df["close"].shift(1)` | close[1] | | `df["high"].rolling(20).max()` | highest(high, 20). Rolling calculations come back as a decision, so you pick the function. | > **Tip.** A data-frame script has no orders in it, so it comes back as an indicator. Add `when` rules to turn it into a strategy. ## Names the importer translates for you | Their name | AlgoBarsX | | --- | --- | | `mom` | [`momentum`](https://algobarsx.com/docs/ref-fn-momentum/#ref-momentum) | | `natr` | [`atr`](https://algobarsx.com/docs/ref-fn-volatility/#ref-atr) | | `willr` | [`williams_r`](https://algobarsx.com/docs/ref-fn-momentum/#ref-williams-r) | > **Read every import before you run it.** Compare the plain-English description with what your original did, settle each decision, and backtest before you deploy. --- # Values, units and types > Percent, pips, R and money are real types, not bare numbers. Source: https://algobarsx.com/docs/values-and-units/ 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 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](https://algobarsx.com/docs/diag-units-and-risk/#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`](https://algobarsx.com/docs/ref-fn-missing-values/#ref-is-na), replace with [`nz`](https://algobarsx.com/docs/ref-fn-missing-values/#ref-nz). | A stop written as a bare number is caught before anything runs: *“stop 25 has no unit. Did you mean 25 pips?”* ([AS0302](https://algobarsx.com/docs/diag-units-and-risk/#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](https://algobarsx.com/docs/ref-units/). --- # Series and history > Every value has a past. Read it without looking ahead. Source: https://algobarsx.com/docs/series-and-history/ `close` is not one number. It is a series with a value on every bar. Square brackets read earlier bars: `close[1]` is the previous bar's close. A value at a bar never depends on a later bar, and the test suite proves it by rewriting the future and checking the past did not move. ```algobarsx prev_close = close[1] range_high = highest(high, 20)[1] rising = close > close[1] and close[1] > close[2] recent = was(rsi(close, 14) < 30, within: 5 bars) steady = held(close > ema(close, 50), for: 3 bars) since_cross = bars_since(crosses_above(close, ema(close, 50))) safe = nz(close[500], close) ``` - [`was`](https://algobarsx.com/docs/ref-fn-conditions/#ref-was) is true if a condition was true at some point in recent bars. [`held`](https://algobarsx.com/docs/ref-fn-conditions/#ref-held) is true if it has been true for consecutive bars. - [`crosses_above`](https://algobarsx.com/docs/ref-fn-conditions/#ref-crosses-above), [`crosses_below`](https://algobarsx.com/docs/ref-fn-conditions/#ref-crosses-below) and [`crosses`](https://algobarsx.com/docs/ref-fn-conditions/#ref-crosses) detect crossings. [`starts`](https://algobarsx.com/docs/ref-fn-conditions/#ref-starts) and [`ends`](https://algobarsx.com/docs/ref-fn-conditions/#ref-ends) are true on the bar a condition becomes true or stops being true. - [`bars_since`](https://algobarsx.com/docs/ref-fn-conditions/#ref-bars-since) counts bars since a condition was last true. - Reading further back than the data goes gives `na`. [`nz`](https://algobarsx.com/docs/ref-fn-missing-values/#ref-nz) supplies a fallback. - Reading forward is an error, not a bug waiting to happen: *“close[-1] would read a future bar. History counts back from the current bar: close[1] is the previous bar.”* ([AS0203](https://algobarsx.com/docs/diag-names-and-types/#AS0203)) - Indicator calls update on every bar, even when their line sits in a branch that did not run, so a reading is never stale. Built-in price series: `open high low close volume time hl2 hlc3 ohlc4`, plus facts about the bar such as `bar.index`, `bar.confirmed` and `bar.range`. See [Bar variables](https://algobarsx.com/docs/ref-var-bars/). --- # Operators and expressions > and, or, not, between, in, if-then-else. Source: https://algobarsx.com/docs/operators/ ```algobarsx in_band = rsi(close, 14) between 40 and 60 morning = hour in 8..11 bias = if close > ema(close, 200) then 1 else -1 power = 2 ** 3 calm = not (atr(14) > atr(14)[10]) first_hour = time_of_day between 08:00 and 09:00 ``` | Operator | Meaning | | --- | --- | | `+ - * / % **` | Arithmetic. `**` is power and groups from the right, so `2 ** 3 ** 2` is 512. | | `== != < <= > >=` | Comparison. | | `and or not` | Logic, in words. | | `x between a and b` | True when `x` is inside the range. | | `x in 8..11` | True when `x` is in a range or a list. | | `if c then a else b` | Chooses a value inside an expression. | | `2% of account.balance` | Turns a percent into an amount. | | `+= -= *= /=` | Update a `state` value in place. | Time variables available everywhere: `hour`, `minute`, `day_of_week` and `time_of_day`. --- # Inputs and constants > What the person running the script may change. Source: https://algobarsx.com/docs/inputs-and-constants/ An `input` becomes a setting in the script's panel. Its type comes from its default value, so `input risk = 1%` is a percent and `input higher_tf = 4h` is a bar size. A `const` is fixed. ```algobarsx input fast = 20, label: "Fast length", min: 2, max: 500, group: "Trend" input source = close, label: "Source" input higher_tf = 4h, label: "Higher timeframe" input session = "london", options: ["london", "new_york", "asia"] input risk = 1%, min: 0.1%, max: 5%, step: 0.1% input show_zones = true, group: "Display" input zone_color = blue.fade(70), group: "Display", visible_if: show_zones const RISK_CAP = 2% ``` | Option | What it does | | --- | --- | | `label` | The name shown in the panel. | | `min`, `max`, `step` | Limits and step size. | | `options` | A fixed list of choices. | | `group` | Groups inputs under a heading. | | `visible_if` | Shows this input only when another one is on. | An input nobody reads is flagged as a hint ([AS0601](https://algobarsx.com/docs/diag-hints/#AS0601)). --- # Variables and state > Values recalculated each bar, and values that survive between bars. Source: https://algobarsx.com/docs/state/ A plain assignment such as `trend_up = close > ema(close, 50)` is worked out again on every bar. A `state` value is set once and keeps whatever you last put in it, which is how you count things or remember a price. ```algobarsx state triggers = 0 state last_entry: price = na when close > open: triggers += 1 last_entry = close on day change: triggers = 0 ``` You can annotate a type when the default does not say enough: `state last_entry: price = na`. --- # Control flow > if, for, match, break and continue. Source: https://algobarsx.com/docs/control-flow/ ```algobarsx if regime == Regime.trending: risk_now = 1% elif regime == Regime.volatile: risk_now = 0.5% else: risk_now = 0.25% for level in levels: if close > level.price: level.touched += 1 for i in 0..50: if i > 10: break continue match regime: Regime.trending: log "trending" Regime.ranging: log "ranging" ``` - `if` / `elif` / `else` choose between blocks. - `for x in list` and `for i in 0..50` loop. `break` and `continue` work as you expect. - `match` picks a branch by value, which reads well with an `enum`. --- # Functions, types, enums and lists > Simple on top, a full language underneath. Source: https://algobarsx.com/docs/functions-and-types/ ```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 ``` - `fn` defines a pure function. It calculates and returns a value. - `action fn` may place orders, so it can only be called where orders are allowed. A plain `fn` that tries to trade is an error ([AS0403](https://algobarsx.com/docs/diag-where-things-may-go/#AS0403)). - `type` defines a record with named, typed fields and optional defaults. `enum` defines a fixed set of names. - Parameters can have types and defaults: `fn f(source: series = close, length: int = 20) -> number`. ## Lists and lambdas ```algobarsx levels.push(Level(price: high, formed_at: time)) levels = levels.filter(l => l.touched == 0).keep_last(50) ranked = levels.sort_by((a, b) => a.price - b.price) ``` Lists support `push`, `pop`, `remove`, `filter`, `map`, `sort_by`, `keep_last`, `first`, `last`, `len` and `contains`, plus the aggregates `sum`, `mean`, `min` and `max`. A lambda is written `x => expression`. --- # The header and its settings > Markets, bar size, limits and trading hours. Source: https://algobarsx.com/docs/strategy-header/ ```algobarsx strategy "Language Tour" markets: EURUSD, GBPUSD bars: 15m evaluate: bar_close max_open: 3 max_open_per_side: 2 direction: both opposite: reverse pyramiding: 3 min_distance: 20 pips max_daily_loss: 3% max_drawdown: 10% trade_only: within sessions london, new_york ``` Every setting, with its type and default: | Setting | Type | Default | What it does | | --- | --- | --- | --- | | [`market`](https://algobarsx.com/docs/ref-settings/#ref-market) | symbol | `chart symbol` | Symbol the script runs on. | | [`markets`](https://algobarsx.com/docs/ref-settings/#ref-markets) | list | | Several symbols; alerts evaluate each independently. | | [`bars`](https://algobarsx.com/docs/ref-units/#ref-bars) | bartype | `chart bars` | Bar type: timeframe, range(n), xray(n), renko(n) or heikin_ashi(tf). | | [`evaluate`](https://algobarsx.com/docs/ref-settings/#ref-evaluate) | string | `bar_close` | bar_close (default, never repaints) or tick. | | [`pane`](https://algobarsx.com/docs/ref-settings/#ref-pane) | string | `price` | price, new or a named pane. | | [`max_open`](https://algobarsx.com/docs/ref-settings/#ref-max-open) | int | `1` | Open trades allowed at once. | | [`max_open_per_side`](https://algobarsx.com/docs/ref-settings/#ref-max-open-per-side) | int | | Open trades allowed per side. | | [`direction`](https://algobarsx.com/docs/ref-settings/#ref-direction) | string | `both` | both, long or short. | | [`opposite`](https://algobarsx.com/docs/ref-settings/#ref-opposite) | string | `ignore` | On an opposite signal: close, reverse, ignore or hedge (where the venue supports it). | | [`warmup`](https://algobarsx.com/docs/ref-settings/#ref-warmup) | int | | Bars required before rules run (computed by the compiler when omitted). | | [`repeat`](https://algobarsx.com/docs/ref-settings/#ref-repeat) | string | `once per bar` | once, once per bar, once per bar close or every time. | | [`cooldown`](https://algobarsx.com/docs/ref-modifiers/#ref-cooldown) | duration \| bars | | Minimum time or bars between notifications. | | [`expires`](https://algobarsx.com/docs/ref-settings/#ref-expires) | date \| duration | | When the alert stops. | | [`check`](https://algobarsx.com/docs/ref-settings/#ref-check) | duration | `every 1m` | How often account-only alerts are checked. | | [`show_on_chart`](https://algobarsx.com/docs/ref-settings/#ref-show-on-chart) | bool | `true` | Draw fire points, watched levels and live status on the chart. | | [`max_daily_loss`](https://algobarsx.com/docs/ref-settings/#ref-max-daily-loss) | percent \| money | | Pause the deployment after this loss in a day. | | [`max_drawdown`](https://algobarsx.com/docs/ref-settings/#ref-max-drawdown) | percent \| money | | Pause the deployment at this drawdown. | | [`max_total_risk`](https://algobarsx.com/docs/ref-settings/#ref-max-total-risk) | percent | | Risk allowed across open trades. | | [`pyramiding`](https://algobarsx.com/docs/ref-settings/#ref-pyramiding) | int | `1` | Entries allowed in the same direction. | | [`min_distance`](https://algobarsx.com/docs/ref-settings/#ref-min-distance) | distance | | Smallest distance between pyramided entries. | | [`trade_only`](https://algobarsx.com/docs/ref-settings/#ref-trade-only) | sessions | | Sessions in which the strategy may open trades. | Limits are checked when an entry fills, not when it is placed ([E19](https://algobarsx.com/docs/rules-strategy-controls/#E19)). With `trade_only`, entries are only created inside the listed sessions, while exits and management carry on outside them ([E22](https://algobarsx.com/docs/rules-strategy-controls/#E22)). The named sessions are `sydney`, `tokyo`, `asia`, `frankfurt`, `london` and `new_york`. --- # Rules: when something is true, do something > The when rule and its timing modifiers. Source: https://algobarsx.com/docs/rules/ A rule is `when [modifiers]:` followed by what to do. Name a rule with `as` to read its counters later, such as `long_entry.triggers`. ```algobarsx when long_setup.passed as long_entry every 4th: buy risk: risk, stop: atr(14) * 1.5, target: 3R when starts(long_setup.passed) skip first 3 max 2 per day cooldown 30m: triggers += 1 if triggers % 4 == 0: buy risk: 0.5%, stop: atr(14) * 1.5, target: 3R ``` Modifiers say when a rule may fire, on the rule itself, so there are no counters to build by hand: | Modifier | What it does | | --- | --- | | [`every \| every bar`](https://algobarsx.com/docs/ref-modifiers/#ref-every) | Act on every Nth trigger, or count every bar the condition holds. | | [`skip first `](https://algobarsx.com/docs/ref-modifiers/#ref-skip) | Ignore the first N triggers, then act on every trigger. | | [`max per `](https://algobarsx.com/docs/ref-modifiers/#ref-max) | Cap actions per day, session, hour or week. | | [`cooldown `](https://algobarsx.com/docs/ref-modifiers/#ref-cooldown) | Ignore triggers for a while after acting. | | [`once per bar`](https://algobarsx.com/docs/ref-modifiers/#ref-once) | In tick mode, act at most once per bar. | | [`within sessions , ...`](https://algobarsx.com/docs/ref-modifiers/#ref-within) | Only trigger inside the named sessions. | | [`from