How could I cache the values of indicators each tick to speed up backtesting. Does mt5 do this already?

 

I have a neural network with various indicators as inputs. Is there a way I could code in a huge lookup table so each tick I could look up the value instead of calculating them every time? Does mt5 do this already internally? Could I do this in ontesterinit()? Is there a function to get the start and end dates of the testing? And then in ontesterinit is there a function that I could just put in the start and end date and get every calculated tick for stochastic? I imagine writing these to a file and reading it takes as much or more time then calculating it. Are there any other ways to store it so each pass can quickly look up the values?

Thanks

 
tanner gilliland:

I have a neural network with various indicators as inputs. Is there a way I could code in a huge lookup table so each tick I could look up the value instead of calculating them every time? Does mt5 do this already internally? Could I do this in ontesterinit()? Is there a function to get the start and end dates of the testing? And then in ontesterinit is there a function that I could just put in the start and end date and get every calculated tick for stochastic? I imagine writing these to a file and reading it takes as much or more time then calculating it. Are there any other ways to store it so each pass can quickly look up the values?

Thanks

I am sure your NN is more complex to calculate than the indicators.

No, there is no function available to get start and end dates of the tester.

OnTesterInit is run in a separate instance, independent of the actual EA tested. There is no common ground to exchange data except for filesystem.

What you could do:

Since your indicators (most probably) are calculated using the close price, you could create a close-price indicator-result table for each indicator in use. You would need to estimate the range of prices, iE for EURUSD something like 0.80000 to 1.30000 and have a result value for each price step in between.

Then you can "hard code" these values in a binary file, which you supply as a resource.

Now you need a lookup function to do the lookup, like a bubble search Wich has a complexity of O(log n).

The question is, will this be faster? Honestly I don't know. And what about resources, like memory. I don't know either.

Probably the required effort is not worth the gain.

A more interesting question would be if it were possible to make the indicator calculations required to feed your NN part of the NN itself. So that you don't need the indicators, but can feed the price directly into the NN.

Then you could focus on optimizing the execution of the NN, leveraging your GPU via OpenCL maybe.

My personal opinion is, it's probably the best to focus on optimizing what you have, instead of trying to bypass the current code.
 

Thanks for taking the time to reply, I appreciate it. I think I'm going to try to get it to run on the GPU with OpenCL. It is a very small NN and I'm not sure how fast it would be to send inputs and get outputs from the gpu, but hopefully it would speed it up by a decent amount.