Questions from Beginners MQL5 MT5 MetaTrader 5 - page 532

 
-Aleks-:
We will get the seconds we need to round up - rounding is the problem.

duh

datetime Day00=86400*(time[n]/86400);//начало дня
and there is rounding to the beginning of the day. 86400=24*60*60
 
-Aleks-:

I can't figure out how to use it.

The second value requires"MqlDateTime&dt_struct// structure for taking values" and I don't understand how to use this MqlDateTime.

There is a time. Time has such parameters as: year, month, day, hours, minutes, seconds, etc. Calling function TimeToStruct(), you decompose time into these components. Then, for example, you can zero out hours, minutes and seconds - you get the beginning of day.

MqlDateTime is a data type, just like int, bool, etc. It is just a compound type, i.e. to access its fields (hours, minutes, seconds...) you need to use a point. For example: dt_struct.hour - hour value. Read more about structures at https://www.mql5.com/ru/docs/basis/types/classes.

Документация по MQL5: Основы языка / Типы данных / Структуры и классы
Документация по MQL5: Основы языка / Типы данных / Структуры и классы
  • www.mql5.com
Основы языка / Типы данных / Структуры и классы - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
What does this comment on the order in the logbook mean as it changes nothing

 
Aleksey Lebedev:

well

and there is a rounding off to the beginning of the day. 86400=24*60*60
According to your formula we get the number of days between the current bar and the remote, but these days are conditional, it could be 9 o'clock this day and 1 hour the day before, then the difference in seconds is 122400 , which is 1.42 days - when rounded to 1 day, and the need to be 2.
 
Alexey Kozitsyn:

There is time. Time has parameters such as: year, month, day, hours, minutes, seconds, etc. By calling the TimeToStruct() function, you decompose time into these components. Then, for example, you can zero out hours, minutes and seconds - you get the beginning of day.

MqlDateTime is a data type, just like int, bool, etc. It is just a compound type, i.e. to get access to its fields (hours, minutes, seconds...) you need to use a point. For example: dt_struct.hour - hour value. Read more about structures at https://www.mql5.com/ru/docs/basis/types/classes.

And how, I'm sorry, to perform this zeroing?
 
-Aleks-:
According to your formula we obtain the number of days between the current bar and the remote, but these days are conditional, ie it may be 9 o'clock the current day and 1 hour of the day before. Then the difference in seconds will be 122400, which equals 1.42 days - when rounded to 1 day, and the need to have 2.

a day lost, 23h+24h+9h=2 days 8h... I don't need this formula if I need it:

I need to calculate on each graph of the current timeframe. For calculation I need to know the date of the upper timeframe (days). Above I have attached the code - the point is to know on each bar the maximal price of the upper TF at the moment of bar opening in the current timeframe.

Again:
datetime Day00=86400*(time[n]/86400);//начало дня для time[n]



And you say structure... :)

 
Aleksey Lebedev:

a day lost, 23h+24h+9h=2 days 8h... You don't need this formula if you need it:

Again:



And you say structure... :)

Why do you have 23 hours - I wrote 1 hour, but the point doesn't change.

24 (the day before - one hour yesterday)+24 (yesterday - one hour today)+8 (after one hour today - minus one hour)=56/24=2.33, so it made two days, don't you agree?

 
-Aleks-:

Why do you have 23 hours - I wrote 1 hour, but the essence does not change

24 (the day before - at 1 o'clock yesterday)+24 (yesterday - at 1 o'clock today)+8 (after 1 o'clock today - minus 1 o'clock) =56/24=2,33, so it is two days, don't you agree?

23h before yesterday +

24h yesterday +

9h today=

2 days 8h=2,(33)days

That's the right way to do it:

int DayN=time[0]/86400-time[163]/86400;

Never mind, it's not necessary)
 
Aleksey Lebedev:

23h before yesterday+

24h yesterday+

9h today=

2 days 8h=2,(33)days

The correct way is something like this:

Never mind, it's not necessary)

Now let's imagine that it is not 9h this day but 19

24(the day before yesterday +24(yesterday - 1h today)+18(after 1h today - minus 1h)=66/24=2.75 i.e. it makes three days, do you agree?

As though the range has not changed daily, and the calculation during the day gives then 2, then 3 days - in this the trouble.

The variant

 int DayN=time[0]/86400-time[163]/86400;

It is also not good, if we assume that the current bar is 1 hour and the calculated one is 23 hours, in this case the result of the calculation will be zero, while it should be 1.
 
-Aleks-:
This also does not work if we assume that the current bar is 1 hour and the estimated bar is 23 hours, in which case the result of the calculation is zero and should be 1.

It will be 1, both times are first rounded up to a whole day, then subtracted.

Reason: