Hi,
I have a question about zero divide in indicator when it run. What is wrong. Should we use a trick to fix it? Thanks.
Hi,
I have a question about zero divide in indicator when it run. What is wrong. Should we use a trick to fix it? Thanks.
Function MarketInfo() is wrong. According to the documentation it MUST return a particular kind of "various data about securities listed in the "Market Watch" window" and in the particular case it is "Margin to maintain open orders calculated for 1 lot", which cannot be 0. Nevertheless, the function returns 0. It is wrong.
The trick you might use is first to keep the value returned by the function in an additional variable and then check its value for 0. If it is 0, an error should be signaled somehow instead of performing division. Otherwise, division is to be performed as usual.
A trick ? Yes, don't divide by zero.
Thanks all for the respons. Let me make more clear.
MarketInfo(Symbol(),MODE_MARGINREQUIRED) does have non zero value.
But when we run MT4 with that indicator in it, it has zero divide error.
Then if we compile the indicator, it works.
The question is why it has to compile every we start MT4.
PS : that formula works well if we put in EA
If the symbol you are using has no data at the time you apply the indicator, the MarketInfo() can't return the right value.
Why don't you filter the calculation with : if(MarketInfo(....) > 0)
If the symbol you are using has no data at the time you apply the indicator, the MarketInfo() can't return the right value.
Why don't you filter the calculation with : if(MarketInfo(....) > 0)
Thanks FerruFx.
That's what I meant using a trick. Your explanation is clear for me now.
Thanks FerruFx.
That's what I meant using a trick. Your explanation is clear for me now.
If the symbol you are using has no data at the time you apply the indicator, the MarketInfo() can't return the right value.
Why don't you filter the calculation with : if(MarketInfo(....) > 0)
Of course, the OP get a zero divide error, but there is no division by zero in the code. I suppose you are understanding yourself what you mean.
According to the documentation MarketInfo() CANNOT return 0 for the particular parameter.
The fact it does means the quality of MT4 implementation is quite poor.
What if MarketInfo() returns a non-zero but still wrong value?
Do programmers need to calculate the same value MarketInfo() should return themselves and then check whether MarketInfo() returned a proper value and they can trust it or not?
The system functions must strictly adhere their contracts. If documentation says MarketInfo() does not return zero (for a particular parameter) then there is NO division by zero in "1 / MarketInfo()" expression. But you implicitly stated that there is.
This is definitely the bug of MarketInfo(). And therefore a workaround is needed.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I have a question about zero divide in indicator when it run. What is wrong. Should we use a trick to fix it? Thanks.