MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Post Your News in Blogs and Become Famous!

Zero Divide Error

Back to topics list To post a new topic, please log in or register
avatar
8
arfian 2010.02.11 15:54
 

Hi, I have this strange error "Zero Divide", when loading attached indicator. Can somebody solve the code, so that the error will not show in the future.


Thanks,

Attached files:
  g7_usdn.mq4  (4.48 KB)
 
SOMETHING TO READ - How Legendary Traders Made Millions: Profiting From the Investment Strategies of the Gretest Traders of All time
From the author of three market books published by McGraw-Hill, Lessons From the Greatest Stock Traders of All Time was chosen by Barron's as one of the top 25 Best Books of 2004. A former stockbroker and currently a financial controller, his second book was released in April 2006 titled How Legendary Traders Made Millions.
avatar
Moderator
2029
gordon 2010.02.11 16:48 #
 
arfian:

Hi, I have this strange error "Zero Divide", when loading attached indicator. Can somebody solve the code, so that the error will not show in the future.


Thanks,

You should verify that every denominator is not zero BEFORE dividing (unless it's a non-zero constant). You can also add print statements to pinpoint the problem:


if ( x!=0 ) 
   y = z/x;  
else  
   Print("Warning: x==0");
 
avatar
857
fbj 2010.02.11 19:07 #
 

arfian, your code uses expressions which get divided by iClose(...)

iClose() can return ZERO. This happens when local history for the symbol is not available until received from server. Usual method is to detect the ZERO and confirm that the terminal's error code is ERR_HISTORY_WILL_UPDATED (4066) and if so, reissue call to iClose(). Sometimes, a Sleep() is used to allow for server -> terminal updates.

hth


if you are not ok with MQL4, suggest you look at THE BOOK via link at page top.

 
avatar
8
arfian 2010.02.11 20:09 #
 
fbj:

arfian, your code uses expressions which get divided by iClose(...)

iClose() can return ZERO. This happens when local history for the symbol is not available until received from server. Usual method is to detect the ZERO and confirm that the terminal's error code is ERR_HISTORY_WILL_UPDATED (4066) and if so, reissue call to iClose(). Sometimes, a Sleep() is used to allow for server -> terminal updates.

hth


if you are not ok with MQL4, suggest you look at THE BOOK via link at page top.

Actually i'm not a mql programmer. I Just use the indicator, from your explanation, is it the iClose() that make the error? Sorry for my newbie thought.

 
avatar
1184
jjc 2010.02.11 20:14 #
 
fbj:

arfian, your code [...]

It's not "his" code. It's clearly come out of a decompiler.

avatar
8
arfian 2010.02.11 20:19 #
 
jjc:

It's not "his" code. It's clearly come out of a decompiler.

Yup its not mine, but I'm not using Decompiler, I just downloaded from one of the thread in forex forum. It seem good indicator, so i tried, but that error came out. I dont know the owner of that indicator.

 
Back to topics list  

To add comments, please log in or register