Types & variables
Primitive types are int, float, bool, string,
datetime and color.
int period = 14;
float price = 100.5;
bool active = true;
string note = "entry";
datetime start = '2026-07-30 09:15';
color up = #00ff00;Constants
A const must be initialised and cannot be reassigned.
const int MAX_QTY = 5;Persistent variables (global)
Prefix any variable with global to make it persistent: its value is saved
against the running strategy and restored the next time that strategy runs. Use it to carry state across
days — so a strategy can resume from where it left off instead of starting fresh each morning.
The initialiser is only a seed. It is used the very first time the variable is created; after that a stored value always wins, so the variable is not reset on the next run.
global float entryPrice = 0; // seeded to 0 once; later runs load the saved value
global int tradeCount = 0;
global string lastSignal = "";
global bool isInTrade = false;
onTick {
if (entryPrice == 0) {
OrderSend(NIFTY, BUY, 50, 0, 0, 0, NORMAL, DAY, "entry");
entryPrice = Close(NIFTY, D1, 0); // saved automatically when it changes
tradeCount = tradeCount + 1;
}
}Notes. Values persist for paper and live trading only
— in a backtest a global behaves like a normal variable (seeded from its initialiser,
kept in memory) so that backtests stay repeatable. global cannot be combined with arrays.
Arrays
Declare an array with type[]. Indicators fill arrays; you can also initialise one with a list.
Index with [i].
float[] sma; // declared, filled later by an indicator
int[] levels = [100, 200, 300];
int first = levels[0]; // index access — [0] is the first elementReady 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.