How a script is laid out
Header, inputs, calculations, rules, drawing.
A script reads from top to bottom in five parts. Only the header is required.
algobarsx 1# 1. Header: what kind of script this is, and its settingsstrategy "Layout"market: EURUSDbars: 15m# 2. Inputs: what the person running it may changeinput length = 20# 3. Calculations: worked out on every bartrend_up = close > ema(close, length)# 4. Rules: when something is true, do somethingwhen starts(trend_up):buy risk: 1%, stop: 20 pips, target: 2R# 5. Drawing: what the chart showsplot 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).
- Comments start with
#and run to the end of the line. - The optional first line
algobarsx 1names 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,stateandinput. The full list is in the 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 and E1.