A division by zero error appeared in one indicator - page 4

 

limit in the code, if 1/2=0.5 then apparently the rounding now gives 0 instead of 1?

To test the hypothesis I changed the code

         double d1=(delta_price_high-center_line_point)/((double)limit/2);
         double d2=(center_line_point-delta_price_low)/((double)limit/2);
 
Aleksey Vyazmikin:

Total trash - got division by zero error again

Code from ME as a picture - maybe I'm blind but I don't understand what's going on

The error is still in the same line.

The file is the same, as the error line has shifted due to the addition of code for the print.

You should usea styler - you would immediately see that your problem string is NOT within the check zone if(limit==0)

 
Vladimir Karputov:

You should usea styler - you would immediately see that your problem string is NOT in the check zone if(limit==0)

So it doesn't need to enter, why?

 

This code.

         int a=1;
         double test=1/(a/2);

Hanging up the terminal.

 
Aleksey Vyazmikin:

limit in the code, if 1/2=0.5 then apparently the rounding now gives 0 instead of 1?

To test the hypothesis I changed the code

Code:

//+------------------------------------------------------------------+
//|                                           writeSpicifiedType.mq5 |
//|                                                              hoz |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "hoz"
#property link      ""
#property version   "1.00"
//---
double high=-1.0;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   for(int limit=0;limit<4;limit++)
     {
      Print("limit (",limit,")/2 ",limit/2);
     }
  }
//+------------------------------------------------------------------+


Result:

Test_en (EURUSD,M30)    limit (0)/2 0
Test_en (EURUSD,M30)    limit (1)/2 0
Test_en (EURUSD,M30)    limit (2)/2 1
Test_en (EURUSD,M30)    limit (3)/2 1
 
Vladimir Karputov:

Code:


Result:

That's the thing, and earlier apparently 1/2 gave a 1, not a zero.

 
Aleksey Vyazmikin:

That's the thing, and before, 1/2 must have been a 1 instead of a zero.

Nope. It always rounded up like that.

 
Vladimir Karputov:

Nope. It's always rounded off like that.

So it's something else after all...

 

Changed the code for the print

         if(limit/2==0)
         {
         limit=2;
         Print("start_time - ",TimeToString(start_time,TIME_DATE|TIME_MINUTES)," stop_time - ",TimeToString(stop_time,TIME_DATE|TIME_MINUTES));
         Print("start_index=",start_index, " stop_index=",stop_index);
         }

and now I get...

2018.07.04 15:47:07.959 IndDrafter (Si-9.18,H1) start_time - 2017.08.10 11:00 stop_time - 2017.08.10 11:00
2018.07.04 15:47:07.959 IndDrafter (Si-9.18,H1) start_index=2012 stop_index=2012

How come?

 
Aleksey Vyazmikin:

Changed the code for the print

and now I get...

How's that?

All is correct. If limit is calculated using the formulalimit=(int)(stop_time-start_time)/PeriodSeconds(_Period);

then the result will be = 0.

Now we need to see how stop and start times are formed.