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

 
Aleksey Vyazmikin:

Suppose we have

We know thatstart_time should be2018.04.28 23:00

So it turns out that the time is wrong here ?

Alexey, take a look at my example. I showed there line by line how the hourly time you pass is converted to the nearest time from the current bar.

 
I couldn't find a declaration of the variable limit type. My eyesight is weak.
 
Алексей Тарабанов:
Couldn't find a declaration of the variable type limit. My eyesight is weak.

Post 50, procedure OnCalculate

 
Sergey Savinkin:

Post 50, OnCalculate procedure

Thanks, but which one is 50? Can you help me out with a link?

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

Thanks, but which one is the 50? Can you help me out with a link?

https://www.mql5.com/ru/forum/262864/page5

The link is just to the page. It says #50 in the title of the post. Your #74 ))

В одном индикаторе появилась ошибка деления на ноль
В одном индикаторе появилась ошибка деления на ноль
  • 2018.07.04
  • www.mql5.com
Общее обсуждение: В одном индикаторе появилась ошибка деления на ноль
 
Thank you
 
Sergey Savinkin:
You havelimit=start_index-stop_index+1 written first, that islimit==1, and then where the division by 2 islimit=(int)(stop_time-start_time)/PeriodSeconds(_Period). One is not added. Zero is divided by the period.

Right,limit=start_index-stop_index+1is for i>0, i.e. for history calculation, and limit=(int)(stop_time-start_time)/PeriodSeconds(_Period) is for calculation on the current bar.

And the thing is, in fact, why our time is so crooked - if we have an hour timeframe, the dates must be round, both at the beginning and at the end - this is the real problem, that the bar time on the start date is somehow wrong!!!

Perhaps there is a problem here.

start_index=ArrayBsearch(Time,start_time);

As start_time comes correct at this point

datetime start_time=rates[i].time;
 
Alexei, there is no 'at the end'. It's just quantisation. At exactly 18:00 the bar opened, showed a minimum and a maximum and safely closed, in the same second.
 
Алексей Тарабанов:
Alexey, there is no "at the end". It's just a quantization. Exactly at 18:00 the bar opened, showed minimum and maximum and safely closed, in the same second.

For example, the bar opened at 18:00, so the initial time(start_time) will be 18:00 and the final time(stop_time) is supposed to be 19:00 for the hourly timeframe. Thus, the index between them will be different on the M1 timeframe. And in the code, the start and the end index are the same, which is not true.

 
Aleksey Vyazmikin:

Right,limit=start_index-stop_index+1is for i>0, i.e. for history calculation, and limit=(int)(stop_time-start_time)/PeriodSeconds(_Period) is for calculation on the current bar.

And the thing is, in fact, why our time is so crooked - if we have an hour timeframe, the dates must be round, both at the beginning and at the end - this is the real problem, that the bar time on the start date is somehow wrong!!!

Perhaps there is a problem here.

Since start_time comes correct at this point

And why are they round, if you first make CopyRates from hourly timeframe (it turns out round numbers), then pass to the procedureCreateFigure time from the current timeframe (time, which turns into Time) and Rates from hourly timeframe, and then look for an index in the array of current time?start_index=ArrayBsearch(Time,start_time);