Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via Visa QIWI Wallet
Ivo Luhse
660
Ivo Luhse 2015.06.11 08: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 

Keith Watford
Moderator
7862
Keith Watford 2015.06.11 12:38  
Maybe  NumberOfOrders returns zero?
Ivo Luhse
660
Ivo Luhse 2015.06.16 11:28  
GumRai:
Maybe  NumberOfOrders returns zero?

No not NumberOfOrders.

It was TICKVALUE got it sorted now anyway, Thanks 

JD4
1101
JD4 2015.06.23 06: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

}

/
To add comments, please log in or register