Execution Speed Limit

Let's calculate the backtest of our double-SMA strategy:

function Rises(value):
value > value[1]

function Falls(value):
value < value[1]

function SMA(applyTo, period):
sum = 0
for distance from 0 to (period - 1)
sum = sum + applyTo[distance]
sum / period

sma300 = SMA(applyTo: open, period: 300)
sma400 = SMA(applyTo: open, period: 400)

enter long when Rises(sma300) and Rises(sma400)
exit long when Falls(sma300) and Falls(sma400)

When we click on "Calculate backtest", we get the following error in the console, below the editor:

Average bar execution time is higher than 0.1ms

Why is this happening?

Firstly, ProQuant and, as an extension, QuantScript, is a free service. Your QuantScript strategies run in our cloud, for free, alongside the strategies of many other users. Therefore, we must enforce some performance limits to make sure one strategy does not hog resources from every other strategy in our cloud.

We want to ensure fast execution for everyone - that's why we've limited strategies to 0.1 milliseconds of execution time per bar.

If you manage to squeeze under that time restriction during backtesting, we'll allow you to run your strategy. If, while running, execution does happen to take longer than 0.1ms, we won't stop your strategy or throw an error - this probably happened due to a server hiccup on our side.

We also enforce limits on memory usage but more on that later.

Secondly, our current SMA implementation is just slow. Let's look at why that is and how we could speed it up.