How to speed up the processing of a script on the API
1. Measure the running time of the script
public void Execute(IContext ctx, ISecurity sec)
{
var sw = Stopwatch.StartNew();
// here is the script code
if (!ctx.Runtime.IsAgentMode) // write to the log only in the Laboratory mode
ctx.Log($"Time: {sw.Elapsed}", MessageType.Info, true);
}2. Get the required data from ISecurity before the cycle
var closePrices = sec.ClosePrices;
for (int i = startBar; i < barsCount; i++)
{
var signal = closePrices[i] > closePrices[i - 1];
...
}3. Create objects before the loop
4. Use indicator caching
Last updated
Was this helpful?