Questions from Beginners MQL5 MT5 MetaTrader 5 - page 532
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
We will get the seconds we need to round up - rounding is the problem.
duh
and there is rounding to the beginning of the day. 86400=24*60*60I 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.
well
and there is a rounding off to the beginning of the day. 86400=24*60*60There 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.
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.
And you say structure... :)
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?
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:
Never mind, it's not necessary)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;
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.