Function - Method for sorting an array of structures. Prize 10$ - page 4

 
Sergey Dzyublik:

What's the problem?

In addition to the function itself, you have to do a typedef on it and create a variable, just to pass the function as a parameter, which is what you do under the lambda macro.

 
fxsaber:

Checked it, it's working.

Unfortunately not (((.


 
Vladimir Pastushak:

Sadly not (((.

You don't have sorting working in MT4.
So, insert the call for the suggested sorting for MT4 in the conditional compilation, and leave the code for MT5 untouched.

 
Vladimir Pastushak:

Sadly not (((.


Update your MT4.

 

Checked the code in MT4, all works

2020.04.21 23:27:35.728 Script t EURUSD,H1: removed

2020.04.21 23:27:35.726 t EURUSD,H1: uninit reason 0

2020.04.21 23:27:35.726 t EURUSD,H1: 1.08685 1.087231.085271.08542020.04.21 18:00:001.08518 1.087021.084561.086842020.04.21 19:00:001.0843 1.085271.084291.085172020.04.21 20:00:001.08503 1.085061.08411.084292020.04.21 21:00:001.08535 1.08551.084971.085022020.04.21 22:00:00

2020.04.21 23:27:35.726 t EURUSD,H1:

Sorting by time.

2020.04.21 23:27:35.726 t EURUSD,H1: 1.08503 1.085061.08411.084292020.04.21 21 21:00:001.0843 1.085271.084291.0851720.04.21 20:00:001.08535 1.08551.084971.085022020.04.21 22:00:001.08518 1.087021.084561.086842020.04.21 19:00:001.08685 1.087231.085271.08542020.04.21 18:00:00

2020.04.21 23:27:35.726 t EURUSD,H1:

Sorting by high-value.

2020.04.21 23:27:35.726 t EURUSD,H1: 1.08503 1.085061.08411.084292020.04.21 21 21:00:001.08535 1.08551.084971.085022020.04.21 22:00:001.0843 1.085271.084291.085172020.04.21 20:00:001.08685 1.087231.085271.08542020.04.21 18:00:001.08518 1.087021.084561.086842020.04.21 19:00:00

2020.04.21 23:27:35.726 t EURUSD,H1:

Sorting by open price.

2020.04.21 23:27:35.726 t EURUSD,H1: 1.08685 1.087231.085271.08542020.04.21 18:00:001.08518 1.087021.084561.086842020.04.21 19:00:001.0843 1.085271.084291.085172020.04.21 20:00:001.08503 1.085061.08411.084292020.04.21 21:00:001.08535 1.08551.084971.085022020.04.21 22:00:00

2020.04.21 23:27:35.726 t EURUSD,H1:

Bars without sorting - as received.

2020.04.21 23:27:35.726 t EURUSD,H1: initialized

2020.04.21 23:27:34.279 Script t EURUSD,H1: loaded successfully

MT4 build 1262

I unlocked it like this:

string MqlRatesToStr(MqlRates &arr[])
{
   string result = "";
   for(int i = 0; i < ArraySize(arr); ++i)
   {
      result += (string)(arr[i].close) + " " + (string)(arr[i].high) +(string)(arr[i].low) +(string)(arr[i].open) +(string)(arr[i].time);
   }
   return result;
}
 
Vladimir Pastushak:

In the provided code I forgot to wrap the main function ArraySortStruct back into macro, that it would be possible to specify sorting field.
But the author of the topic is stubbornly silent, apparently I'm the only one who needs it...

 

Algorithm:

1. Structure = String. First loop.

2. Sort array of strings. Second loop (complex, bubble).

3. String = Structure. The third loop.

Hardly any faster.

Reason:

1. Structures are represented in the system as strings, only alignment must be taken into account (byte-by-byte).

2. The string processing speed is much higher than the speed of other data types processing.

3. Only one operation of two rows comparison is carried out in a loop. Field values need not be compared.

I used to do it on Clarion in the early 90s. It worked.

Документация по MQL5: Операции с массивами / ArraySort
Документация по MQL5: Операции с массивами / ArraySort
  • www.mql5.com
//| Получение значений границ для тиковых объемов                    | //| Custom indicator initialization function                         | //| Custom indicator iteration function                              | //
 
Sergey Dzyublik:

In the provided code I forgot to wrap the main function ArraySortStruct back into macro, that it would be possible to specify sorting field.
But the author of the topic is stubbornly silent, apparently I'm the only one who needs it...

I haven't looked at it yet. I don't understand macros. I'd be grateful for the full code.
 
Алексей Тарабанов:

I did that in the early 90s on a Clarion. It flew.

to tears! )))

i remember the first semester of the 1st course and the first practice classes in algorithms and programming.... i even do not remember what we learned, i think we learned pascal at first, but the lessons were on the IBM terminal classes, i compiled the program at 15-20 lines... well, first 2-3 minutes, then up to 20 minutes when people did a lot of typing and syntax errors

from the second semester, we were working on 486s


it flew! ))))


SZS: if I'm not mistaken it was EC-1035 .... it flew!

 
Igor Makanu:

to tears! )))

I remembered the first semester of the 1st year and the first practice sessions on algorithms and programming.... i can't even remember what we were studying, i think it was Pascal at first, but the lessons were on IBM computers in the terminal classes, compiling the program of 15-20 lines... well, at first we studied for 2-3 minutes, then up to 20 minutes when people did a lot of typing and syntax errors

from the second semester, we were working on 486s


it flew! ))))


SZY: If I'm not mistaken, it was the EC-1035 .... it flew!

I started on the world's first personal electronic digital computer in 1976. It was designed by Kyiv Institute of Cybernetics of the Academy of Science of the Ukrainian Soviet Social Republic. Then came the Minsk-32, and then the EC.