MarketInfo(_Symbol,MODE_TICKVALUE) equal to zero ?!

 

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

 
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.
 
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 !

 
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 ?
 
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.

 
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;
 
  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).

 
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 ?

 
Or just log it and return. Retest on the next tick.
 
whroeder1:
Or just log it and return. Retest on the next tick.
Which is what I provided as solution. (except logging)
 
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?

Reason: