zero divide error

Back to topics list To post a new topic, please log in or register
avatar
10
ivolux 2015.06.11 10:49
 

Hello.

Can anyone shed some light on this?

I`m geting zero divide error when my EA calculates lot size. It only happens in Strategy tester on EURUSD and USDJPY when testing in tick mode ( control points works fine) 

This is the code I use:

double lot = MathFloor(((risk / NumberOfOrders)) / (((openPrice-sl) / Point) * MarketInfo(Symbol(),MODE_TICKVALUE)) / LotStep)*LotStep; 

  Also tried this and get the same result

double lot = NormalizeDouble((risk/ NumberOfOrders)/(openPrice-sl)*Point/(MarketInfo(Symbol(), MODE_TICKVALUE)),2);


Looks to me that for some reason Point and MODE_TICKVALUE return 0 values?

 Any help much appreciated.

Thanks

Ivo 

avatar
Moderator
3407
GumRai 2015.06.11 14:38 #
 
Maybe  NumberOfOrders returns zero?
avatar
10
ivolux 2015.06.16 13:28 #
 
GumRai:
Maybe  NumberOfOrders returns zero?

No not NumberOfOrders.

It was TICKVALUE got it sorted now anyway, Thanks 

avatar
313
JD4 2015.06.23 08:05 #
 

Speaking from a programming side of things (not MQL, but I have an Associates Degree in computers), a zero error is a pain in the ass.  The best way to resolve it, if it pops up, is to test for the possibility of the item you are dividing for being a zero, usually with an if/else type of statement, like the following

If variable==0

{

  do this code

}

else

{

  do this code

}


Back to topics list  

To add comments, please log in or register