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

 
Sergey Savinkin:

And why will they be round if you first make CopyRates from hourly timeframe (the round numbers are obtained), then pass to the procedureCreateFigure the time from the current timeframe (time, which turns into Time), and then search the index by the current timeframe?start_index=ArrayBsearch(Time,start_time);

That's right, we're looking for a round time on a non-round time in the array... I.e. looking for, a bar on a minute timeframe on which the time corresponded to the opening time of the hour.

 
О!
 
Алексей Тарабанов:
О!

Emotions are good!

But maybe there will be some substantive thoughts!?

 

Here's what about time for example - I added two variables to save time

void CreateFigure(int i,const datetime &Time[],const double &Open[],const double &High[],const double &Low[],const double &Close[],MqlRates &rates[])
  {
   datetime start_time=rates[i].time;
   datetime stop_time=(start_time+PeriodSeconds(TimeFrames));
   datetime start_timeA=start_time;
   
//---
   int start_index,stop_index,limit;
   datetime vertical_line_time;
//---
   start_index=ArrayBsearch(Time,start_time);
   datetime start_timeB=Time[start_index];   
   if(Time[start_index]<start_time) start_index=(start_index>0?start_index-1:start_index);
   start_time=Time[start_index];
   Print("start_timeA=", start_timeA, " start_timeB=",start_timeB," start_time=",start_time);

We get a print like this

2018.07.05 00:39:30.465 IndDrafter_Test (Si-9.18,M1)    start_timeA=2018.07.04 12:00:00 start_timeB=2018.07.04 12:00:00 start_time=2018.07.04 12:00:00
2018.07.05 00:39:30.465 IndDrafter_Test (Si-9.18,M1)    start_timeA=2018.07.04 13:00:00 start_timeB=2018.07.04 13:00:00 start_time=2018.07.04 13:00:00
2018.07.05 00:39:30.465 IndDrafter_Test (Si-9.18,M1)    start_timeA=2018.07.04 14:00:00 start_timeB=2018.07.04 13:59:00 start_time=2018.07.04 14:05:00
2018.07.05 00:39:30.465 IndDrafter_Test (Si-9.18,M1)    start_timeA=2018.07.04 15:00:00 start_timeB=2018.07.04 15:00:00 start_time=2018.07.04 15:00:00

I.e. as if in a normal/stationary situation everything is correct.

You can see that at 14:00 there is a correction of bar opening time on the minute TF to 14:05 - actual time of the first bar appearance on TF M1.
 
Aleksey Vyazmikin:

Emotions are good!

But maybe there will be some substantive thoughts!?

The hour is the same, so limit=0. I wanted to do it myself.

 
Алексей Тарабанов:

The hour is the same, so limit=0. I wanted to do it myself.

So what if the hour is the same? After all, there are 60 bars in this hour on TF M1!

And in case of coincidence of the current TF and the calculated one there is a protection and there will be no divisions by zero in this situation

if(_Period>=TimeFrames) return(0);
 
Sleeping
 
Алексей Тарабанов:
Sleeping

You're hiding!?

 
Sleeping
 
Алексей Тарабанов:
Sleeping

???