Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 570

 

How do I check the condition at a given time? e.g. on the M5 chart, at 22:59, i.e. one minute before the bar closes. check for the whole minute.

      //22:59
      if(open[i]>close[i] && high[i]-low[i]>=100*Point)
        {
         BufferUP[i]=low[i]-distance*Point;
        }
 
PolarSeaman:

How to check the condition at a given time? For example, on the M5 chart, at 22:59, i.e. one minute before the bar closes.

In the indicator on the history - only by reading the data from the younger TF (in this case M1), we will have to fuss. But for the zero bar:

  1. Calculate the time left to close the bar.
  2. If there is 1 minute or less, we do what is necessary.

 
Ihor Herasko:

...Well for the zero bar:

  1. Calculate the time until the bar closes.
  2. If there is 1 minute or less left, then do what is necessary.

That is, current time subtract the bar open time?

Maybe we should skip the iteration if the time is not in the range of 22:59, 23:00

how to write this condition correctly?

 
PolarSeaman:

Is it, the current time subtracted from the bar opening time? Does it count for less than a minute?

Maybe skip the iteration if the time is not in the range 22:59, 23:00

How do I correctly write this condition?

If the time is explicitly set, then it's the same as in the scheme above:

input uint i_uHoursStart = 22; // Час начала действия диапазона
input uint i_uMinutesStart = 59; // Минуты начала действия диапазона
input uint i_uHoursEnd = 23; // Час окончания действия диапазона
input uint i_uMinutesEnd = 00; // Минуты окончания действия диапазона

uint g_uTimeStart, g_uTimeEnd;

int OnInit()
{
...
   g_uTimeStart = i_uHoursStart * 60 + i_uMinutesStart;
   g_uTimeEnd = i_uHoursEnd * 60 + i_uMinutesEnd;
...

}

...
uint uCurDayMinutes = Hour() * 60 + Minute();
if (uCurDayMinutes >= g_uTimeStart && uCurDayMinute < g_uTimeEnd)
{
   // Время от 22:59 до 23:00
}

I didn't check the code. There may be misprints and some errors. The main thing here is the directions of thought.

You must also check that the values of hours and minutes are correct. After all, a user can enter values like 38 hours and 112 minutes.

 
Ihor Herasko:

If the time is explicitly set, then it's the same as above:

I haven't checked the code. There may be typos and some errors. The main thing here is the direction of thought.

You should also check that the values of hours and minutes are correct. After all, a user can enter values like 38 hours and 112 minutes.

In the eye, user, for 112 minutes)

why can't it be like this?

if (TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES)>="22:59"&&TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES)<"23:00")

does not show at the specified time

There will be several ranges each to be switched off

 

the quotes may "fall asleep" for a minute and you will miss the time)

The right thing to do is to make a timer, synchronise local and current time, and in the timer "catch" the right time

 
PolarSeaman:

In the eye, to the user, in 112 minutes)

Why can't you do it this way?

This is exactly the wrong solution, because you are comparing strings, not numbers. Although you can do something with TimeToStr too. But this approach is doomed to be slower than operating with numbers. After all, string operations take much more time than the simplest arithmetic operations (+, -, /, *).

There will be several ranges, each one must be disabled.

This is done by storing the values of the desired ranges into arrays. Admittedly, it's not clear how this would look in the configuration parameters - too many of them would have to be done. The solutions do exist, though. Not simple, but they are available.

 
Taras Slobodyanik:

the quotes may "fall asleep" for a minute and you will miss the time)

The correct way is to make a timer, synchronize local and current time, and "catch" the right time in the timer

Well, you don't have to do anything at a set time. So it's OK))

 
Taras Slobodyanik:

the quotes may "fall asleep" for a minute and miss the time)

correctly make a timer, synchronize local and current time, and in the timer "catch" the right time

can you insert OnCalculate() in OnTimer()?

I don't know how to synchronize local andcurrent time, I can't find it in help.

 
Ihor Herasko:

Well, that's what it takes to do nothing at a given time. So it's OK ))

how, do nothing? only this minute is required to check, and sleep for 24 hours)

Reason: