Need help: selecting a specific open trade from many available open trades

 

Hi everyone,

I have an EA which opens 2 trades simultaneously for a pair. i have also ensured that when a pair is trading, no new trades on the same pair is opened but trades for other pairs are allowed. simply put i want a maximum of 4 pairs (8 in total) to be traded simultaneously.

1. To avoid opening of same pair which is already opened previously, i'm using the below code (A).

2. To manage the active trades for any given pair, i'm using a sets of rules which shall be applied after selection of open trade occurs, and for this i'm using code (B)

My problem is that the rules only works for the first 2 trades of the same pair (in sequence 1 followed by 2), and unless these trades are closed, the sets of rules don't work on other opened trades (different pairs). Also the other pairs are treated in the sequence they were opened.

i would like to get some idea on how to get the rules applied for the opened trades irrespective of the sequence of opening for each pair.

i'm attaching the excerpt for the commands (A) and (B) in the SRC..

really appreciate your

//---Code (A)----

int j=Total - 1;
  int Count=0;

   for (int i=j;i>=0;i--)
   {
   
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if(OrderSymbol()==Symbol())
   {
     Count=Count+1;   //Count++
   }
   
   }
     

 if( Count==0 )
 {  



// ----Code (B)----


for(Cnt=0;Cnt<Total;Cnt++)  
  { 
  
  OrderSelect(Cnt,SELECT_BY_POS,MODE_TRADES);
       
    
     
  if(OrderType()==OP_BUY)                           
  {                 

// Followed by sets of rules.....

comments and guidance on this...

Tq