Dividing open positions into groups - page 4

 
Alexey Viktorov:

Copying the array "into itself", starting at the position next to the one to be deleted and writing from the one to be deleted. And then resize as Grigori.S.B suggested

Interestingly, if I understood you correctly, do you need to use this function?

int  ArrayCopy( 
   void&        dst_array[],         // куда копируем 
   const void&  src_array[],         // откуда копируем 
   int          dst_start=0,         // с какого индекса пишем в приемник 
   int          src_start=0,         // с какого индекса копируем из источника 
   int          count=WHOLE_ARRAY    // сколько элементов 
   );
 
Sergey Voytsekhovsky:

Good morning, thank you for your reply.

I guess you haven't noticed, you can look above, all the questions were about MQL5.

I understand that the difference is not crucial sometimes, but nevertheless. The function you cited resizes the array, perhaps cutting off extra elements if the size is reduced.

This is not what is needed. You need to remove an element by finding it by value. I tried this function too, I wrote about it in #23. Thanks anyway.

I have not paid attention to it too. mql5 has ArrayRemove function and no problems.

 

In this caseArrayRemove is more suitable, there is an example in the manual, it works exactly the same way

//| Script program start function                                    | 
//+------------------------------------------------------------------+ 
void OnStart() 
  { 
//--- объявим массив фиксированного размера и заполним значениями 
   int array[10]; 
   for(int i=0;i<10;i++) 
     { 
      array[i]=i; 
     } 
//--- покажем массив до удаления элементов 
   Print("До вызова ArrayRemove()"); 
   ArrayPrint(array); 
//--- удалим 2 элемента из массива и покажем новый состав 
   ArrayRemove(array,4,2); 
   Print("После вызова ArrayRemove()"); 
   ArrayPrint(array); 
/* 
   Результат выполнения:  
   До вызова ArrayRemove() 
   0 1 2 3 4 5 6 7 8 9 
   После вызова ArrayRemove() 
   0 1 2 3 6 7 8 9 8 9 
*/

The only problem is, these examples and functions are designed for one-dimensional arrays, and they don't want to work with two-dimensional arrays.

I think I'm missing something very important and fundamental. But what is it?

I'm telling you, I've already lost the reference book.

 
Sergey Voytsekhovsky:

In this caseArrayRemove is more suitable, there is an example in the manual, it works exactly the same way

The only problem is, these examples and functions are designed for one-dimensional arrays, and they don't want to work with two-dimensional arrays.

I think I'm missing something very important and fundamental. But what is it?

I'm telling you, I've already lost track of it.

Is the order important?
Copy from the last position to the one to be deleted, resize the array.
 
Alexey Viktorov:
For a two-dimensional array, you need to multiply the line number for deletion by 2. For a 3-dimensional array multiply by 3...

I don't quite understand this, could you please elaborate on it, or better yet, show me the edit on a piece of my code, I posted it above. If it's inconvenient, then whatever, I'll figure it out somehow.

 
Aliaksandr Hryshyn:
Is the order important?
You copy from the last position to the one to be deleted, resize the array.

No, the order is not important, you just need to delete a known (found by knowledge, index is known) entry. It can be anywhere in the array (at the beginning, in the middle, at the end).ArrayRemove is great, everything would be fine, but how to apply this function to a two-dimensional array? the manual is silent about it.

 
Sergey Voytsekhovsky:

No, the order is not important, we just need to delete a known (found by cognition, index is known) record. It can be anywhere in the array (at the beginning, in the middle, at the end).ArrayRemove is great, everything would be fine, but how to apply this function to a two-dimensional array? There's nothing in the manual about it.

So do as I said, only the array in the second dimension is copied.
When resizing an array, specify a third parameter as well, e.g. 32.
 
Sergey Voytsekhovsky:

In this caseArrayRemove is more suitable, there is an example in the manual, it works exactly like this

The only problem is, these examples and functions are designed for one-dimensional arrays, and they don't want to work with two-dimensional arrays.

I think I'm missing something very important and fundamental. But what is it?

I'm telling you, I've lost the reference book.

That's nonsense. I used this function without reading the manual. In the debugger I saw how the element was deleted and the array size was instantly reduced. I checked it, it works even with an array of structures without any problems. Now I cannot work with the code, but only words: For example, I want to delete the 3rd index from a 2-dimensional array. It turns out that the fifth and sixth values have to be removed. When copying, the function, HOWEVER, arranges all values into a one-dimensional array and it turns out that the third pair begins with index 5. In general this comes to a realization after a few experiments.

As for ArrayRemove when I can, I'll test it on 2-4 dimensional arrays. For want of need I've never tested it and didn't suspect it didn't work.


Added:

Checked. Don't forget that you can't resize a static array. That's why in the example from the documentation the size of the array remains the same and the last two strings are repeated. When you delete rows from a dynamic array, the size changes without any problems.

The handbook should be scrubbed to the holes:)))) in the monitor.

/********************Script program start function*******************/
void OnStart()
 {
  double arrTest[][ 2];
  for(int i = 0; i < 10; i++)
   {
    ArrayResize(arrTest, i+1);
    arrTest[i][0] = iOpen(_Symbol, PERIOD_CURRENT, i);
    arrTest[i][1] = iClose(_Symbol, PERIOD_CURRENT, i);
   }
    Print("ArraySize ", ArraySize(arrTest));
    ArrayPrint(arrTest);
    ArrayRemove(arrTest, 3, 2);
    Print("ArraySize ", ArraySize(arrTest));
    ArrayPrint(arrTest);
         );
 }/******************************************************************/
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  ArraySize 20
2020.03.23 11:36:02.296 00 (GBPUSD,H1)          [,0]    [,1]
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [0,] 1.16465 1.16084
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [1,] 1.17094 1.16461
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [2,] 1.16878 1.17084
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [3,] 1.16525 1.16876
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [4,] 1.16467 1.16525
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [5,] 1.16491 1.16467
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [6,] 1.16186 1.16498
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [7,] 1.15985 1.16185
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [8,] 1.16156 1.15985
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [9,] 1.15447 1.16156
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  ArraySize 16
2020.03.23 11:36:02.296 00 (GBPUSD,H1)          [,0]    [,1]
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [0,] 1.16465 1.16084
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [1,] 1.17094 1.16461
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [2,] 1.16878 1.17084
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [3,] 1.16491 1.16467
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [4,] 1.16186 1.16498
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [5,] 1.15985 1.16185
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [6,] 1.16156 1.15985
2020.03.23 11:36:02.296 00 (GBPUSD,H1)  [7,] 1.15447 1.16156

Here is the 3-dimensional array and the result:

2020.03.23 11:40:11.328 00 (GBPUSD,H1)  ArraySize 30
2020.03.23 11:40:11.328 00 (GBPUSD,H1)          [,0]    [,1]    [,2]
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [0,] 0.00000 1.16465 1.16255
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [1,] 1.00000 1.17094 1.16461
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [2,] 2.00000 1.16878 1.17084
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [3,] 3.00000 1.16525 1.16876
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [4,] 4.00000 1.16467 1.16525
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [5,] 5.00000 1.16491 1.16467
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [6,] 6.00000 1.16186 1.16498
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [7,] 7.00000 1.15985 1.16185
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [8,] 8.00000 1.16156 1.15985
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [9,] 9.00000 1.15447 1.16156
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  ArraySize 24
2020.03.23 11:40:11.328 00 (GBPUSD,H1)          [,0]    [,1]    [,2]
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [0,] 0.00000 1.16465 1.16255
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [1,] 1.00000 1.17094 1.16461
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [2,] 2.00000 1.16878 1.17084
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [3,] 5.00000 1.16491 1.16467
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [4,] 6.00000 1.16186 1.16498
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [5,] 7.00000 1.15985 1.16185
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [6,] 8.00000 1.16156 1.15985
2020.03.23 11:40:11.328 00 (GBPUSD,H1)  [7,] 9.00000 1.15447 1.16156
 
Alexey Viktorov:

That's rubbish. I used this function without reading the manual. In debugger I saw how element is deleted and array size is instantly reduced. Checked, even on an array of structures works without problems. Now I cannot work with the code, but only words: For example, I want to delete the 3rd index from a 2-dimensional array. It turns out that the fifth and sixth values have to be removed. When copying, the function, HOWEVER, arranges all values into a one-dimensional array and it turns out that the third pair begins with index 5. In general this comes to a realization after a few experiments.

As for ArrayRemove when I can, I'll test it on 2-4 dimensional arrays. For want of need I've never tested it and didn't suspect it didn't work.


Added:

Checked. Don't forget that you can't resize a static array. That's why in the example from the documentation the size of the array remains the same and the last two strings are repeated. When you delete rows from a dynamic array, the size changes without any problems.

The directory has to be scrubbed to the holes:)))) in the monitor.

Here I have made a 3 dimensional array and the result:

Your example is very slow, with a large number of values this will be noticeable.
 
Aliaksandr Hryshyn:
Your example is very slow, with a large number of values this will be noticeable.

With a lot of what? Array elements that are not even filled on every tick? How will it be noticeable?