Backtestesting error

 

Hi, i have a problem with backtesting that maybe someone would be willing to help me with. When i try to backtest my EA it cannot load an indicator, i tried with multiple custom and built-in, niether worked. I run backtests on multiple pairs, usually more than 20, on 10-15 years of daily data. The problem is with creating an indicator handle on some pairs, some work fine, since i use a for loop to create the handles, the error occurs somewhere in the middle. It also works fine with less pairs, for example 5, and on a shorter period of time. For me if is quite important that i get this much data, because i trade on the daily so something like 2 years worth of data simply isn't enough. My first thoughts are that something is wrong with the data imported, because i tried multiple indicators, started from the beginning and writing all the code again, restoring windows to a version i had installed when everything worked fine, updating and reinstalling MT5, creating a new demo acc,  everthing i could think of. I saw somewhere that Metatrader compresses data from a long time ago, making 1 minute charts after a certain date one bar equaling to an hourly bar instead of M1.I will append the code and errors below, if i missed any important data i am happy to provide it in the comments as this really makes it impossible to work.

Thanks..

Files:
 
reday1324:

Hi, i have a problem with backtesting that maybe someone would be willing to help me with. When i try to backtest my EA it cannot load an indicator, i tried with multiple custom and built-in, niether worked. I run backtests on multiple pairs, usually more than 20, on 10-15 years of daily data. The problem is with creating an indicator handle on some pairs, some work fine, since i use a for loop to create the handles, the error occurs somewhere in the middle. It also works fine with less pairs, for example 5, and on a shorter period of time. For me if is quite important that i get this much data, because i trade on the daily so something like 2 years worth of data simply isn't enough. My first thoughts are that something is wrong with the data imported, because i tried multiple indicators, started from the beginning and writing all the code again, restoring windows to a version i had installed when everything worked fine, updating and reinstalling MT5, creating a new demo acc,  everthing i could think of. I saw somewhere that Metatrader compresses data from a long time ago, making 1 minute charts after a certain date one bar equaling to an hourly bar instead of M1.I will append the code and errors below, if i missed any important data i am happy to provide it in the comments as this really makes it impossible to work.

Thanks..

I have gone through your code and found nothing that could be the cause of your difficulties. I therefore suspect that the cause of those difficulties can be found in the directory where your code is being executed.

if the executor is in a subdirectory of the EA directory, that may be the reason why an indicator is not being loaded.

 
LUC JACOBUS A VERHEECKE:

I have gone through your code and found nothing that could be the cause of your difficulties. I therefore suspect that the cause of those difficulties can be found in the directory where your code is being executed.

if the executor is in a subdirectory of the EA directory, that may be the reason why an indicator is not being loaded.

I'm not sure if i understand you correctly, is the path to the EA that's causing problems, or the indicator, as i have both of them in their own folders that are inside the default data folder for MT5. I am sorry for the probably obvious question, but since these are the kind of errors i try to understand, what is an executor, is it a compiled file of the code - an ex5 file?

I will try to move the files of the indicator and the ea to see the results, will report back

 
So i tried moving my expert to every folder in MQL5/Experts and without a subfolder, tried moving my indicator to it's designated directory, later tried everything again with it in the same folder as the expert, nothing worked. Is there anything else i can try? Or else i will just backup my PC and try reseting it, or maybe try it with linux, has anyone got any experience with double operating systems for MT5 or any other tips? Maybe I'll try downloading some data for backtesting and try it with that, any tips are appreciated
Testing trading strategies on real ticks
Testing trading strategies on real ticks
  • www.mql5.com
The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.
 
reday1324:
So i tried moving my expert to every folder in MQL5/Experts and without a subfolder, tried moving my indicator to it's designated directory, later tried everything again with it in the same folder as the expert, nothing worked. Is there anything else i can try? Or else i will just backup my PC and try reseting it, or maybe try it with linux, has anyone got any experience with double operating systems for MT5 or any other tips? Maybe I'll try downloading some data for backtesting and try it with that, any tips are appreciated

bonjour reday1324

I mentioned that to you because it reminded me of an identical difficulty that I could overcome by posting the .ex5 in the Expert / Advisor directory. I ran your program and received no error message. I'm very sorry, but I have no other idea to help you.

 
LUC JACOBUS A VERHEECKE:

bonjour reday1324

I mentioned that to you because it reminded me of an identical difficulty that I could overcome by posting the .ex5 in the Expert / Advisor directory. I ran your program and received no error message. I'm very sorry, but I have no other idea to help you.

Or another suggestion could be: erase the STA-files on your computer; download the STA.mq5 file from this site and then recompile it on your computer... 

 
LUC JACOBUS A VERHEECKE:

Or another suggestion could be: erase the STA-files on your computer; download the STA.mq5 file from this site and then recompile it on your computer... 

Will try that, thanks for your help, if it won't work i'll just reset my computer as that is probably the error then

 
SymbolSelect(SymbolArray[SymbolLoop],true);
⋮
handle_SSL[SymbolLoop] = iMA(SymbolArray[SymbolLoop],PERIOD_D1,15,0,MODE_EMA,PRICE_CLOSE)
Your code is opening multiple daily charts. No where between those two statements do you wait for that chart to be created.
 
William Roeder:
Your code is opening multiple daily charts. No where between those two statements do you wait for that chart to be created.
Thank you, this helped me, but i was only able to get one good backtest, as i wasn’t sure what i was doing, that’s why i would appreciate if you could help me if you have any experience with this. Searching through the threads i found a quick fix with the Sleep() function after adding pairs to the marketwatch with the for loop, but this isn’t the way to go in the long run, it’s already inconsistent. I also experimemted with this: https://www.mql5.com/en/code/1251 but didn’t manage to get it working.
Thanks for you help!
Documentation on MQL5: Common Functions / Sleep
Documentation on MQL5: Common Functions / Sleep
  • www.mql5.com
Sleep - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

After many unsuccessful attempts i still am  unable to get it working. I tried everything i could find but unfortunately nothing really worked for me, the links William Roeder kindly provided didn't really solve the problem, they did however deepen my knowlege of the platform, i hope i didn't miss anything, the closest to the solution i came was this: creating the handles outside of OnInnit because as i understand it OnInnit is finished when all the charts are synchronized, thats why i decidet to create the handles on on tick like this:

void OnTick()
   {
      if(handles_to_do)
      {
         handles_to_do = false;
         SetUpIndicatorHandles();
      }...

and calling the CopyTime() function in OnInnit inside a for loop for all the pairs:

for(int SymbolLoop=0; SymbolLoop < NumberOfTradeableSymbols; SymbolLoop++)
      {
         OpenTradeOrderTicket[SymbolLoop] = 0;
         int countTime=CopyTime(SymbolArray[SymbolLoop],TradeTimeframe,TimeCurrent(),1000,times);
         
      }

This however doesn't solve all my problems, an error is still present, i just think it pust me closerto the solution:


I realy don't have an idea what to do anymore, any help is appreciated, I'll add the code down below again, as i am not sure if this is the only thing i changed.

Files:
STA.mq5  12 kb
prenos.png  68 kb
Reason: