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

 
How do I get the next bar open time for the current timeframe? Tried to do
Time[1]+2*PERIOD_CURRENT, but it gives a crap...
As far as I understand Time gives time in minutes from 1970?
 
RomanRott:
Please advise how to get the opening time of the next bar for the current timeframe? Tried to do
Time[1]+2*PERIOD_CURRENT, but it gives a crap...
As far as I understand Time gives the time in minutes from 1970?

In seconds time, with this knowledge correct your formula.

 
Aleksey Vyazmikin:

In seconds time, with this knowledge, correct your formula.

Shit, I mean with PERIOD_... just in one line can't be done
 
RomanRott:
Please advise how to get the opening time of the next bar for the current timeframe? Tried to do
Time[1]+2*PERIOD_CURRENT, but it gives a crap...
As far as I understand Time gives the time in minutes from 1970?

Try Alert(Time[0]+_Period*60); PERIOD_CURRENT is 0, zero, blank, notation of timeframe of the used chart

 
RomanRott:
How do I get the next bar open time for the current timeframe? I tried to do
Time[1]+2*PERIOD_CURRENT, but it gives a crap...
As far as I understand Time gives time in minutes from 1970?
Time[0]+PeriodSeconds();
 
RomanRott:
Shit, I mean with PERIOD_... just one line can't do it

  datetime time0 = Time[0]; 
   datetime time1 = Time[0]+PeriodSeconds(0)*1;   //1 = нужное кол. баров в будущее
   
  Comment("Время открытия тек. бара = ",time0,
  "\n","Время открытия след. бара(в будущее) = ",time1 );

That's it


oops))) ahead of the curve

 
Artyom Trishkin:
Time[0]+PeriodSeconds();
Yes, thank you!
 
RomanRott:
Yes, thank you!

You're welcome.

Multi-platform code:

void OnTick()
  {
   ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT;    // Таймфрейм графика (текущий, можно задать нужный)
   string   symbol=Symbol();                    // Символ графика
   datetime time_open_curr=0;                   // Время открытия текущего бара
   datetime time_open_next=0;                   // Время открытия следующего бара
   int      number_next_bar=1;                  // На сколько баров в будущее рассчитывать время
   //---
   time_open_curr=TimeOpen(symbol,timeframe,0); // Здесь 0 - текущий бар заданного графика
   //--- Если получили время текущего бара, рассчитаем время следующего
   if(time_open_curr>0)
      time_open_next=time_open_curr+PeriodSeconds(timeframe)*number_next_bar;
  }
//+------------------------------------------------------------------+
//| Возвращает время открытия бара shift                             |
//| периода графика timeframe                                        |
//| на символе symbol_name                                           |
//+------------------------------------------------------------------+
datetime TimeOpen(string symbol_name,ENUM_TIMEFRAMES timeframe,int shift)
  {
   datetime array[]={0};
   if(CopyTime(symbol_name,timeframe,shift,1,array)==1) return array[0];
   return 0;
  }
//+------------------------------------------------------------------+
 

how do I write a function with a variable number of parameters?

 
RomanRott:

how do I write a function with a variable number of parameters?

For example?

Reason: