Download MetaTrader 5

MarketInfo(_Symbol,MODE_TICKVALUE) equal to zero ?!

To add comments, please log in or register
parham.trader
375
parham.trader  

Hi friends

I wonder how could it be possible for "MarketInfo(_Symbol,MODE_TICKVALUE)" to be equal to zero?

I've written the code below to calculate the broker's commission in point but sometime it takes the zero divide error !

   double commission_in_point=((commission_per_lot)/MarketInfo(_Symbol,MODE_TICKVALUE))*_Point;

and then my EA doesn't work anymore.

I'd appreciate if anyone can guide me on this issue.

thanking in advance

Alain Verleyen
Moderator
34471
Alain Verleyen  
Either because the information is not available yet (for example if you run this code in OnInit()) or it's not provided by the broker.
parham.trader
375
parham.trader  
Alain Verleyen:
Either because the information is not available yet (for example if you run this code in OnInit()) or it's not provided by the broker.

Thank you for your prompt response.

I actually use it on the OnTick Func.

what is the solution for this ?

the first solution I found is to use the "while" for checking it but I'm aware if it become an endless loop !

Alain Verleyen
Moderator
34471
Alain Verleyen  
parham.trader:

Thank you for your prompt response.

I actually use it on the OnCalculate Func.

what is the solution for this ?

the first solution I found is to use the "while" for checking it but I'm aware if it become an endless loop !

Is it always returning 0 ? or only sometimes ?
parham.trader
375
parham.trader  
Alain Verleyen:
Is it always returning 0 ? or only sometimes ?

Only sometimes as I attach my EA to the chart it takes the zero divide error and the EA won't work anymore, and as I remove the EA and reattach it on the chart it doesn't take the error and the EA can resume its operations.

Alain Verleyen
Moderator
34471
Alain Verleyen  
parham.trader:

Only sometimes as I attach my EA to the chart it takes the zero divide error and the EA won't work anymore, and as I remove the EA and reattach it on the chart it doesn't take the error and the EA can resume its operations.

Add a test on the returned value to avoid "zero divide" error.

double tickValue=MarketInfo(_Symbol,MODE_TICKVALUE);
if(tickValue==0)
  {
   return(0);
  }
double commission_in_point=((commission_per_lot)/tickValue)*_Point;
Carl Schreiber
Moderator
7837
Carl Schreiber  
  1. You have to check the error (_LastError) - could be 4066.
  2. if it is an indicator (they "can't" sleep!!) you have to return from OnCalculate() (skipping all the ticks unless ...)
  3. if it is a script or an EA you can loop (with Sleep(100)) until the requested value arrives!

The tickvalue is constantly updated by the server and I think it is provided as the last (my guess).

parham.trader
375
parham.trader  
Carl Schreiber:
  1. if it is a script or an EA you can loop (with Sleep(100)) until the requested value arrives!

The tickvalue is constantly updated by the server and I think it is provided as the last (my guess).


You mean using "Sleep" and "while" together until the MarketInfo(_Symbol,MODE_TICKVALUE) change to non-zero ?

whroeder1
16820
whroeder1  
Or just log it and return. Retest on the next tick.
Alain Verleyen
Moderator
34471
Alain Verleyen  
whroeder1:
Or just log it and return. Retest on the next tick.
Which is what I provided as solution. (except logging)
parham.trader
375
parham.trader  
whroeder1:
Or just log it and return. Retest on the next tick.

what do you mean by "log it"? could you please describe it a bit more?

12
To add comments, please log in or register