Learning and writing together in MQL5 - page 14

 

Out of curiosity, I checked. The result is as follows

2011.04.15 15:50:34     123 (EURUSD,D1) time for 'd = a + b + c' = 84453 milliseconds, i = 10000000
2011.04.15 15:51:54     123 (EURUSD,D1) time for 'StringAdd()' = 80906 milliseconds, i = 10000000
2011.04.15 15:53:22     123 (EURUSD,D1) time for 'StringConcatenate(d,a,b,c)' = 87359 milliseconds, i = 10000000
2011.04.15 15:55:11     123 (EURUSD,D1) time for 'd = a + b + c' = 83266 milliseconds, i = 10000000
2011.04.15 15:56:39     123 (EURUSD,D1) time for 'StringAdd()' = 88390 milliseconds, i = 10000000
2011.04.15 15:58:12     123 (EURUSD,D1) time for 'StringConcatenate(d,a,b,c)' = 93391 milliseconds, i = 10000000

But it seems to me that there is something wrong here (I mean checking algorithm)...

 

Yedelkin:

It turns out that StringConcatenate is slower than string binding using addition operations. What's the snag?

The peculiarity of strings.
In the first pass, you get the right buffer size to store the result of string addition and transformation, i.e. there is no buffer relocation for strings d,(string)b and(string)c.
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы ввода/вывода / Использование кодовой страницы
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы ввода/вывода / Использование кодовой страницы
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы ввода/вывода / Использование кодовой страницы - Документация по MQL5
 
mql5:
Feature strings.
In the first pass you get the right buffer size to store the result of the addition and transformation of strings, i.e. buffer relocation for strings d,(string)b and(string)c does not happen.

Tried different ways of comparing - doesn't get the result I want. I've come to this code:

   uint   start,stop;
   long   i,length=1000000;
   string a1[1000000]; for(i=0;i<length;i++) a1[i]="Пример";
   string a2[1000000]; for(i=0;i<length;i++) a2[i]="Пример";
   string a3[1000000]; for(i=0;i<length;i++) a3[i]="Пример";

   double b1[1000000]; ArrayInitialize(b1,1.26);
   double b2[1000000]; ArrayInitialize(b2,1.26);
   double b3[1000000]; ArrayInitialize(b3,1.26);

   double c1[1000000]; ArrayInitialize(c1,1.27);
   double c2[1000000]; ArrayInitialize(c2,1.27);
   double c3[1000000]; ArrayInitialize(c3,1.27);

   string d1[1000000]; for(i=0;i<length;i++) d1[i]=NULL;
   string d2[1000000]; for(i=0;i<length;i++) d2[i]=NULL;
   string d3[1000000]; for(i=0;i<length;i++) d3[i]=NULL;


////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------//
//Work variables
//----------------------------------------------------------------------------//
   start=GetTickCount();
   for(i=0;i<length;i++)
     {
      d1[i]=a1[i]+(string)b1[i]+(string)c1[i];
     }
   stop=GetTickCount();
   Print("time for 'd = a + b + c' = ",(stop-start)," milliseconds, i = ",i);

//Второй способ
   start=GetTickCount();
   for(i=0;i<length;i++)
     {
      StringAdd(d2[i],a2[i]);
      StringAdd(d2[i],(string)b2[i]);
      StringAdd(d2[i],(string)c2[i]);
     }
   stop=GetTickCount();
   Print("time for 'StringAdd()' = ",(stop-start)," milliseconds, i = ",i);

//Третий способ
   start=GetTickCount();
   for(i=0;i<length;i++)
     {
      StringConcatenate(d3[i],a3[i],b3[i],c3[i]);
     }
   stop=GetTickCount();
   Print("time for 'StringConcatenate(d,a,b,c)' = ",(stop-start)," milliseconds, i = ",i);

Results:

KL 0 DoubleToString (EURGBP,M1)      23:53:01        time for 'd = a + b + c' = 15766 milliseconds, i = 1000000
HD 0 DoubleToString (EURGBP,M1)      23:53:26        time for 'StringAdd()' = 25390 milliseconds, i = 1000000
FK 0 DoubleToString (EURGBP,M1)      23:54:03        time for 'StringConcatenate(d,a,b,c)' = 36516 milliseconds, i = 1000000
KS 0 DoubleToString (EURGBP,M1)      23:54:56        time for 'd = a + b + c' = 15781 milliseconds, i = 1000000
FL 0 DoubleToString (EURGBP,M1)      23:55:21        time for 'StringAdd()' = 25375 milliseconds, i = 1000000
OR 0 DoubleToString (EURGBP,M1)      23:55:57        time for 'StringConcatenate(d,a,b,c)' = 35828 milliseconds, i = 1000000
 
Question. The OrdersTotal() function returns the total number of active orders for a trading account. Is there an easy way to get the number of active orders for a specific symbol?
 
Yedelkin:
Question. The OrdersTotal() function returns the total number of active orders for a trading account. Is there an easy way to get the number of active orders for a certain symbol?
Get the entire history and make a selection.
 
Urain:
Get the whole story and do a sampling.
OK. So there's no easy way.
 

Question. The HistorySelect() and HistorySelectByPosition() functions request the history of orders and history of deals. I ran the explanatory script from the Guide, and its list of deals is arranged in ascending order. Is it so by chance, or are functions HistorySelect() and HistorySelectByPosition() programmed to return lists ordered in ascending order?

 
Yedelkin:

Question. The HistorySelect() and HistorySelectByPosition() functions request the history of orders and history of deals. I ran the explanatory script from the Guide, and its list of deals is arranged in ascending order. Is it so by chance, or have the HistorySelect() and HistorySelectByPosition() functions been programmed to return the lists ordered in ascending order?

No matter how many times I've experimented, the result is the same: a list ordered in a certain way is returned.

Once I even wanted to write a request for an additional parameter specifying exactly how the entries should be sorted.

But then I thought carefully and decided that it's not worth it (they may answer that sort themselves and all that), although it's possible that I shouldn't have written it down...

 
Interesting:

... sort yourself and all that

It's just that if there is a preset forced sorting it's one thing, but creating additional sorting manually is another.
 
Yedelkin:
Just if there's a preset forced sorting it's one thing, but creating additional sorting manually is another.

It's just that in MT4 I sorted manually (and filtered too), if I'm not mistaken I sorted in "bubbles".

I got the sorting code from the database there, so that can be clarified.

And I haven't decided on the best way to sort in MQL5, since I've understood that history queries are now not tied to history tab (sorting and content does not depend on what the user has done in the tab).