anyone can help me to find which line of code is causing ZeroDivideError? MQL message is not with enough details.

 

Hi

Can someone help me to know which piece of code is causing Zero Divide error, so I can fix it.

2024.03.09 13:30:06.707 login (build 4153)

2024.03.09 13:30:06.722 template file tester.tpl added. 7012 bytes loaded

2024.03.09 13:30:06.725 expert file added: Experts\Algo\EAToTest\TestEA_iVP-v6.ex5. 89413 bytes loaded

2024.03.09 13:30:06.744 successfully initialized

2024.03.09 13:30:06.820 XAUUSD: symbol to be synchronized

2024.03.09 13:30:06.821 XAUUSD: symbol synchronized already, 18 bytes received

2024.03.09 13:30:06.821 XAUUSD: history synchronization started

2024.03.09 13:30:06.825 XAUUSD: load 27 bytes of history data to synchronize in 0:00:00.001

2024.03.09 13:30:06.825 XAUUSD: history synchronized from 2016.01.04 to 2024.03.06

2024.03.09 13:30:06.948 XAUUSD,M15: history cache allocated for 52008 bars and contains 43368 bars from 2022.01.03 01:00 to 2023.10.31 23:45

2024.03.09 13:30:06.948 XAUUSD,M15: history begins from 2022.01.03 01:00

2024.03.09 13:30:06.949 XAUUSD,M15 (Pepperstone-Demo): 1 minutes OHLC ticks generating

2024.03.09 13:30:06.949 XAUUSD,M15: testing of Experts\Algo\EAToTest\TestEA_iVP-v6.ex5 from 2023.11.01 00:00 to 2024.03.06 00:00 started with inputs:

2024.03.09 13:30:06.949   InpSymbol=XAUUSD

2024.03.09 13:30:06.970 2023.11.01 00:00:00   Zero divide, check divider for zero to avoid this error in 'C:\Users\anilh\AppData\Roaming\MetaQuotes\Tester\73B7A2420D6397DFF9014A20F1201F97\Agent-127.0.0.1-3000\MQL5\Experts\Algo\EAToTest\TestEA_iVP-v6.ex5::Indicators\Development\iVP-v6\iVP-v6-V2.01.ex5'

The indicator iVP-v6-V2.01.ex5 is tested without any error in Strategy Tester!!! However, when used it's class in EA, it is giving this error.

attached is screen shot of indicator running well in Strategy Tester.

Files:
 
Anil Varma: Can someone help me to know which piece of code is causing Zero Divide error, so I can fix it.
  1. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked, so we can't see your machine.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    We can't see your broken code.

    Always post all relevant code (using Code button) or attach the source file.


  2. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

 
The strategy tester works differently in the visual mode vs non-visual mode. The indicator may work fine in visual mode, but if you use it in a EA and then test it in non-visual mode, bugs may happen. The error certainly is in the indicator  iVP-v6-V2.01.ex5 code, but we're lacking info about what it could be. The only clue here is that something is dividing by zero - check all divisions in your code and make sure the denominator cannot be 0.
 
Emanuel Cavalcante Amorim Filho #:
The strategy tester works differently in the visual mode vs non-visual mode. The indicator may work fine in visual mode, but if you use it in a EA and then test it in non-visual mode, bugs may happen. The error certainly is in the indicator  iVP-v6-V2.01.ex5 code, but we're lacking info about what it could be. The only clue here is that something is dividing by zero - check all divisions in your code and make sure the denominator cannot be 0.

Thanks a lot @Emanuel Cavalcante Amorim Filho.

I really appreciate your meaningful answer, than just blaming not so share code. (There must be a reason, why I didn't and I hope others will also understand it as you have).

Yes I agree (and understood ZeorDivide error well) the error is caused something is divided by Zero.

My post was to find out is it normal for MQL to return error with such lack of information? In past I have encountered this error few times and always error messages pointed line number or so, to point possible area in the code.

" The indicator may work fine in visual mode, but if you use it in a EA and then test it in non-visual mode, bugs may happen." ... noted and thanks for pointing this information, I was unware of.

For other users of the forum

the update is that it is resolved.

The culprit was calling IsNewBar() in Indicator.OnInit()  without refreshing the associated arrays with this call. So array values with 0 value were being used to divide another variable.

The point here is, if one looks for a variable/0, he will never find the issue as it variable / array[i] ... and value at array[i] = 0.

Once I removed it from OnInit(), the error went off.

Thanks to everyone who responded to the post.

 
I suppose it should tell you where the zero divide happened, similar to an out of range error: (line/character) 
That information should be at the end of the line that you posted - which is so long that it is not displayed here. It says exactly in which file, line and character the error occurred.
 
Tobias Johannes Zimmer #:
I suppose it should tell you where the zero divide happened, similar to an out of range error: (line/character) 
That information should be at the end of the line that you posted - which is so long that it is not displayed here. It says exactly in which file, line and character the error occurred.

do not make a comment unless you have read the full question first. If you had, then you would have seen that it is a resource file, and does NOT give a line number.

 
Tobias Johannes Zimmer #:
I suppose it should tell you where the zero divide happened, similar to an out of range error: (line/character) 
That information should be at the end of the line that you posted - which is so long that it is not displayed here. It says exactly in which file, line and character the error occurred.
If I am not mistaking, the zero divide error details are only printed in non-optimized compile builds.

In many cases these details are actually missing.
 
Michael Charles Schefe #:

do not make a comment unless you have read the full question first. If you had, then you would have seen that it is a resource file, and does NOT give a line number.

Even if your comment is correct in it's assumption, I am sure you are able to phrase this in a more polite manner.


 
Michael Charles Schefe #:

do not make a comment unless you have read the full question first. If you had, then you would have seen that it is a resource file, and does NOT give a line number.

You are right I assumed that. I have not yet seen a zero divide not return line and character numbers. So far. I will book it under Dunning Kruger 🤦🏻‍♂️😂
Thanks for the feedback and sorry for the inconvenience.
 
Anil Varma #:

Thanks a lot @Emanuel Cavalcante Amorim Filho.

I really appreciate your meaningful answer, than just blaming not so share code. (There must be a reason, why I didn't and I hope others will also understand it as you have).

Yes I agree (and understood ZeorDivide error well) the error is caused something is divided by Zero.

My post was to find out is it normal for MQL to return error with such lack of information? In past I have encountered this error few times and always error messages pointed line number or so, to point possible area in the code.

" The indicator may work fine in visual mode, but if you use it in a EA and then test it in non-visual mode, bugs may happen." ... noted and thanks for pointing this information, I was unware of.

For other users of the forum

the update is that it is resolved.

The culprit was calling IsNewBar() in Indicator.OnInit()  without refreshing the associated arrays with this call. So array values with 0 value were being used to divide another variable.

The point here is, if one looks for a variable/0, he will never find the issue as it variable / array[i] ... and value at array[i] = 0.

Once I removed it from OnInit(), the error went off.

Thanks to everyone who responded to the post.


Glad you found it. I had a similar problem once (another error) and it took me a while to understand that the visual mode differs from the non-visual mode. For anyone with a similar issue, just insert lots of Print calls in your indicator code and try to figure out where the error is, since there isn't really an optimal way to debug it in this case.

 
Michael Charles Schefe #:
If you had, then you would have seen that it is a resource file, and does NOT give a line number.

Hi @Michael Charles Schefe

No the indicator does not used any resource files.

Yes it used include files, which I am sure is not treated as 'resource'.

#include <Algo\iVP_v6\CTimeGMT.mqh>                                                     // In PRODUCTION Version comment out
#include <Algo\iVP_v6\CSessionHours.mqh>

#include <Algo\Function\IsNewBar.mqh>
CIsNewBar                               *cIsNewBar;

#include  <Algo\\Base\IndicatorBase.mqh>

a resource file must be included with #resource key word

#define         iHullMAPath "Indicators\\AlgoBulls\\Trend\\iHullMA.ex5"
#resource "\\" + iHullMAPath
Reason: