Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1198

 
Vitaly Muzichenko:

Logically, you should first collect all the lines in an array, I would make a two-dimensional array, or an array structure, in the first dimension add the time of creation, in the second - the name of the line.

In the loop for one run, fill the array, outside the loop after filling the array is sorted by the first dimension, that is, the time.

The result is printed in the second loop.

As a result, we have 2 cycles and sorting between them.

That's all, if I understood the problem correctly :)

That's not exactly how an array works. An array of strings doesn't seem to sort either, I haven't tried it because I don't need to.

 
Vitaly Muzichenko:

Logically, you should first collect all the lines in an array, I would make a two-dimensional array, or an array structure, in the first dimension we add the creation time, in the second - the name of the line.

In the loop for one run, fill the array, outside the loop after filling the array is sorted by the first dimension, that is, the time.

The result is printed in the second loop.

As a result, we have 2 cycles and sorting between them.

That's all, if I understood the problem correctly :)

Question - what type of this two-dimensional array should be? )))

 
Alexey Viktorov:

That's not exactly how an array works. An array of strings doesn't seem to sort either, haven't tried it because I don't need to.

Why? Here's

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

Why? Here

But it doesn't mention an array of structures anywhere. I'll have to check it to be sure. But not right now.

 
Alexey Viktorov:

But it doesn't mention an array of structures anywhere. We'll have to check it to be sure. But not right now.

I answered regarding an array, there is a different sorting for a structure, but it's not that important for the task at hand.

 
Vitaly Muzichenko:

I answered regarding the array, there is a different sorting for the structure, but it's not that important for the task at hand.

I'm slowing down something....

   long     vlines_arr[][1];

   vlines = ObjectsTotal(ChartID(),0,OBJ_VLINE);
   ArrayResize(vlines_arr,vlines);
   
   for(int i = 0; i < vlines; i++)
   {
      long tml = (long)ObjectGetInteger(ChartID(),vlines_name[i],OBJPROP_TIME);
      vlines_arr[i][0]  = {{tml}, {i}};
      
   }

It doesn't compile that way...

 
Сергей Таболин:

Something's slowing me down....

It doesn't compile that way...

   long vlines_arr[][2];

   vlines = ObjectsTotal(ChartID(),0,OBJ_VLINE);
   ArrayResize(vlines_arr,vlines);
   
   for(int i = 0; i < vlines; i++)
   {
      long tml = (long)ObjectGetInteger(ChartID(),vlines_name[i],OBJPROP_TIME);
      vlines_arr[i][0] = tml;
      vlines_arr[i][1] = i;
      
   }
 
Vitaly Muzichenko:

Thank you. Time for bed )))

 

Mystery simple....

void OnStart()
{
int      vlines            = 0;
string   vlines_name[];
string   vlines_name_sort[];
datetime tm[];
long     vlines_arr[][2];

   vlines = ObjectsTotal(ChartID(),0,OBJ_VLINE);
   if(vlines < 20 * 2)
   {
      Print("вертикальных линий меньше необходимиого. (",vlines," < ",20 * 2,")");
      return;
   }
   ArrayResize(vlines_arr,vlines);
   ArrayResize(vlines_name,vlines);
   ArrayResize(vlines_name_sort,vlines);
   
   for(int i = 0; i < vlines; i++)
   {
      long tml = (long)ObjectGetInteger(ChartID(),vlines_name[i],OBJPROP_TIME);
      vlines_arr[i][0]  = tml;
      vlines_arr[i][1]  = (long)i;
   }
   ArrayPrint(vlines_arr);
   ArraySort(vlines_arr);
   Print("-------------");
   ArrayPrint(vlines_arr);
   
   for(int i = 0; i < vlines; i++)
   {
      vlines_name_sort[i]  = ObjectName(ChartID(),(int)vlines_arr[i][1],0,OBJ_VLINE);
   }
   ArrayPrint(vlines_name_sort);

Ran just this the first time - it printed an array, all nice.

Added this - and I don't know what's going on at all... Must be bedtime after all....

(GBPUSD,H6)          [,0][,1]
(GBPUSD,H6)     [ 0,]   0   0
(GBPUSD,H6)     [ 1,]   0   1
(GBPUSD,H6)     [ 2,]   0   2
(GBPUSD,H6)     [ 3,]   0   3
(GBPUSD,H6)     [ 4,]   0   4
(GBPUSD,H6)     [ 5,]   0   5
(GBPUSD,H6)     [ 6,]   0   6
(GBPUSD,H6)     [ 7,]   0   7
(GBPUSD,H6)     [ 8,]   0   8
(GBPUSD,H6)     [ 9,]   0   9
(GBPUSD,H6)     [10,]   0  10
(GBPUSD,H6)     [11,]   0  11
(GBPUSD,H6)     [12,]   0  12
(GBPUSD,H6)     [13,]   0  13
(GBPUSD,H6)     [14,]   0  14
(GBPUSD,H6)     [15,]   0  15
(GBPUSD,H6)     [16,]   0  16
(GBPUSD,H6)     [17,]   0  17
(GBPUSD,H6)     [18,]   0  18
(GBPUSD,H6)     [19,]   0  19
(GBPUSD,H6)     [20,]   0  20
(GBPUSD,H6)     [21,]   0  21
(GBPUSD,H6)     [22,]   0  22
(GBPUSD,H6)     [23,]   0  23
(GBPUSD,H6)     [24,]   0  24
(GBPUSD,H6)     [25,]   0  25
(GBPUSD,H6)     [26,]   0  26
(GBPUSD,H6)     [27,]   0  27
(GBPUSD,H6)     [28,]   0  28
(GBPUSD,H6)     [29,]   0  29
(GBPUSD,H6)     [30,]   0  30
(GBPUSD,H6)     [31,]   0  31
(GBPUSD,H6)     [32,]   0  32
(GBPUSD,H6)     [33,]   0  33
(GBPUSD,H6)     [34,]   0  34
(GBPUSD,H6)     [35,]   0  35
(GBPUSD,H6)     [36,]   0  36
(GBPUSD,H6)     [37,]   0  37
(GBPUSD,H6)     [38,]   0  38
(GBPUSD,H6)     [39,]   0  39
(GBPUSD,H6)     [40,]   0  40
(GBPUSD,H6)     [41,]   0  41
(GBPUSD,H6)     [42,]   0  42
(GBPUSD,H6)     [43,]   0  43
(GBPUSD,H6)     [44,]   0  44
(GBPUSD,H6)     [45,]   0  45
(GBPUSD,H6)     [46,]   0  46
(GBPUSD,H6)     [47,]   0  47
(GBPUSD,H6)     [48,]   0  48
(GBPUSD,H6)     [49,]   0  49
(GBPUSD,H6)     -------------
(GBPUSD,H6)          [,0][,1]
(GBPUSD,H6)     [ 0,]   0   0
(GBPUSD,H6)     [ 1,]   0   1
(GBPUSD,H6)     [ 2,]   0   2
(GBPUSD,H6)     [ 3,]   0   3
(GBPUSD,H6)     [ 4,]   0   4
(GBPUSD,H6)     [ 5,]   0   5
(GBPUSD,H6)     [ 6,]   0   6
(GBPUSD,H6)     [ 7,]   0   7
(GBPUSD,H6)     [ 8,]   0   8
(GBPUSD,H6)     [ 9,]   0   9
(GBPUSD,H6)     [10,]   0  10
(GBPUSD,H6)     [11,]   0  11
(GBPUSD,H6)     [12,]   0  12
(GBPUSD,H6)     [13,]   0  13
(GBPUSD,H6)     [14,]   0  14
(GBPUSD,H6)     [15,]   0  15
(GBPUSD,H6)     [16,]   0  16
(GBPUSD,H6)     [17,]   0  17
(GBPUSD,H6)     [18,]   0  18
(GBPUSD,H6)     [19,]   0  19
(GBPUSD,H6)     [20,]   0  20
(GBPUSD,H6)     [21,]   0  21
(GBPUSD,H6)     [22,]   0  22
(GBPUSD,H6)     [23,]   0  23
(GBPUSD,H6)     [24,]   0  24
(GBPUSD,H6)     [25,]   0  25
(GBPUSD,H6)     [26,]   0  26
(GBPUSD,H6)     [27,]   0  27
(GBPUSD,H6)     [28,]   0  28
(GBPUSD,H6)     [29,]   0  29
(GBPUSD,H6)     [30,]   0  30
(GBPUSD,H6)     [31,]   0  31
(GBPUSD,H6)     [32,]   0  32
(GBPUSD,H6)     [33,]   0  33
(GBPUSD,H6)     [34,]   0  34
(GBPUSD,H6)     [35,]   0  35
(GBPUSD,H6)     [36,]   0  36
(GBPUSD,H6)     [37,]   0  37
(GBPUSD,H6)     [38,]   0  38
(GBPUSD,H6)     [39,]   0  39
(GBPUSD,H6)     [40,]   0  40
(GBPUSD,H6)     [41,]   0  41
(GBPUSD,H6)     [42,]   0  42
(GBPUSD,H6)     [43,]   0  43
(GBPUSD,H6)     [44,]   0  44
(GBPUSD,H6)     [45,]   0  45
(GBPUSD,H6)     [46,]   0  46
(GBPUSD,H6)     [47,]   0  47
(GBPUSD,H6)     [48,]   0  48
(GBPUSD,H6)     [49,]   0  49
(GBPUSD,H6)     [ 0] "H6 Vertical Line 10771" "H6 Vertical Line 10884" "H6 Vertical Line 12743" "H6 Vertical Line 1371"  "H6 Vertical Line 14306"
(GBPUSD,H6)     [ 5] "H6 Vertical Line 16501" "H6 Vertical Line 17907" "H6 Vertical Line 20277" "H6 Vertical Line 23365" "H6 Vertical Line 28358"
 
Сергей Таболин:

Mystery simple....

Ran just this the first time - it printed an array, all nice.

Added this - and I don't know what's going on at all... I guess it's time to go to sleep after all....

Maybe I don't understand something, but herelong tml = (long)ObjectGetInteger(ChartID(),vlines_name[i],OBJPROP_TIME); substitute line name, not index, otherwise you won't get result.

Reason: