Reverse logic error

 

Hello I need your assistance in debugging the following code to implement the logic below, I've tried many times but I am stuck. Your help will be appreciated:


logic is open with buy and sell pair as per input..

when tp hit then reverse with opposite trade

when loss then hedge at desired pips..

this is the continuous process...

but ea not working continuous.. and stop after few trades...

if eurusd open a buy trade at 1.2060


we use tp=20 and hedge at loss pips 20 then


when market 1.2080 buy close open a sell


when sell trade go loss at 20 pips 1.3000 buy trade open


when this buy 1.3000 hit tp at 1.3020 then sell open


when 1.3020 sell hit tp at 1.3000 then buy open


when this 1.3000 buy loss then 1.2080 there is existing sale already so no double trade...


this is the strategy and continuous cycle...


void ReplaceClosed()
  {
   int b = 0, s = 0;
   string curr;
   int t = 0;
   for(int i=0; i<ArraySize(Ticket); i++)
     {
      if(Ticket[i] != 0 && OrderSelect(Ticket[i],SELECT_BY_TICKET))
        {
         curr = OrderSymbol();
         t = OrderTicket();
         if(OrderCloseTime() == 0)
           {
            if(OrderType() == OP_BUY && OrderMagicNumber()==MagicNumber && SymbolInfoDouble(curr,SYMBOL_ASK) - OrderOpenPrice() >= TakeProfit*GetPips(curr) && !OrderArround(curr,SymbolInfoDouble(curr,SYMBOL_ASK),"buy"))
              {
               if(OrderSelect(t,SELECT_BY_TICKET))
                 {
                  bool c = OrderClose(t,OrderLots(),OrderClosePrice(),0,clrNONE);
                  if(c)
                     Ticket[i] = 0;
                 }
               if(!OpenReverse)
                 {
                  b = OrderSend(curr,OP_BUY,LotSize,SymbolInfoDouble(curr,SYMBOL_ASK),0,0,0,EAComment,MagicNumber,0,clrNONE);
                  if(b > 0)
                     Save(b);
                 }
               else
                 {
                  s = OrderSend(curr,OP_SELL,LotSize,SymbolInfoDouble(curr,SYMBOL_BID),0,0,0,EAComment,MagicNumber,0,clrNONE);
                  if(s > 0)
                     Save(s);
                 }
              }

            if(OrderType() == OP_SELL  && OrderMagicNumber()==MagicNumber && OrderOpenPrice() - SymbolInfoDouble(curr,SYMBOL_BID) >= TakeProfit*GetPips(curr) && !OrderArround(curr,SymbolInfoDouble(curr,SYMBOL_BID),"sell"))
              {
               if(OrderSelect(t,SELECT_BY_TICKET))
                 {
                  bool c = OrderClose(t,OrderLots(),OrderClosePrice(),0,clrNONE);
                  if(c)
                     Ticket[i] = 0;
                 }
               if(!OpenReverse)
                 {
                  s = OrderSend(curr,OP_SELL,LotSize,SymbolInfoDouble(curr,SYMBOL_BID),0,0,0,EAComment,MagicNumber,0,clrNONE);
                  if(s > 0)
                     Save(s);
                 }
               else
                 {
                  b = OrderSend(curr,OP_BUY,LotSize,SymbolInfoDouble(curr,SYMBOL_ASK),0,0,0,EAComment,MagicNumber,0,clrNONE);
                  if(b > 0)
                     Save(b);
                 }
              }
           }
        }
     }
  }