Questions from Beginners MQL5 MT5 MetaTrader 5 - page 981

 

Friends, can you tell a newbie what's wrong? I want to find bars corresponding to a certain time, below is the code, but it doesn't work.

       MqlRates rates[];
       ArraySetAsSeries(rates,true);
       int copied = CopyRates(NULL,_Period,0,f_bar,rates);
     
        string a1,a2;
          if (copied>0)
         for(int i=0;i<copied;i++)
           {
               a1 = TimeToString (rates[i].time,TIME_DATE);
               a2 = TimeToString(rates[i].time,TIME_MINUTES);
               if(a2=="14:00"){Comment(a1,"\n",a2);break;
           }
 
Alexander Mikryukov:

Friends, can you tell a newbie what's wrong? I want to search for bars corresponding to a certain time, below is the code, but it doesn't work.

Searching for a bar by time

 
Alexander Mikryukov:

Friends, can you tell a newbie what's wrong? I want to find bars corresponding to a certain time, below is the code, but it doesn't work.

And you, sorry not to offend, didn't count the number of crooked brackets?

 
Alexey Viktorov:

I'm sorry, I don't want to offend anyone, but have you considered the number of curve brackets?

This is how I copied it, the compiler doesn't swear.

The task was to select all the bars of a certain hour at a certain period of time and subsequently calculate the parameters of this bar. That is why I decided to master this function. I am just beginning to master MQL5, that is why I may have some silly questions.


I have understood it and it works.

 
Gentlemen, help me out here. I am writing an indicator, which draws max and min of the previous day. How to exclude Saturday and Sunday from drawing?
 
Alexander Mikryukov:
Gentlemen, please help me to understand this. I am developing an indicator that uses max and min of the previous day. How to avoid Saturday and Sunday from drawing?

There are no ticks on the weekend, so the indicator will not do anything. And if it doesn't do anything, it means it won't draw anything :)

 
Alexander Mikryukov:
Gentlemen, help me out here. I am writing an indicator, which draws max and min of the previous day. How to exclude Saturday and Sunday from drawing?

First, show me how you get them, these max and min.

 
There is a function in MQL4
Month()
how to know the month in MQL5?
 
Aliaksandr Yemialyanau:
MQL4 has a function how to know the month in MQL5?

MqlDateTime - structure to store the date.

TimeToStruct- passes the time to the structure.

Now look at the fields of the structure:

struct MqlDateTime 
  { 
   int year;           // год 
   int mon;            // месяц 
   int day;            // день 
   int hour;           // час 
   int min;            // минуты 
   int sec;            // секунды 
   int day_of_week;    // день недели (0-воскресенье, 1-понедельник, ... ,6-суббота) 
   int day_of_year;    // порядковый номер в году (1 января имеет номер 0) 
  };
 
Vladimir Karputov:

MqlDateTime - structure to store the date.

TimeToStruct- passes the time to the structure.

Now look at the fields of the structure:

In addition to this, there are

datetime  TimeCurrent(
   MqlDateTime&  dt_struct      // переменная типа структуры
   );
Документация по MQL5: Дата и время / TimeCurrent
Документация по MQL5: Дата и время / TimeCurrent
  • www.mql5.com
Возвращает последнее известное время сервера, время прихода последней котировки по одному из выбранных в "Обзоре рынка" символов. В обработчике OnTick() данная функция вернет время пришедшего обрабатываемого тика. В других случаях (например, вызов в обработчиках OnInit(), OnDeinit(), OnTimer() и так далее) это –...
Reason: