Analogue to iBarShift

 

I missed the functionality similar to iBarShift for MT4. Can you tell me how to do it?

And as far as I understand you should use CopyTime instead of Time[10]?

 
GarF1eld писал(а)  :

I missed the functionality similar to iBarShift for MT4. Can you tell me how to do it?

And as far as I understand you should use CopyTime instead of Time[10]?

The analogue of ibarshift:

int iBarOnTime( string symbol, ENUM_TIMEFRAMES timeframe, datetime time, bool exact=false )

analogue of Time[]:

Time( int i )

There's a lot more out there that will come in handy:

double iHigh(string symbol,int tf,int ind)
double High( int i )
double iLow(string symbol,int tf,int ind)
double Low( int i )
double iClose(string symbol,int tf,int ind)
double Close( int i )
double iOpen(string symbol,int tf,int ind)
double Open( int i )
double HighOnTime( string symbol, ENUM_TIMEFRAMES timeframe, datetime time, bool exact=false )
double LowOnTime( string symbol, ENUM_TIMEFRAMES timeframe, datetime time, bool exact=false )
double CloseOnTime( string symbol, ENUM_TIMEFRAMES timeframe, datetime time, bool exact=false )
double OpenOnTime( string symbol, ENUM_TIMEFRAMES timeframe, datetime time, bool exact=false )
string SPeriod(ENUM_TIMEFRAMES tf)  //символьное представление периода
datetime iTime( const string symbol, int tf, int ind  )

//+------------------------------------------------------------------+
//| Аналог Bars(), не требует предварительной синхронизации истории  |
//| Вход  : symbol - символ в терминале                              |
//|         timeframe - таймфрейм                                    |
//| Выход : нет                                                      |
//| Прим. : нет                                                      |
//+------------------------------------------------------------------+
int BarsSinh( string symbol,ENUM_TIMEFRAMES  timeframe )

//+------------------------------------------------------------------+
//| Произвести синхронизацию таймсерии с историей                    |
//| Вход  : symbol - символ в терминале                              |
//|         tf     - таймфрейм                                       |
//| Выход : нет                                                      |
//| Прим. : нет                                                      |
//+------------------------------------------------------------------+
void SynhronizeSeries( string symbol, ENUM_TIMEFRAMES tf )

//+------------------------------------------------------------------+
//| Проверить наличие истории на дату start_date, если остуствует,   |
//| то произвести попытку загрузки                                   |
//| Вход  : symbol - символ в терминале                              |
//|         period - таймфрейм                                       |
//|         start_date - дата проверки истории                       |
//| Выход : код результата выполнения операции подробнее             |
//|         см. https://www.mql5.com/ru/docs/series/timeseries_access |
//| Прим. : нет                                                      |
//+------------------------------------------------------------------+
int CheckLoadHistory(string symbol,ENUM_TIMEFRAMES period,datetime start_date)
//+------------------------------------------------------------------+
//| возвращает строкое значение периода                              |
//+------------------------------------------------------------------+
string GetPeriodName(ENUM_TIMEFRAMES period)
Files:
common.mqh  22 kb
 
gdtt:

ibarshift analogue :

Time[] analogue:

there's a lot more out there that will come in handy:

thanks! useful thing

If there's nothing more sane from the standard, I'll use algorithms from the library

 
Can anyone suggest a faster counterpart to iBarShift? Existing options with CopyTime turn out to be terribly slow, judging by the profiler. I need bar synchronization. I'm counting an indicator on each bar once, but unfortunately I have to process ticks until the bar is synchronized. I have also inserted a timer; I do not see any productivity gain.
 

If anyone is interested, I found an alternative.

int iBarShiftFast(string symbol, ENUM_TIMEFRAMES timeframe, datetime time)
{
  datetime lastBar;
  SeriesInfoInteger(symbol, timeframe, SERIES_LASTBAR_DATE, lastBar);
  return(Bars(symbol, timeframe, time, lastBar) - 1);
}

According to my measurements, acceleration compared to CopyTime variant is from 2 to 7 times (depending on input data). If you have any comments or bugs, please post them.

 
marketeer:

If anyone is interested, I found an alternative.

According to my measurements, acceleration compared to CopyTime variant is from 2 to 7 times (depending on input data). If you have any comments or bugs, please write.

Thank you. I will try it.

 

Or maybe this is the right way to do it now:

int bar = Bars(0, 0, barTime_last, TimeCurrent());
 
Roffild:

Or maybe this is more correct now:

int bar = Bars(0, 0, barTime_last, TimeCurrent());

And even faster and more correct (the first parameter must be NULL, it does not work with zero)

 int bar = Bars(NULL, 0, t, 32000000000);

Because there is no need to execute theTimeCurrent() function unnecessarily

32000000000 is not from the current moment, but almost from the moment of 3000

 
Nikolai Semko:

And even faster and more correct (the first parameter must be NULL, it does not work with zero)

Because there is no need to execute theTimeCurrent() function unnecessarily

32000000000 is not from the current moment, but almost from the moment of 3000


And what about -1? This is an important moment...
 
Denis:

What about -1? It's an important point...
I don't know what you're talking about?
Explain.
 
Nikolai Semko:
I'm not sure what this is about?
Explain.

The Bars function returns the number of bars. When we want to get the index of a bar with index 9 (sorry for the tautology), it will return 10, because the index of the first bar is 0.
Reason: