Dividing open positions into groups - page 5

 
Alexey Viktorov:

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

This code stings to the eye, as if it were intentionally made worse.

Well, if it doesn't make a difference, let's do it this way:

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);

    for(int j=0;j<100;j++)
    Sleep(1);
   }

Why not?

ArrayResize(arrTest, 10);
for(int i = 0; i < 10; i++)
  {
    arrTest[i][0] = iOpen(_Symbol, PERIOD_CURRENT, i);
    arrTest[i][1] = iClose(_Symbol, PERIOD_CURRENT, i);
  }
 
Aliaksandr Hryshyn:

This code stings to the eye, as if it were intentionally made worse.

If it doesn't make a difference, let's do it this way:

Why?

ps; Ahh, I see. Well, this is an example. When the working array will be filled, for sure it will be filled by one index. Not the variant where you have to pay attention to such subtleties.
 
Alexey Viktorov:

Why?

Probably for the reason why you have the array change inside the loop when the size is known in advance.

I don't know the exact reason :).

You're freelancing, aren't you! Terrible :).

 
Aliaksandr Hryshyn:

Probably for the reason why you have the array change inside the loop when the size is known in advance.

I don't know the exact reason :).

You're freelancing, aren't you! Terrible :).

So what of it?

 
Alexey Viktorov:

That's rubbish. I used this function without reading the manual. ...

It worked, thank you very much !!! What I wrote was indeed nonsense, theArrayRemove delete function works fine on arrays of any dimension.

The error was elsewhere. After applying the function, I had to redefine it, this time to a smaller array, because in the next step this variable was used in the loop again, and the array fell out of the range (I may be wrong in terminology, but I hope I made myself clear).

I will post the working version below and in the attached file. The subtle points are highlighted.

//+------------------------------------------------------------------+
int Array_Caste_Positions_Creating(){
   int  n           = 0;
   long ticket      = 0;
   bool new_pos     = true;
//---Запись новых тикетов в массив позиций        
   int All_Position = PositionsTotal();
   int Array_Size   = ArrayRange(Arr_Position,0);
//---  
   for(int i = 0; i < All_Position; i++){
      if(m_position.SelectByIndex(i)){
         ticket  = PositionGetInteger(POSITION_TICKET);
         new_pos = true;}
      for(int e = 0; e < Array_Size; e++){
         if(Arr_Position[e][0]==ticket){
            new_pos = false;
            n++;
            break;}}
      if(new_pos){
         int New_Size = Array_Size+1;
         ArrayResize(Arr_Position,New_Size,0);
            Arr_Position[Array_Size][0] = (int)ticket;//Ticket
            Arr_Position[Array_Size][1] = 0;//Number_Caste (0 = начальные позиции)
            n++;}}                       
//---Удаление из массива мёртвых тикетов 
      Array_Size   = ArrayRange(Arr_Position,0);
      All_Position = PositionsTotal();
//---      
      for(int e = 0; e < Array_Size; e++){
         int  ticket_dead = Arr_Position[e][0];
         bool dead_pos    = true;
         for(int i = 0; i < All_Position; i++){
            if(m_position.SelectByIndex(i)){
                  if(ticket_dead == PositionGetInteger(POSITION_TICKET)){
                        dead_pos = false;
                        n++;
                        break;}}}
         if(dead_pos){
            ArrayRemove(Arr_Position,e,1);
            Array_Size   = ArrayRange(Arr_Position,0);}}
//---     
return(n);}
//+------------------------------------------------------------------+
Files:
Sower_1_6.mq5  19 kb
 

I feel like a misbehaving student, unwittingly present at an argument between two teachers, each insisting on the correctness of their teaching methodology.

Allow me to insert my delicate three cents.

Despite the slight imperfection of the code of the example postedby Alexey Viktorov, the thoughts he put forward were correct and they helped us to understand it. And if a freelancer is ready and willing to help free of charge, not trying to extort an extra penny - then praise him, I really respect him. Thank you.

Aliaksandr Hryshyn- Thank you very much, you also were not indifferent and sincerely wanted to help and you did it. Who knows how events would have unfolded without your criticism?

 
Sergey Voytsekhovsky:

It worked, thank you very much !!! What I wrote was really nonsense, theArrayRemove delete function works fine on arrays of any dimension.

The error was elsewhere. After applying the function, I had to redefine it, this time to a smaller array, because in the next step this variable was used again in the loop, and the array fell out of the range (I may be wrong in terminology, but I hope I made myself clear).

I will post the working version below and in the attached file. The subtle points are highlighted.

Quick tutorial.

Here it is

      if(m_position.SelectByIndex(i)){
         ticket  = PositionGetInteger(POSITION_TICKET);

can be replaced by

      t icket = PositionGetTicket(i);
 
Alexey Viktorov:

A little literacy.

This one

can be replaced by.

Great, if any other places in code cause rejection - please show me, I am a homebrew coder, what I dug, that's mine, knowledge is not systematic and fragmentary. I will be very grateful for guidance on the right path.

Corrected, now it's like this:

//---Запись новых тикетов в массив позиций        
   int All_Position = PositionsTotal();
   int Array_Size   = ArrayRange(Arr_Position,0);
//---  
   for(int i = 0; i < All_Position; i++){
      ticket = (int)PositionGetTicket(i);
      new_pos = true;
      for(int e = 0; e < Array_Size; e++){
         if(Arr_Position[e][0]==ticket){
            new_pos = false;
            n++;
            break;}}
      if(new_pos){
         int New_Size = Array_Size+1;
         ArrayResize(Arr_Position,New_Size,0);
            Arr_Position[Array_Size][0] = (int)ticket;//Ticket
            Arr_Position[Array_Size][1] = 0;//Number_Caste (0 = начальные позиции)
            n++;}}                       
 
Sergey Voytsekhovsky:

Great, if there are any other places in the code that cause rejection - please show me, I am a homebrew coder, what I found is mine, the knowledge is not systematic and fragmentary. I would be very grateful for guidance on the right path.

Only on occasion. I won't keep track of it. In fact, I'm self-taught and an old self-taught man, too.

Tickets in mql5 are of ulong type

Then there's less to bring to the type

 
Alexey Viktorov:

Only if there is an occasion. I won't be watching. And in general, I am also self-taught, and an old self-taught one at that.

Tickets in mql5 are of ulong type

Then there's less to bring to the type

Thank you, I'll take it into account, and I'll redo it here later.