Control flow
if / else if / else
if (rsi[0] < 30) {
OrderSend(nifty, BUY, 1, 0, 0, 0, INTRADAY, DAY, "oversold");
} else if (rsi[0] > 70) {
OrderSend(nifty, SELL, 1, 0, 0, 0, INTRADAY, DAY, "overbought");
} else {
// do nothing
}while, for, foreach
int i;
// while — increment with i = i + 1 (++ is only valid in a for header)
i = 0;
while (i < 3) {
i = i + 1;
}
// for — the header may use i++, i += 2, etc.
for (i = 0; i < 5; i++) {
if (i == 2) continue; // skip this iteration
if (i == 4) break; // stop the loop
}
// foreach — iterate any list or array
int[] strikes = [24000, 24500, 25000];
foreach strike in strikes {
// use strike
}
foreach ord in OpenOrders() { // e.g. walk your open positions (see "Positions & orders")
// ord.Symbol, ord.Volume, ord.Profit ...
}The compound operators (++, --, +=, -=,
*=, /=) are only valid inside a for header. Elsewhere, use
x = x + 1;.
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.