Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1571

 
sportoman [iHighest(NULL,0,MODE_CLOSE,period,i)];

MinL = Low[iLowest(NULL,0,MODE_CLOSE,period,i)];

MaxH = high[iHighest(NULL,0,MODE_CLOSE,period,i)];

MinL = low[iLowest(NULL,0,MODE_CLOSE,period,i)];

 
Vitaly Muzichenko #:

MaxH = high[iHighest(NULL,0,MODE_CLOSE,period,i)];

MinL = low[iLowest(NULL,0,MODE_CLOSE,period,i)];

thanks, but it doesn't work at all like in mql4

 
sportoman #:

thanks, but it doesn't work the same way as in mql4

ArraySetSeries(high,true) is also needed there..default array indexing is different in mt5.

 
sportoman #:

MaxH = high[iHighest(NULL,0,MODE_CLOSE,period,i)];

MinL = low[iLowest(NULL,0,MODE_CLOSE,period,i)];

ArraySetSeries(high,true);
ArraySetSeries(low,true);

MaxH = high[iHighest(NULL,0,MODE_CLOSE,period,i)];                       
MinL = low[iLowest(NULL,0,MODE_CLOSE,period,i)];
 

Question about multicurrency:

There are several symbols, we need to get indicator data

Since a new candle opens on some symbols later than on the main symbol - we will not get the actual data for that symbol

We have added a check for time coincidence, and if the opening time coincides on all symbols - continue

The code works and performs its functions until we add a symbol with a limited session, for example, Index

then all code execution stops

void OnTick()
{
  bool flag=true;
  static datetime pTime;
  datetime cTime=iTime(NULL,0,1);
//--
  if(pTime!=iTime(NULL,0,1)) {
    for(int i=0; i<Sym_count; i++) {
      if(cTime!=iTime(Sym_arr[i],0,1)) { // если не прошли проверку
        flag=false; // ставим флаг
        break;
      }
      if(CopyBuffer(hRSI[i],0,1,1,buf)==-1) return;
      Ind_arr[i]=buf[0];
    }
    MinInd=ArrayMinimum(Ind_arr);
    MaxInd=ArrayMaximum(Ind_arr);
    Comment("\n",EnumToString(SelectInd)," : ",TimeCurrent(),
            "\nMaximum: ",Sym_arr[MaxInd]," = ",DoubleToString(Ind_arr[MaxInd],6),
            "\nMinimum: ",Sym_arr[MinInd]," = ",DoubleToString(Ind_arr[MinInd],6));
  }
  if(flag) { // Если всё хорошо - идём дальше
    pTime=iTime(NULL,0,1);
    Print("On = ",TimeCurrent());
  } else Print("Off = ",TimeCurrent());
}

--

The question is:

How to make code execution for those symbols with open session and not use with closed session.

Thanks!

 
Vitaly Muzichenko #:

Question about multicurrency:

There are several symbols, we need to get indicator data

Since a new candle opens on some symbols later than on the main symbol - we will not get the actual data for that symbol

We have added a check for time coincidence, and if the opening time coincides on all symbols - continue

The code works and performs its functions until we add a symbol with a limited session, for example, Index

then all code execution stops

--

The question is:

How to make the code execution for those symbols with open session, and not to use with closed session.

Thanks!

Check the market information for each symbol if it is not is session then exclude it..

https://www.mql5.com/en/docs/marketinformation

Documentation on MQL5: Market Info
Documentation on MQL5: Market Info
  • www.mql5.com
These are functions intended for receiving information about the market state...
 
Vitaly Muzichenko #:

The question is:

How to make code execution for those characters that have an open session, and not to use with a closed session.

Thanks!

If sessions are not set in the specification or are set but not correctly, which happens often.

Then find the time of the last minute bar of yesterday and compare it with the time of the last minute bar of today.

If I have not mixed up anything (which is unlikely), then like this

if(pTime != iTime(NULL, 0, 1))
  {
   for(int i = 0; i < Sym_count; i++)
     {
      if(cTime != iTime(Sym_arr[i], 0, 1))
        {
         if(iTime(Sym_arr[i], PERIOD_M1, 0) >= iTime(Sym_arr[i], PERIOD_M1, iTime(Sym_arr[i], PERIOD_D1, 0), 1))
            continue;
         flag = false;
         break;
        }


S.F. Of course I'm confused)))) It is necessary to send the found time to the structure and then compare hours and minutes.


like this

if(pTime != iTime(NULL, 0, 1))
  {
   for(int i = 0; i < Sym_count; i++)
     {
      if(cTime != iTime(Sym_arr[i], 0, 1))
        {
         MqlDateTime dtLast, dtCurr;
         TimeToStruct(iTime(Sym_arr[i], PERIOD_M1, iTime(Sym_arr[i], PERIOD_D1, 0), 1), dtLast);
         TimeCurrent(dtCurr);
         if(dtCurr.hour + dtCurr.min * 60 >= dtLast.hour + dtLast.min * 60)
            continue;
         flag = false;
         break;
        }
     }
  }
It's monstrous and probably takes a long time, but I can't think of anything better.
 
Aleksandr Slavskii #:

If sessions are not set in the specification or are set, but not correctly, which is often the case.

Then find the time of the last minute bar of yesterday and compare it with the time of the last minute bar of today.

If I have not mixed up anything (which is unlikely), then like this


S.F. Of course I am confused)))) It is necessary to send the found time to the structure and then compare hours and minutes.


This is possible.

Monstruous and probably long, but nothing better comes to mind.

Thanks for your attention!

There's a bit of a problem: something extra

if(cTime != iTime(Sym_arr[i], 0, 1)) {
        MqlDateTime dtLast, dtCurr;
        TimeToStruct(iTime(Sym_arr[i], PERIOD_M1, iTime(Sym_arr[i], PERIOD_D1, 0), 1), dtLast);
        TimeCurrent(dtCurr);
        if(dtCurr.hour + dtCurr.min * 60 >= dtLast.hour + dtLast.min * 60)
          continue;
 
Vitaly Muzichenko #:

Thank you for your attention!

There is some problem: something extra

Yeah. It's the same as always. Something's wrong.

//+------------------------------------------------------------------+
void OnTick(void)
  {
   MqlDateTime dtLast, dtCurr;
   datetime TimeCurr = TimeCurrent(dtCurr);
   datetime TimeDay = iTime(_Symbol, PERIOD_D1, 0);
   int Shift = iBarShift(_Symbol, PERIOD_M1, TimeDay);
   datetime TimeLast = iTime(_Symbol, PERIOD_M1, Shift);
   TimeToStruct(TimeLast, dtLast);

   if(dtCurr.hour + dtCurr.min * 60 >= dtLast.hour + dtLast.min * 60)
      Print("TimeCurrent ", TimeCurrent(), "; TimeLast ", TimeLast);
  }
//+------------------------------------------------------------------+
TimeCurrent 2024.10.02 13:57:36; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:36; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:36; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:36; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:36; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:36; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:36; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:36; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:36; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:37; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:37; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:37; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:37; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:37; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:37; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:37; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:37; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:38; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:38; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:38; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:38; TimeLast 2024.10.01 23:49:00
TimeCurrent 2024.10.02 13:57:38; TimeLast 2024.10.01 23:49:00
 
Vitaly Muzichenko #:

Thank you for your attention!

There is some problem: something extra

Yeah, it's the same as always. Nothing superfluous, it's just not right.

//+------------------------------------------------------------------+
void OnTick(void)
  {
   MqlDateTime dtLast, dtCurr;
   datetime TimeCurr = TimeCurrent(dtCurr);
   datetime TimeDay = iTime(_Symbol, PERIOD_D1, 0);
   int Shift = iBarShift(_Symbol, PERIOD_M1, TimeDay);
   datetime TimeLast = iTime(_Symbol, PERIOD_M1, Shift);
   TimeToStruct(TimeLast, dtLast);

   if(dtCurr.hour * 60 + dtCurr.min >= dtLast.hour * 60 + dtLast.min)
      Print("TimeCurrent ", TimeCurrent(), "; TimeLast ", TimeLast);
  }
//+------------------------------------------------------------------+
TimeCurrent 2024.10.01 23:49:00; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:02; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:04; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:06; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:08; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:11; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:13; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:15; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:17; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:20; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:22; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:24; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:26; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:28; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:31; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:33; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:35; TimeLast 2024.09.30 23:49:00
TimeCurrent 2024.10.01 23:49:37; TimeLast 2024.09.30 23:49:00