SutraLipi language
SutraLipi (the TradingLang DSL) turns a trading idea into an exact, executable formula. This reference covers the full syntax with runnable examples, one topic per page.
Getting started
- Overview — A TradingLang program declares symbols and variables, then reacts to the market inside event blocks such as onTick. Learn the basic shape of a script.
- Your first strategy — The same TradingLang script runs unchanged in backtest, paper and live. Learn the shape every strategy follows: declare symbols, declare arrays, write your logic in an event.
- Comments & statements — TradingLang comments start with // and run to the end of the line. Every statement ends with a semicolon.
Language
- Types & variables — TradingLang primitive types are int, float, bool, string, datetime and color, plus const values and arrays.
- Operators — Arithmetic, comparison and logical operators in TradingLang, and the precedence rules that decide how expressions are evaluated.
- Control flow — TradingLang control flow: if/else if/else, while and for loops, foreach over lists and arrays, and the compound operators valid inside a for header.
Market data
- Symbols — How to declare equity, future and option symbols in TradingLang, including the expirySpec forms: bare date, Expiry.OnDate, Expiry.Weekly and Expiry.Monthly.
- Option chain — Declare an OptionChain and pick strikes dynamically with chain.ATM/OTM/ITM instead of hardcoding a strike price.
- Price references — Read OHLCV and derived series — HighestHigh, LowestLow, OpenInterest, DeliveryVolume, CandleTime — for any symbol and timeframe.
- Timeframes — TradingLang timeframes are written as bare tokens: M1 M2 M3 M4 M5 M10 M15 M30 H1 H2 H4 D1 W1 MN.
Indicators & time
- Indicators — TradingLang indicator calls fill an output array: INDICATOR_NAME(outputArray, symbol, timeframe, ...params). Full reference of built-in indicators.
- Date & time — Extract parts of a time value with HOUR, MINUTE, SECOND, DOD, MONTH, YEAR, DAYOFWEEK and DATE, plus weekday helper functions.
- Candle patterns — Built-in candlestick pattern helpers such as Bullish_Engulfing_Pattern and Three_White_Soldiers that return a boolean for a symbol and timeframe.
Trading
- Order commands — Full syntax reference for OrderSend, OrderModifyBySymbol/ByTicket/ByMagic and OrderCloseBySymbol/ByTicket/ByMagic/All in TradingLang.
- Lock clause — The TradingLang lock clause blocks new orders on a symbol for a period, standalone or attached to an order, with a fixed duration or until the next candle.
- Positions & orders — Read your account and existing positions with OpenOrders(), reconcile positions on restart, and the full set of order properties and account functions.
Program
- Events — TradingLang logic lives inside event blocks — onStart, onTick, onStop, onTimer and onTrade.
- Functions — Define reusable functions with function, and custom indicators with indicator, in TradingLang.
Recipes
- Examples — Runnable TradingLang examples: an EMA crossover, an ATM short straddle with relative expiry, and a time-based square-off.