SutraLipi docs grammar v1

Positions & orders

Beyond placing orders, the runtime exposes built-in functions (handled directly by the engine, not indicators) to read the account and your existing positions. The key one is OpenOrders() — it returns your currently open positions, and in paper/live it syncs them from your broker first.

On a restart, reconcile existing positions first. If the strategy re-runs (for example a daily restart), positions from the previous run may still be open — always check them in onStart before entering anything new.

Reconciling positions on restart

Walk the open positions with foreach and read each order's properties.

onStart {
    // reconcile existing positions before trading anything new
    foreach ord in OpenOrders() {
        // e.g. close any losing position left from a previous run
        if (ord.Profit < 0) {
            OrderCloseByTicket(ord.Ticket, INTRADAY, DAY, "cleanup");
        }
    }
}

Order properties

Each order (such as the ord loop variable) exposes these properties via ord.Name:

PropertyMeaning
ord.TicketUnique order id
ord.SymbolThe order's symbol
ord.TypeSide — buy or sell
ord.VolumeQuantity
ord.PriceExecution price
ord.SL / ord.TPStop loss / take profit
ord.OpenTimeEntry time
ord.MagicMagic number
ord.ProfitNet profit / loss
ord.RemarkRemark text

Account, position & time functions

FunctionReturns
OpenOrders()Open orders (syncs from the broker in paper/live)
OpenPositions()Open orders held in memory
PositionsTotal()Number of open orders
PositionSize(symbol)Total quantity held for a symbol
Balance() / Equity()Account balance / equity
IsLocked(symbol)Whether the symbol is currently locked
TimeCurrent() / ServerTimeCurrent()Current time
DayOfWeek()Current day of week (number)
DayAdd(datetime, days)A datetime shifted by n days
GetTodayDayName()Today's name, e.g. "Monday"
GetWeekDayOpen/High/Low/Close(...)This week's weekday OHLC
GetPreviousWeekDayOpen/High/Low/Close(...)Last week's weekday OHLC

Ready to run this? Build and backtest strategies in the SutraLipi algo trading platform — no-code builder, tick-level backtesting and one-click live execution. Browse all documentation topics.

Code copied — paste it into the editor with Ctrl+V.