Can't get my orders count filtering by Magic Number, can someone help my code to check, please?

 

Hello everyone, I hope someone can help to check my code.

I wrote my own function that counts the number of orders aggregated separately by the magic number.

However, when I ran the Strategy Tester, I found that the function might not work as well.

Here is what I wanted to do in the code. (I will write only part of the code, not all of it. The main function "MyCurrentOrders" is written at the last.)

======================================================

int Magic_M1 = 10099990;
int Magic_M1_H = 10099991;
int Magic_M5 = 50099990;
int Magic_M5_H = 50099991;
int Magic_M15 = 15099990;
int Magic_M15_H = 15099991;
int Magic_H1 = 60099990;
int Magic_H1_H = 60099991;
int Magic_H4 = 24099990;
int Magic_H4_H = 24099991;
int Magic_D1 = 14409990;
int Magic_D1_H = 14409991;
int Magic_W1 = 10080990;
int Magic_W1_H = 10080991;
int Magic_MN1 = 43200990;
int Magic_MN1_H = 43200991;
int Magic_STOP = 99999999;
int Magic_Manual = 0;

double Lots_M1_B =0.0, Lots_M1_S =0.0, Lots_M1_H =0.0, Lots_M5_B =0.0, Lots_M5_S =0.0, Lots_M5_H =0.0, Lots_M15_B =0.0, Lots_M15_S =0.0, Lots_M15_H =0.0, Lots_H1_B =0.0, Lots_H1_S =0.0, Lots_H1_H =0.0, Lots_H4_B =0.0, Lots_H4_S =0.0, Lots_H4_H =0.0, Lots_D1_B =0.0, Lots_D1_S =0.0, Lots_D1_H =0.0, Lots_W1_B =0.0, Lots_W1_S =0.0, Lots_W1_H =0.0, Lots_MN1_B =0.0, Lots_MN1_S =0.0, Lots_MN1_H =0.0, Lots_STOP =0.0, Lots_Manual =0.0;

MyCurrentOrders(Lots_M1_B, Lots_M1_S, Lots_M1_H, Lots_M5_B, Lots_M5_S, Lots_M5_H, Lots_M15_B, Lots_M15_S, Lots_M15_H, Lots_H1_B, Lots_H1_S, Lots_H1_H, Lots_H4_B, Lots_H4_S, Lots_H4_H, Lots_D1_B, Lots_D1_S, Lots_D1_H, Lots_W1_B, Lots_W1_S, Lots_W1_H, Lots_MN1_B, Lots_MN1_S, Lots_MN1_H, Lots_STOP, Lots_Manual);

double Lot_B[9];
ArrayInitialize(Lot_B,0);
Lot_B[0] = Lots_M1_B;
Lot_B[1]  = Lots_M5_B;
Lot_B[2]  = Lots_M15_B;
Lot_B[3]  = Lots_H1_B;
Lot_B[4]  = Lots_H4_B;
Lot_B[5]  = Lots_D1_B;
Lot_B[6]  = Lots_W1_B;
Lot_B[7]  = Lots_MN1_B;
Lot_B[8]  = 0;

double Lot_S[9];
ArrayInitialize(Lot_S,0);
Lot_S[0] = Lots_M1_S;
Lot_S[1]  = Lots_M5_S;
Lot_S[2]  = Lots_M15_S;
Lot_S[3]  = Lots_H1_S;
Lot_S[4]  = Lots_H4_S;
Lot_S[5]  = Lots_D1_S;
Lot_S[6]  = Lots_W1_S;
Lot_S[7]  = Lots_MN1_S;
Lot_S[8]  = 0;

//============================================================
//After this it seems the value of Lot_B[0] until Lot_B[8] and  Lot_S[0] until Lot_S[8] return 0, even it may have some BUY/SELL positions.
//Below is the code of my own function.
//============================================================ 

void MyCurrentOrders(double& lots_M1_B, double& lots_M1_S, double& lots_M1_H, double& lots_M5_B, double& lots_M5_S, double& lots_M5_H, double& lots_M15_B, double& lots_M15_S, double& lots_M15_H, double& lots_H1_B, double& lots_H1_S, double& lots_H1_H, double& lots_H4_B, double& lots_H4_S, double& lots_H4_H, double& lots_D1_B, double& lots_D1_S, double& lots_D1_H, double& lots_W1_B, double& lots_W1_S, double& lots_W1_H, double& lots_MN1_B, double& lots_MN1_S, double& lots_MN1_H, double& lots_STOP, double& lots_Manual)
{
   for(int i=0; i<OrdersTotal(); i++)
   {
      if(OrderSelect(i, SELECT_BY_POS) == false) break;
      if(OrderSymbol() != Symbol()) continue;
      if(OrderType() != OP_BUY || OrderType() != OP_SELL) continue;
      
      if(OrderType() == OP_BUY)
      {
         switch(OrderMagicNumber())
         {
            case 10099990:
               lots_M1_B += OrderLots();
               break;
            case 10099991:
               lots_M1_H += OrderLots();
               break;            

            case 50099990:
               lots_M5_B += OrderLots();
               break;
            case 50099991:
               lots_M5_H += OrderLots();
               break;            

            case 15099990:
               lots_M15_B += OrderLots();
               break;
            case 15099991:
               lots_M15_H += OrderLots();
               break;            

            case 60099990:
               lots_H1_B += OrderLots();
               break;
            case 60099991:
               lots_H1_H += OrderLots();
               break;            
            
            case 24099990:
               lots_H4_B += OrderLots();
               break;
            case 24099991:
               lots_H4_H += OrderLots();
               break;            
            
            case 14409990:
               lots_D1_B += OrderLots();
               break;
            case 14409991:
               lots_D1_H += OrderLots();
               break;            

            case 10080990:
               lots_W1_B += OrderLots();
               break;
            case 10080991:
               lots_W1_H += OrderLots();
               break;            

            case 43200990:
               lots_MN1_B += OrderLots();
               break;
            case 43200991:
               lots_MN1_H += OrderLots();
               break;            

            case 99999999:
               lots_STOP += OrderLots();
               break;

            case 0:
               lots_Manual += OrderLots();
               break;            
         }
      
      }

      else if(OrderType() == OP_SELL)
      {
         switch(OrderMagicNumber())
         {
            case 10099990:
               lots_M1_S -= OrderLots();
               break;
            case 10099991:
               lots_M1_H -= OrderLots();
               break;            

            case 50099990:
               lots_M5_S -= OrderLots();
               break;
            case 50099991:
               lots_M5_H -= OrderLots();
               break;            

            case 15099990:
               lots_M15_S -= OrderLots();
               break;
            case 15099991:
               lots_M15_H -= OrderLots();
               break;            

            case 60099990:
               lots_H1_S -= OrderLots();
               break;
            case 60099991:
               lots_H1_H -= OrderLots();
               break;            
            
            case 24099990:
               lots_H4_S -= OrderLots();
               break;
            case 24099991:
               lots_H4_H -= OrderLots();
               break;            
            
            case 14409990:
               lots_D1_S -= OrderLots();
               break;
            case 14409991:
               lots_D1_H -= OrderLots();
               break;            

            case 10080990:
               lots_W1_S -= OrderLots();
               break;
            case 10080991:
               lots_W1_H -= OrderLots();
               break;            

            case 43200990:
               lots_MN1_S -= OrderLots();
               break;
            case 43200991:
               lots_MN1_H -= OrderLots();
               break;            

            case 99999999:
               lots_STOP -= OrderLots();
               break;

            case 0:
               lots_Manual -= OrderLots();
               break;            
         }
      }      
   }
}
The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
理由: