Tutorial for XMas : How to avoid the OnTick()'s memory error during optimization

 

Hi,

I figured out how to deeply reduce the memory used by the EA in a way it could be optimized with the cloud. Nobody's has provided a solution for that, here's what worked - for me.

1. Purify your code : ZeroMemory all variables when not used anymore, ArrayFree/ArrayResize all the array when not needed anymore

2. Check the loops, moreover the loops inside loops : it helped to Sleep(60000) at the end of an iteration

3. Indicators & Handle : You can ZeroMemory the handle of each indicator if they're called on the fly - load indicator + unload indicator - In my case, unloading the indicator before reloading it consumes more memory than loading it once.

4. Change the timeframe used for a higher one

5. Check the used memory (   Print("Used ",TerminalInfoInteger(TERMINAL_MEMORY_USED)," Mb of memory"); ) before & after each function called to know where's the consumption from.

6. MQLInfoInteger(MQL_MEMORY_LIMIT) (= 2048) seems to be the limit of the MQL cloud Agents ; don't expect to optimize with cloud if you use more than ... it's a standard.

7. Change the period on which you wish to optimize : 1 year may suits using timeframe H1 while not 2 year

8 : Homogenize the timeframe used by your EA, more than 1 indicator ? Make them all run on the same timeframe & adapt the period

... at this point you got the thing ... I've reduced mine from more than 4GB to less than 1gb (900Mb approx.), it's now optimizing, with no errors.

NB : 9. Yet the damn error can appear, in my case, using MQL Europe 2 & MQL Usa provided the error - just deactivate it as soon as you see it in the logs - it's time & money consuming since you have to re-pay for the pass re-queued.

That's all folks ! Hope it'll help. 

By the way, if someone know how to reduce the MaxBars in MQL  he's welcome, it seems locked at 100000, even if you change the value from the terminal properties

 
blouf:

Hi,

I figured out how to deeply reduce the memory used by the EA in a way it could be optimized with the cloud. Nobody's has provided a solution for that, here's what worked - for me.

1. Purify your code : ZeroMemory all variables when not used anymore, ArrayFree/ArrayResize all the array when not needed anymore

2. Check the loops, moreover the loops inside loops : it helped to Sleep(60000) at the end of an iteration

3. Indicators & Handle : You can ZeroMemory the handle of each indicator if they're called on the fly - load indicator + unload indicator - In my case, unloading the indicator before reloading it consumes more memory than loading it once.

4. Change the timeframe used for a higher one

5. Check the used memory (   Print("Used ",TerminalInfoInteger(TERMINAL_MEMORY_USED)," Mb of memory"); ) before & after each function called to know where's the consumption from.

6. MQLInfoInteger(MQL_MEMORY_LIMIT) (= 2048) seems to be the limit of the MQL cloud Agents ; don't expect to optimize with cloud if you use more than ... it's a standard.

7. Change the period on which you wish to optimize : 1 year may suits using timeframe H1 while not 2 year

8 : Homogenize the timeframe used by your EA, more than 1 indicator ? Make them all run on the same timeframe & adapt the period

... at this point you got the thing ... I've reduced mine from more than 4GB to less than 1gb (900Mb approx.), it's now optimizing, with no errors.

NB : 9. Yet the damn error can appear, in my case, using MQL Europe 2 & MQL Usa provided the error - just deactivate it as soon as you see it in the logs - it's time & money consuming since you have to re-pay for the pass re-queued.

That's all folks ! Hope it'll help. 

By the way, if someone know how to reduce the MaxBars in MQL  he's welcome, it seems locked at 100000, even if you change the value from the terminal properties

interesting

 

i'm finding ways to make my optimization faster. Point 1 seems interesting.