Functions
Define reusable functions with function, and custom indicators with indicator.
Parameters are type name (use type[] for an array); return hands back a value.
function float midpoint(float h, float l) {
return (h + l) / 2;
}
indicator float hl2(float h, float l) {
return (h + l) / 2;
}
onTick {
float m = midpoint(High(nifty, M5, 0), Low(nifty, M5, 0));
}Array length — Count()
Count(array) returns the number of elements in an array. Useful for looping over indicator
output safely, since the number of values returned can be smaller than you asked for when there is not
enough history yet.
float[] swings;
INDICATOR_SWING(swings, nifty, D1, 1, 5);
onTick {
int n = Count(swings);
for (int i = 0; i < Count(swings); i = i + 1) {
// ... use swings[i]
}
}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.