Download MetaTrader 5

expert complain that"zero devide"

To add comments, please log in or register
Fa Cao
1141
Fa Cao  
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
5390
Ubzen  
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  
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
18021
Simon Gniadkowski  
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  
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
32820
Alain Verleyen  
vx0532:

only these two items were devided.

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



"Pips_SL" have a fixed value, which i should explain before, sorry for this.
GreenMoney
379
GreenMoney  
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
18021
Simon Gniadkowski  
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