Remove sell signal after a Short

I wrote a code with buy / sell / short / cover signal as below. Buy and short signal are fine but it always shows wrong close signal such as sell signal after a short or cover signal after a buy. Anyone can guild me how to remove it?


Hh = HHV( H, 27 );
Ll = LLV( L, 27 );
Color1 =(ParamColor("(Highest Hi )",colorRed));
Plot( Hh, "p1:", Color1, styleLine +styleNoTitle);

Color2 =(ParamColor("hh - ( hh - ll ) * 0.5",colorViolet));
Plot( p1, "p1:", Color2, styleLine+styleNoTitle );

Color3 =(ParamColor("( ll )",colorWhite));
Plot( Ll, "p1:", Color3, styleLine+styleNoTitle );

macdvalue= EMA(C,12)-EMA(C,26);
 


buy1 = OBV()>EMA(OBV(),20);
sell1= EMA(OBV(),20)>OBV() ;

buy2 = RSI(15)>EMA(rsi(15),39);
sell2= EMA(rsi(15),39)>rsi(15) ;

buy3 = Ref(MACDvalue,-1)< MACDvalue ;
sell3= Ref(MACDvalue,-1)> MACDvalue;


closebuy =  Cross(Ref(ll,-1),C) OR Cross(p1,C) ;
closeshort = Cross(C,Ref(hh,-1)) OR Cross(C,p1) ;

Buy= buy1 AND  buy2 AND buy3 ;


Short= sell1 AND  Sell2 AND sell3 ;
Sell= Closebuy ;
Cover= closeshort ;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
Long=Flip(Buy,Sell); 
Shrt=Flip(Short,Cover); 
Relax = NOT Long AND NOT Buy AND NOT shrt AND NOT Sell AND NOT Sell AND NOT Cover; 

BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
BPrice=ValueWhen(Long AND Ref(long,-1)==0,C,1);
SPrice=ValueWhen(shrt AND Ref(shrt,-1)==0,C,1);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(IIf(Sell, shapeStar, shapeNone),colorgreen, 0, L, Offset=-15); 
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorred, 0,L, Offset=-15); 

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = "BUY";


bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "CLOSE BUY";
entry = C[i];


bars = i;
i = 0;
}
if(short[i] == 1)
{
sig = "SHORT";
entry = C[i];


bars = i;
i = 0;
}
if(Cover[i] == 1)
{
sig = " CLOSE SHORT";
entry = C[i];


bars = i;
i = 0;
}
}
for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount+1,entry,Null,colorBlue);


}