EA Not closing all trades of a specific pair when achieving Pair Target

 

I'm looking for someone who can help me modify or correct the mistake in my code for a trade manager that closes all trades when its target is reached. This works perfectly with the Equity Target but fails to do the same for Pair Target. At times it works flawlessly but when reapplied on the same chart; It stops closing trades .

Hope someone can point my mistake or share a corrected code with me which fulfils my purpose.

Thanks and Cheers!

Kindly respond or Personally message me if the entire EA Code is required..

 if(GlobalVariableGet("TradeEnable") == 1)
         returnflag = 1;

      if(returnflag == 1 || GlobalVariableGet("TradeEnable") == 1)
         return;
         
      
      double tProfit = ClosedTotalProfit() + OpenTotalProfit();
      if(tProfit >= PAIR_TARGET && PAIR_TARGET != 0 ){

         int j = OrdersTotal();
         while(j > 0) {

            CLOSEALLORDER();
            CLOSEALLORDER();
            CLOSEALLORDER();
            CLOSEALLORDER();
            CLOSEALLORDER();
            CLOSEALLORDER();
            CLOSEALLORDER();
            CLOSEALLORDER();
            CLOSEALLORDER();
            CLOSEALLORDER();
            j--;
         }
         
         Print("All trades closed due to PAIR_TARGET.");
         ObjectSetString(0,value5,OBJPROP_TEXT,DoubleToString(targetProfit,2)+"      PAIR TARGET ACHIEVED");
         returnflag = 1;
         
      }
 

Is this supposed to be for MT5 or MT4?

AS you don't show the functions, how is anybody likely to help?

 
Keith Watford:

Is this supposed to be for MT5 or MT4?

AS you don't show the functions, how is anybody likely to help?

Its for MT5;

Attaching the code here...

Reason: