EA only runs after 2nd or 3rd attempt on backtest

 

Whenever I click "start" my EA usually needs 2 or 3 attempts to run on the Strategy Tester. It uses multiple time frame analysis. The error I'm getting is a zero value at an iAM calculation on the very first bar (which leads to a zero divide since I'm dividing one iMA from another iMA). I have 5 years of full history data from Tickstory and trying the strategy tester with plenty bars in the past for calculation (altough I only use 32 bars for that). Strange thing is that it DOES RUN after 2nd or 3rd try (just click start again). What could be the issue? Anyone?

Thank you.

Eddie 

 
EAlbuquerque:

Whenever I click "start" my EA usually needs 2 or 3 attempts to run. It uses multiple time frame analysis. The error I'm getting is a zero value in an iAM calculation on the very first bar (which leads to a zero divide since I'm diving one iMA from another iMA). I have 5 years of full history data from Tickstory. Strange thing is that it DOES RUN after 2nd or 3rd try (just click start again). What could be the issue? Anyone?

  1. If you are using multi-timeframe and TickStory, then you must produce both FXT and HST files and set both to read-only. This is because multi-timeframe will use the HST files and not the FXT files.
    (see also https://www.mql5.com/en/forum/159520, and also https://www.mql5.com/en/forum/158622)
  2. Since you are using 3rd party FXT files (TickStory), your EA must start at a date further in from the start of available data or you must check the "Bars" count before using history data (such as using the iMA function) to prevent trying to retrieve unknown data and causing "divide by zero" or "array out of range" errors . For example, during the very first bar, there is no available history prior to the current bar (index = 0) because that is where your FXT and HST data begins.
    (see also https://www.mql5.com/en/forum/158878)
  3. Also, when using multi-timeframe, your EA must also handle the delay that will take place before the data is available, by checking for Error 4073 or 4066 that might occur on the first run. That is why it may only run on the 2nd or 3rd try.
    (see also https://www.mql5.com/en/forum/158938/page2#1034408)
 
FMIC:
  1. If you are using multi-timeframe and TickStory, then you must produce both FXT and HST files and set both to read-only. This is because multi-timeframe will use the HST files and not the FXT files.
    (see also https://www.mql5.com/en/forum/159520, and also https://www.mql5.com/en/forum/158622)
  2. Since you are using 3rd party FXT files (TickStory), your EA must start at a date further in from the start of available data or you must check the "Bars" count before using history data (such as using the iMA function) to prevent trying to retrieve unknown data and causing "divide by zero" or "array out of range" errors . For example, during the very first bar, there is no available history prior to the current bar (index = 0) because that is where your FXT and HST data begins.
    (see also https://www.mql5.com/en/forum/158878)
  3. Also, when using multi-timeframe, your EA must also handle the delay that will take place before the data is available, by checking for Error 4073 or 4066 that might occur on the first run. That is why it may only run on the 2nd or 3rd try.
    (see also https://www.mql5.com/en/forum/158938/page2#1034408)

FMIC,

Thank you for reply.

I must say that marking HST as read-only solved the issue for the EURUSD (which I thank you very much for!) but not the SP500. Any clues why the issue was solved marking the HST only for the EURUSD? I must add that I had already disconnected my broker account to prevent overwriting. All the MT4 standard EAs run fine on my history data.

As for the quantity of history bars I do get enough of them, as I said I have 5 years of data and I'm trying the strategy tester with plenty bars in the past for calculation (although I only use 32 bars for that). In fact, I left a full year of history behind to prevent that from happening.

How do I check whether I'm getting errors 4073 or 4066? The log only shows where in the code the zero divide happened (which is at the iMA division) and then it says "Testing pass stopped due to a critical error in the EA".

Thank you a lot! 


 

 
EAlbuquerque:

FMIC,

Thank you for reply.

I must say that marking HST as read-only solved the issue for the EURUSD (which I thank you very much for!) but not the SP500. Any clues why the issue was solved marking the HST only for the EURUSD? I must add that I had already disconnected my broker account to prevent overwriting. All the MT4 standard EAs run fine on my history data.

As for the quantity of history bars I do get enough of them, as I said I have 5 years of data and I'm trying the strategy tester with plenty bars in the past for calculation (although I only use 32 bars for that). In fact, I left a full year of history behind to prevent that from happening.

How do I check whether I'm getting errors 4073 or 4066? The log only shows where in the code the zero divide happened (which is at the iMA division) and then it says "Testing pass stopped due to a critical error in the EA".

Thank you a lot! 


 

UPDATE: I've put the EURUSD to run for a long time and in the middle of the test it gave the bloody error. And restarting the MT4 terminal also produced the error once again like before, at the very beggining. So putting the HST files as read-only actually didn't solve the issue at all. It either runs and stops in the middle or doesn't run at all after 2 or 3 tries.
 
EAlbuquerque:

I must say that marking HST as read-only solved the issue for the EURUSD (which I thank you very much for!) but not the SP500. Any clues why the issue was solved marking the HST only for the EURUSD? I must add that I had already disconnected my broker account to prevent overwriting. All the MT4 standard EAs run fine on my history data.

As for the quantity of history bars I do get enough of them, as I said I have 5 years of data and I'm trying the strategy tester with plenty bars in the past for calculation (although I only use 32 bars for that). In fact, I left a full year of history behind to prevent that from happening.

How do I check whether I'm getting errors 4073 or 4066? The log only shows where in the code the zero divide happened (which is at the iMA division) and then it says "Testing pass stopped due to a critical error in the EA".

Thank you a lot!

UPDATE: I've put the EURUSD to run for a long time and in the middle of the test it gave the bloody error. And restarting the MT4 terminal also produced the error once again like before, at the very beggining. So putting the HST files as read-only actually didn't solve the issue at all. It either runs and stops in the middle or doesn't run at all after 2 or 3 tries.

  1. Error 4073 and 4066 are not reported to the logs because they don't stop the execution. You have to handle those errors in the code itself. In other words, when you call iMA() you must afterwards check the last error code and handle the situation accordingly.
  2. I suggest that you don't disconnect from the broker, because otherwise you will not be able to get certain key information that is required at run-time of the strategy tester such as current prices of currencies to do conversions, etc.
  3. As a whole, without access to your code it is not possible for us to ascertain the exact nature of the problem and offer an exact solution. All we can do is guess at possible problem sources and offer some guidance to resolving them. However, it is definitely a coding related issue.
 
FMIC:
  1. Error 4073 and 4066 are not reported to the logs because they don't stop the execution. You have to handle those errors in the code itself. In other words, when you call iMA() you must afterwards check the last error code and handle the situation accordingly.
  2. I suggest that you don't disconnect from the broker, because otherwise you will not be able to get certain key information that is required at run-time of the strategy tester such as current prices of currencies to do conversions, etc.
  3. As a whole, without access to your code it is not possible for us to ascertain the exact nature of the problem and offer an exact solution. All we can do is guess at possible problem sources and offer some guidance to resolving them. However, it is definitely a coding related issue.

Thank you once again.

I did what you told me: it is error 4073 (no history data). Well, a couple of comments/questions:

1) Now that I'm printing the error on every iteration (I called "Alert" to check on it) the strategy tester doesn't hang the execution due to a zero divide anymore. I suspect that it has something to do with the fact that I'm somehow pre-loading the data or pre-calculating the iMA. This seems to have the same effect as trying to run it for 2nd or 3rd attempt. What I don't understand is: if the iMA (in the denominator) is indeed zero, then why no zero divide error anymore?

2) I'm executing the code on every tick and the iMA uses shift 1 (last closed candle), hence the 4073 error should happen in EVERY tick that is in theory affected my such missing data. HOWEVER, only one tick in the middle of nowhere has this error - its predecessor and sucessor are ok.

Your help is being much appreciated!

Thank you!

 
EAlbuquerque:

I did what you told me: it is error 4073 (no history data). Well, a couple of comments/questions:

1) Now that I'm printing the error on every iteration (I called "Alert" to check on it) the strategy tester doesn't hang the execution due to a zero divide anymore. I suspect that it has something to do with the fact that I'm somehow pre-loading the data or pre-calculating the iMA. This seems to have the same effect as trying to run it for 2nd or 3rd attempt. What I don't understand is: if the iMA (in the denominator) is indeed zero, then why no zero divide error anymore?

2) I'm executing the code on every tick and the iMA uses shift 1 (last closed candle), hence the 4073 error should happen in EVERY tick that is in theory affected my such missing data. HOWEVER, only one tick in the middle of nowhere has this error - its predecessor and sucessor are ok.

  • The fact that you are printing the Error, helps to delay the code execution, giving MetaTrader time to prepare the data for the EA. Since, you are getting error 4073, you will have to change your code and create a routine that first prepares and waits for the data to be fully available, and then and only then, should it then begin processing the data (ticks and bars) and applying your strategy.
  • Without knowing your code, I cannot offer any further specific help. All I can do for now, is highlight the need for you to please read my post (and sample code) that I referenced before, namely https://www.mql5.com/en/forum/158938/page2#1034408.
    Try to read the entire thread so that you can understand the post in context.
  • If you require further help, in which you don't want to post your code here, but would like me to look at it, then send me a PM.
 
FMIC:
  • The fact that you are printing the Error, helps to delay the code execution, giving MetaTrader time to prepare the data for the EA. Since, you are getting error 4073, you will have to change your code andcreate a routine that first prepares and waits for the data to be fullyavailable, and then and only then, should it then begin processing thedata (ticks and bars) and applying your strategy.
  • Without knowing your code, I cannot offer any further specific help. All I can do for now, is highlight the need for you to please read my post (and sample code) that I referenced before, namely https://www.mql5.com/en/forum/158938/page2#1034408.
    Try to read the entire thread so that you can understand the post in context.
  • If you require further help, in which you don't want to post your code here, but would like me to look at it, then send me a PM.

Thank you very much for your help. I'll include a routine to check only the first tick on every candle, not every tick. This will probably solve the problem as there'll be less data access to be made. I'll contact you if I still face problems after that!

Obrigado! ;-)

Eduardo 

 
EAlbuquerque: Obrigado! ;-)
Não há de quê!
Reason: