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

 
Igor Makanu:


measured:

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

hmm, I think some moderator needs a flaming hello ))))

Running the script:

2019.07.30 03:58:46.425 CopyClose: loops=-2147483648 ms=0
2019.07.30 03:58:46.425 iClose: loops=-2147483648 ms=0

What's wrong? (no time to figure it out)

 
Artyom Trishkin:

Running the script:

What's wrong? (no time to figure it out)

there is no check for the number of bars on the chart, maybe the exit by a non-existent bar - i have unlimited and H1 period on eu, rand() seems to give 65 thousand at most


I've popped the rand() compiler, here's a correct test of all 4 methods:

// Позволяет, как в 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)
#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[1];
   MqlRates rates[1];
   srand(GetTickCount());
   test(10,"CopyClose",CopyClose(_Symbol,_Period,rand(),1,buff));
   srand(GetTickCount());
   test(10,"iClose",iClose(NULL,0,rand())); 
   srand(GetTickCount());
   test(10,"Close[i]",Close[rand()]); 
   srand(GetTickCount());
   test(10,"CopyRates",CopyRates(_Symbol,_Period,rand(),1,rates)); 
  }
//+------------------------------------------------------------------+

2019.07.30 00:59:10.911 tst_iXXX_Copy (EURUSD,H1) CopyClose: loops=1410065408 ms=69765

2019.07.30 01:01:23.655 tst_iXXX_Copy (EURUSD,H1) iClose: loops=1410065408 ms=132735

2019.07.30 01:03:51.541 tst_iXXX_Copy (EURUSD,H1) Close[i]: loops=1410065408 ms=147890

2019.07.30 01:05:19.872 tst_iXXX_Copy (EURUSD,H1) CopyRates: loops=1410065408 ms=88328

 
Igor Makanu:

there is no check for the number of bars on the chart, it may crash on a non-existent bar - i have unlimited and H1 period on eu, rand() seems to give 65 thousand at most


I've popped the rand() compiler, here's a correct test of all 4 methods:

2019.07.30 00:59:10.911 tst_iXXX_Copy (EURUSD,H1) CopyClose: loops=1410065408 ms=69765

2019.07.30 01:01:23.655 tst_iXXX_Copy (EURUSD,H1) iClose: loops=1410065408 ms=132735

2019.07.30 01:03:51.541 tst_iXXX_Copy (EURUSD,H1) Close[i]: loops=1410065408 ms=147890

2019.07.30 01:05:19.872 tst_iXXX_Copy (EURUSD,H1) CopyRates: loops=1410065408 ms=88328

2019.07.30 04:12:50.825 CopyClose: loops=-2147483648 ms=0
2019.07.30 04:12:50.825 iClose: loops=-2147483648 ms=0
2019.07.30 04:12:50.825 Close[i]: loops=-2147483648 ms=0
2019.07.30 04:12:50.825 CopyRates: loops=-2147483648 ms=0
Somehow it's not good when you need a file :)
 
Artyom Trishkin:
Somehow not good when you need a file :)

Hmm, I guess it's not possible without a half-litre...

why is loops=-2147483648 in my source code different!

;)

PS: to ulong- ints replace in the define - if you're going to test until morning ))))

 
Igor Makanu:

Hmm, I guess it's not possible without a half-litre...

why is loops=-2147483648 in my source code different!

;)

PS: to ulong-into the ints in the define - if you're going to test until morning ))))

Replaced:

2019.07.30 04:26:12.849 CopyClose: loops=1410065408 ms=71234
2019.07.30 04:26:12.849 iClose: loops=1410065408 ms=0
2019.07.30 04:26:12.849 Close[i]: loops=1410065408 ms=0
2019.07.30 04:26:12.849 CopyRates: loops=1410065408 ms=0

:))

 
Artyom Trishkin:

Replaced:

:))

MQL-source code is one-to-one, I copied the test from the terminal log

hmm, hard to guess where else the naughty hands have dug ))))

i am not that keen on it, the code works fine - it worked for me! i got it from here when we discussed

SZY: Win10 - 64, build 2093 (Intel Core - 8GB RAM) - no problems noted, what do you have there?

--------------

attached...it's a script, in the script folder...don't know what else to suggest

Files:
 
On Win10 x64 all cores are engaged
2019.07.30 00:25:29.057 Test (GBPUSD,M1)   CopyClose: loops=1410065408 ms=72953
2019.07.30 00:27:51.501 Test (GBPUSD,M1)   iClose:    loops=1410065408 ms=143625
2019.07.30 00:30:17.904 Test (GBPUSD,M1)   Close[i]:  loops=1410065408 ms=149078
2019.07.30 00:31:56.618 Test (GBPUSD,M1)   CopyRates: loops=1410065408 ms=88891

Under Wine on Debian x64 only one kernel runs for some reason
2019.07.30 00:38:03.104 Test (GBPUSD,M1)   CopyClose: loops=1410065408 ms=119863
2019.07.30 00:41:10.478 Test (GBPUSD,M1)   iClose:    loops=1410065408 ms=187364
2019.07.30 00:44:16.935 Test (GBPUSD,M1)   Close[i]:  loops=1410065408 ms=186449
2019.07.30 00:46:29.732 Test (GBPUSD,M1)   CopyRates: loops=1410065408 ms=132794
Files:
CPU_Win10.png  47 kb
CPU_Wine.png  21 kb
 
Igor Makanu:

MQL-source code is exactly the same, I copied the test from the terminal log

hmm, it's hard to guess where else the naughty pens have dug ))))

i am not that keen on it, the code works fine - it worked for me! i got it from here when we discussed

SZY: Win10 - 64, build 2093 (Intel Core - 8GB RAM) - no problems noted, what do you have there?

--------------

attached...it's a script, in the script folder...don't know what else to suggest

// Позволяет, как в 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)
#define    test(M,S,EX)        {ulong mss=GetTickCount();ulong nn=(ulong)pow(10,M);for(ulong tst=0;tst<nn&&!_StopFlag;tst++){EX;} \
                                printf("%s: loops=%i ms=%u",S,nn,GetTickCount()-mss);}
//+------------------------------------------------------------------+
void OnStart()
  {
   double buff[1];
   MqlRates rates[1];
   srand(GetTickCount());
   test(10,"CopyClose",CopyClose(_Symbol,_Period,rand(),1,buff));
   srand(GetTickCount());
   test(10,"iClose",iClose(NULL,0,rand())); 
   srand(GetTickCount());
   test(10,"Close[i]",Close[rand()]); 
   srand(GetTickCount());
   test(10,"CopyRates",CopyRates(_Symbol,_Period,rand(),1,rates)); 
  }
//+------------------------------------------------------------------+

Vin10 - 64 , build 2093 (Intel Core i3-3217U CPU @ 1.80GHz - 12GB RAM)- no problems noticed...

 
Artyom Trishkin:

problems noticed...

The only thing to do here is to reduce the number of cycles and if there is a place where the script will work - use the GetLastError() unpacking to look for it

alternatively: or some settings of the terminal? - hmm, what settings are there? - number of bars on the chart and that's it

 
Igor Makanu:

The only thing to do here is to reduce the number of cycles and if there is a place where the script will work - use the GetLastError() undo to look for it

alternatively: or some settings of the terminal? - hmm, what settings are there? - Number of bars on the chart - that's it.

I have no time to look for it. I thought there was something "out of the box" - I just ran it and saw the result. And so ... Yes, and the script does not work immediately, and hangs until you close it forcibly by pressing the PCM on its icon. And only then something there is printed. In general - with macros one hassle for some reason.

Reason: