Heeeeeeeeeelp is this strange Case !!!!!!!!!!!!!!!!!!!!!!!!!!!

 

Dear's,

Kindly i neeed a help about the below code as it sometimes calculate take profit right and if you close Oppsite trade (Second trade) manual and try this more than once it will calculate wrong :(

i neeed your heeeelp please :(


extern int MAGICMA = 222222222222;
extern int Opp = 0;

void start()
  {
int Ticket03;
int TradeMin = 1;

if(Digits==3 || Digits==5) Dig=10;
if(Digits==2 || Digits==4) Dig=1;

if(OrderSelect(SELECT_BY_POS,MODE_TRADES)==true)
   {
    if(
       MathFloor(OrderProfit()/OrderLots()/MarketInfo(OrderSymbol(),MODE_TICKVALUE)) <= -20)
    {
     int Trade = MathFloor( OrderProfit()/ (OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)));
     
     if(TradeMin > Trade)
     { 
      TradeMin = Trade;
      
      if(Opp-2 >= TradeMin && OrdersTotal()== 1)
      {
       Opp = TradeMin;
       
       if(OrderType() == OP_BUY && IsTradeAllowed() == true)
       {
        Ticket03 = OrderSend(OrderSymbol(),OP_SELL,OrderLots(),Bid,0,0.0,0.0,"EA",481162,0,Red);
        
        if(Ticket03 > 0)
        {
         if(OrderSelect(Ticket03,SELECT_BY_TICKET)==true)
         {
          TP = OrderOpenPrice()-(TakeProfit*Dig)*Point;
          SL = OrderOpenPrice()+(StopLoss*Dig)*Point;
        
          OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0,Red);
          Print("OrderSend Success for Symbol : ",OrderSymbol()," Opposite");
          Print("Loss Points : ",Opp);
          return(0);
         }
        }
        else
        {
         Print("OrderSend failed with error : #",GetLastError());
         return(0);
        }
       }
       if(OrderType() == OP_SELL && IsTradeAllowed() == true)
       {
        Ticket03 = OrderSend(OrderSymbol(),OP_BUY,OrderLots(),Ask,0,0.0,0.0,"EA",481162,0,Green);
        
        if(Ticket03 > 0)
        {
         if(OrderSelect(Ticket03,SELECT_BY_TICKET)==true)
         {
          TP = OrderOpenPrice()+(TakeProfit*Dig)*Point;
          SL = OrderOpenPrice()-(StopLoss*Dig)*Point;
        
          OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0,Green);
          Print("OrderSend Success for Symbol : ",OrderSymbol()," Opposite");
          Print("Loss Points : ",Opp);
          return(0);
         }
        }
        else
        {
         Print("OrderSend failed with error : #",GetLastError());
         return(0);
        }
       }
      }
      return(0);
     }
     return(0);
    }
    else
    {
     Opp = 0;
     //Print("Loss : ",Opp);
     return(0);
    }
   }
Reason: