# 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...

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

when market 1.2080 buy close open a sell

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

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(OrderSelect(t,SELECT_BY_TICKET))
{
bool c = OrderClose(t,OrderLots(),OrderClosePrice(),0,clrNONE);
if(c)
Ticket[i] = 0;
}
if(!OpenReverse)
{
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
{