**belido:**

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.

39025

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.

315

Hi,

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.

315

A trick ? Yes, don't divide by zero.

974

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

108738

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)

974

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.

108738

Thanks FerruFx.

That's what I meant using a trick. Your explanation is clear for me now.

315

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)

39025

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.

315

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.

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.