Download MetaTrader 5

expert complain that"zero devide"

To add comments, please log in or register
Did you like the article? Share it with your friends!
Fa Cao
1141
Fa Cao 2014.01.14 04:21 
I don't know what is the chance for "(TimeCurrent()-Time[Bar_Low])" or" (TimeCurrent()-Time[Bar_High])" to become 0
      int Bar_Open = iBarShift(NULL,0,OrderOpenTime(),0)
      ,   Bar_High = iHighest(NULL,0,MODE_HIGH,Bar_Open,0)
      ,   Bar_Low  = iLowest(NULL,0,MODE_LOW,Bar_Open,0)
      ,   Profit_Points = NormalizeDouble( (High[Bar_High] - Low[Bar_Low])/Pips_SL,0 )
      ;    
     if(Profit_Points > 55)
     {
      double B =Profit_Points*60/(TimeCurrent()-Time[Bar_Low]),
             S =Profit_Points*60/(TimeCurrent()-Time[Bar_High]);
............
     }
Ubzen
5394
Ubzen 2014.01.14 05:28  
vx0532: expert complain that"zero devide"
I don't know what is the chance for "(TimeCurrent()-Time[Bar_Low])" or" (TimeCurrent()-Time[Bar_High])" to become 0
When Time[Bar_Low] is the same as TimeCurrent(). This could happen when you're dealing with minute bars for example.
Fa Cao
1141
Fa Cao 2014.01.14 05:42  
ubzen:
When Time[Bar_Low] is the same as TimeCurrent(). This could happen when you're dealing with minute bars for example.

there is no chance for them to be the same because of "Profit_Points > 55".
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2014.01.14 09:27  
vx0532:

I don't know what is the chance for "(TimeCurrent()-Time[Bar_Low])" or" (TimeCurrent()-Time[Bar_High])" to become 0

How do you know it is that divide causing the issue ? how have you verified it ?
Fa Cao
1141
Fa Cao 2014.01.14 11:46  
RaptorUK:
How do you know it is that divide causing the issue ? how have you verified it ?


only these two items were devided.
Alain Verleyen
Moderator
30707
Alain Verleyen 2014.01.14 12:05  
vx0532:

only these two items were devided.

 Profit_Points = NormalizeDouble( (High[Bar_High] - Low[Bar_Low])/Pips_SL,0 );
Fa Cao
1141
Fa Cao 2014.01.14 14:29  
angevoyageur:



"Pips_SL" have a fixed value, which i should explain before, sorry for this.
GreenMoney
379
GreenMoney 2014.01.14 15:29  
vx0532:

I don't know what is the chance for "(TimeCurrent()-Time[Bar_Low])" or" (TimeCurrent()-Time[Bar_High])" to become 0

      int Bar_Open = iBarShift(NULL,0,OrderOpenTime(),0)
      ,   Bar_High = iHighest(NULL,0,MODE_HIGH,Bar_Open,0)
      ,   Bar_Low  = iLowest(NULL,0,MODE_LOW,Bar_Open,0)
      ,   Profit_Points = NormalizeDouble( (High[Bar_High] - Low[Bar_Low])/Pips_SL,0 )
      ;    
     if(Profit_Points > 55)
     {
      double B =Profit_Points*60/(TimeCurrent()-Time[Bar_Low]),
             S =Profit_Points*60/(TimeCurrent()-Time[Bar_High]);
............
     }

Are you selecting an order using OrderSelect() before calling OrderOpenTime(), and if so, are you checking OrderSelect's return code to determine whether the OrderSelect was successful? If you are not using OrderSelect() before calling OrderOpenTime() or if OrderSelect() fails and you subsequently call OrderOpenTime(), OrderOpenTime() could return a value of 0. If Bar_Open is 0, this could have unintended effects on Bar_High and Bar_Low, which would also effect the calculations involving Profit_Points, Bar_High, and Bar_Low, including B and S.
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2014.01.14 16:26  
vx0532:

"Pips_SL" have a fixed value, which i should explain before, sorry for this.

OK, so the logical next step is to Print() . . .

(TimeCurrent()-Time[Bar_Low])" or" (TimeCurrent()-Time[Bar_High])

. . . and then you will know if it is zero or not . . . when you get a divide by zero error.

To add comments, please log in or register