How do I get Open,Low,High,Close parameters in MQL5? - page 6

 
Artyom Trishkin:

There were some problems with SERIES_LASTBAR_DATE. It was discussed here somewhere long ago. Maybe it was fixed.

The iXXX() function works fine, I've been using it for about 3 months (since I started using MQL5) - I haven't noticed any bugs or... - It's very handy and everything works!

SZZY: it works as written in Help :

Parameters

symbol

[in] Instrument symbol name. NULL means current symbol.

timeframe

[in] Period. Can be one of values of enumeration ENUM_TIMEFRAMES. 0 means period of current chart.

 
Igor Makanu:

Do you always just write and don't try to read? I gave you a link to a whole article about the New Bar! Articles are checked - checked by people of a different competence than those who write constantly on the forum ;)

ZS: If you stop writing and start reading, such as the article on my link, you can find another way ( SERIES_LASTBAR_DATE ) not to use the iXXX() - I told you not to use them ))) - who would tell the bugs and errors that the developers released shoddy )))))

Thanks for the link. I wasn't criticizing your solution, just pointing out the iTime call, which itself hints at using iXXX functions, which supersedes the point of fiddling with CopyRates. That is, looking for a new bar with iTime to use CopyRates in order not to use iXXX functions (iTime).))) Vicious circle.)))
 
// Для Тестера.
bool IsNewBar()
{
  static int PrevBars = 0;
  const int CurrBars = Bars;  

  const bool Res = (CurrBars != PrevBars);
  
  PrevBars = CurrBars;
  
  return(Res);
}
 
Roman:
Thank you.
 
fxsaber:
Thank you.
 
Convertedmany MT4EAs to MT5 without changing the source code. I have posted the sabot as Open[i].
 
fxsaber:
I converted many MT4 EAs to MT5 without modifying source code. I posted the sabot as Open[i].

Ever done performance measurements between CopyXXX and iXXX functions? This question is very interesting.

So far I see one obvious convenient use of iXXX functions - less remaking of MQL4 code when porting it to MQL5.

In other cases (without knowledge of performance) - the choice is based only on users preferences.

 
fxsaber:
Sabz in the form of Open[i] posted.

Didn't pay attention to this code, checked it - it works!

ZS: I need to see how I got [] tomorrow when I have a clear head - I tried it several times - it didn't work for me!

// Позволяет, как в MT4, работать с таймсериями: Open[Pos], High[Pos], Low[Pos], Close[Pos], Time[Pos], Volume[Pos].
// А так же задает привычные MT4-функции: iOpen, iHigh, iLow, iClose, iTime, iVolume.
#define  DEFINE_TIMESERIE(NAME,FUNC,T)                                                                         \
  class CLASS##NAME                                                                                           \
  {                                                                                                           \
  public:                                                                                                     \
    static T Get(const string Symb,const int TimeFrame,const int iShift) \
    {                                                                                                         \
      T tValue[];                                                                                             \
                                                                                                              \
      return((Copy##FUNC((Symb == NULL) ? _Symbol : Symb, _Period, iShift, 1, tValue) > 0) ? tValue[0] : -1); \
    }                                                                                                         \
                                                                                                              \
    T operator[](const int iPos) const                                                                     \
    {                                                                                                         \
      return(CLASS##NAME::Get(_Symbol, _Period, iPos));                                                       \
    }                                                                                                         \
  };                                                                                                          \
                                                                                                              \
  CLASS##NAME  NAME;                                                                                           \
                                                                                                              \
  T i##NAME(const string Symb,const int TimeFrame,const int iShift) \
  {                                                                                                           \
    return(CLASS##NAME::Get(Symb,  TimeFrame, iShift));                                                        \
  }
//+------------------------------------------------------------------+
DEFINE_TIMESERIE(Volume,TickVolume,long)
DEFINE_TIMESERIE(Time,Time,datetime)
DEFINE_TIMESERIE(Open,Open,double)
DEFINE_TIMESERIE(High,High,double)
DEFINE_TIMESERIE(Low,Low,double)
DEFINE_TIMESERIE(Close,Close,double)
void OnStart()
  {
   for(int i=0;i<10;i++)
     {
      ResetLastError();
      Print("Bar№ ",i," : ",Time[i]," , O = ",Open[i]," , H = ",High[i]," , L = ",Low[i]," , C = ",Close[i]);
      int err=GetLastError();
      if(err>0) Print("Error № ",err);
     }
  }
//+------------------------------------------------------------------+
 
Artyom Trishkin:

Ever done performance measurements between CopyXXX and iXXX functions? Very interested in this question.

I haven't. I very rarely deal with bars. Nothing should be faster than CopyXXX functions. Only if you cache it.

 
Artyom Trishkin:

Ever done performance measurements between CopyXXX and iXXX functions? Very interested in this question...


fxsaber:

I haven't. I very rarely deal with bars. Nothing should be faster than CopyXXX functions. Only if you cache it.

Measured:

#define    test(M,S,EX)        {uint mss=GetTickCount();int nn=(int)pow(10,M);for(int tst=0;tst<nn&&!_StopFlag;tst++){EX;} \
                                printf("%s: loops=%i ms=%u",S,nn,GetTickCount()-mss);}
//+------------------------------------------------------------------+
void OnStart()
  {
   double buff[];
   test(10,"CopyClose",CopyClose(_Symbol,_Period,rand(),1,buff));
   test(10,"iClose",iClose(NULL,0,rand())); 
  }
//+------------------------------------------------------------------+

2019.07.30 00:44:29.156 tst_iXXX_Copy (EURUSD,H1) CopyClose: loops=1410065408 ms=69407

2019.07.30 00:45:29.408 tst_iXXX_Copy (EURUSD,H1) iClose: loops=1410065408 ms=60250

Reason: