zero divide error

To add comments, please log in or register
Kenneth Njuguna
223
Kenneth Njuguna  

Hey Folks!! Hope everyone is doing just great!! Kindly assist in resolving a "zero divide error" that keeps coming up at the code below;

     double change;

     double PRI_MA;

     double CUR_MA;

     PRI_MA=iMA(NULL,60,60,0,MODE_SMA,PRICE_CLOSE,60);

     CUR_MA=iMA(NULL,60,60,0,MODE_SMA,PRICE_CLOSE,0);

     change=( CUR_MA - PRI_MA ) / PRI_MA;

Any assistance on how to eliminate this recurring error will be highly appreciated. Thanks 

Sergey Golubev
Moderator
114214
Sergey Golubev  
There is something about it here:
Zero Divide
The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks, as a small error in the expert or indicator logic can cause losses on the trading account. That is why we have developed a series of basic checks to ensure the required quality level of the Market products. If any errors are identified by the Market...
Seng Joo Thio
1205
Seng Joo Thio  
Kenneth Njuguna:

Hey Folks!! Hope everyone is doing just great!! Kindly assist in resolving a "zero divide error" that keeps coming up at the code below;

Any assistance on how to eliminate this recurring error will be highly appreciated. Thanks 

Check that the highlighted value, in this case 60, must not be greater than iBars(Symbol(),60)-60

     PRI_MA=iMA(NULL,60,60,0,MODE_SMA,PRICE_CLOSE,60);
Kenneth Njuguna
223
Kenneth Njuguna  
Seng Joo Thio:

Check that the highlighted value, in this case 60, must not be greater than iBars(Symbol(),60)-60

Thank you Seng Joo Thio. Fixing it!!!!

Kenneth Njuguna
223
Kenneth Njuguna  
Sergey Golubev:
There is something about it here:
Zero Divide

Thanks Sergey Golubev!! Much appreciated!

William Roeder
20207
William Roeder  

Kenneth Njuguna:

     PRI_MA=iMA(NULL,60,60,0,MODE_SMA,PRICE_CLOSE,60);

     CUR_MA=iMA(NULL,60,60,0,MODE_SMA,PRICE_CLOSE,0);
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  3. On MT4: Unless the current chart is that specific pair/ TF referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

To add comments, please log in or register