Array out of range error

 
Hello,

I need a little help. Some time ago, a friend of mine quickly made a module. It worked well, but obviously there are some changes and now it gives me this mistake.

// Collect data - array sorted by profit (profitable last)
                for (pos=0; pos<total; pos++) {
                   if (EABC::OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) {
                      if (FilterOrderBy(GroupMode,Group, MarketMode,Market, "both")) {
                         
                         int ticket=EABC::OrderTicket();
                         double profit=EABC::OrderProfit()+EABC::OrderSwap()+EABC::OrderCommission();
                         
                         int size=ArraySize(tickets_list);
                         ArrayResize(tickets_list,size+1);
                         ArrayResize(profits_list,size+1);
                         ArrayResize(types_list,size+1);
                         tickets_list[size]=ticket;
                         profits_list[size]=profit;
                         types_list[size]=EABC::OrderType();
                         last_index=size;
                         
                         double profits_tmp;
                         int tickets_tmp;
                         int is_smallest=true;
                         if (last_index>0) {
                            for (i=0; i<last_index; i++) {
                               if (profit<profits_list[i]) {
                                  if (profit>=profits_list[i-1] || i==0) {
                                     for (j=last_index; j>i; j--) {
                                         profits_list[j]=profits_list[j-1];
                                         tickets_list[j]=tickets_list[j-1];
                                         types_list[j]=types_list[j-1];
                                     }
                                     profits_list[i]=profit;
                                     tickets_list[i]=ticket;
                                     types_list[i]=EABC::OrderType();
                                     break;
                                  }
                               }
                            }
                         }

Thank you so much

 
GMGlive:
Hello,

I need a little help. Some time ago, a friend of mine quickly made a module. It worked well, but obviously there are some changes and now it gives me this mistake.

Thank you so much

Post the whole function, so people could help you

 
amrali #:

Post the whole function, so people could help you

Sorry. I never used the forum before.

***

 
  1. Don't post pictures of code, they are too hard to read.

    Please edit your post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. When i is zero, array[i-1] does not exist. You would know that if you had used the debugger.
  3. Simplify your code by counting down.
    for (i=last_index; i >= 0; --i){
       if(profit > profits_list[i]) break;
       profits_list[i+1]=profits_list[i];
       tickets_list[i+1]=tickets_list[i];
       types_list[i+1]=types_list[i]
    }
       profits_list[i+1]=profit;
       tickets_list[i+1]=ticket;
       types_list[i+1]=BCDD::OrderType();
    

 
William Roeder #:
  1. Don't post pictures of code, they are too hard to read.

    Please edit your post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. When i is zero, array[i-1] does not exist. You would know that if you had used the debugger.
  3. Simplify your code by counting down.

Thank you! I'll do it.