Exrem avoiding consecutive buy/sell signals. Displaying only alternate buy and sell signals

Dear members,
I am facing an issue with exrem fucntion.
I am using 3 min or 5 min chart and i want to place an alert if the candle closes above or below the SMA 30 AND SMA 50
Attached the code below.
Its working fine in some cases only . The problem is the up and down arrows are showing alternatively. I understand that Exrem removes the excess signals but how i want it the code to behave is if the buy/sell logic is satisfied then corresponding arrows must be displayed and when the buy/sell logic fails and again the same buy/sell logic appears the arrows should appear.

Logic

If ( MaCondup = 1 and MaConddn = 0 ) then buy and remove excess signals
If ( MaCondup = 0 and MaConddn = 0 ) then reset previously used exrem (Not sure how to implement this )
If ( MaCondup = 0 and MaConddn = 1 ) then sell and remove excess signals
If ( MaCondup = 0 and MaConddn = 0 ) then reset previously used exrem (Not sure how to implement this )

by this way once i get a buy/sell signal and after some time price goes sideways and once again i get the same buy/sell signal the alert will be displayed.

1st image attached where sell condition is satisfied and sell arrow is displayed

image

2nd image attached where sell condition and buy condition is not satisfied

image

3rd image attached where sell condition is satisfied but the sell arrow is not displayed because of exrem

image

Any help would be greatly appreciated. Thanks in adavnce.

HaClose[0] = (Open[0]+High[0]+Low[0]+Close[0]) / 4;
HaOpen[0]  = (HaClose[0] + Open[0]) / 2;
HaHigh[0]  = Max( High[0], Max( HaClose[0], HaOpen[0] ) );
HaLow[0]   = Min( Low[0], Min( HaClose[0], HaOpen[0] ) );

for (i=1; i<BarCount; i++)
	{
	HaClose[i] = (Open[i]+High[i]+Low[i]+Close[i]) / 4;
	Haopen[i]  = (HaClose[i-1] + HaOpen[i-1]) / 2; // Here is the problem when using Arrays: Haopen always uses its own previous value
	HaHigh[i]  = Max( High[i], Max( HaClose[i], HaOpen[i] ) );
	Halow[i]   = Min( Low[i], Min( HaClose[i], HaOpen[i] ) );
}
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "HA", colorBlack, styleCandle );

Title = Name()+" "+Date()+" Heikin Ashi -- HaOpen:"+NumToStr(HaOpen,1.2,True)+"
/ HaHigh:"+NumToStr(HaHigh,1.2,True)+" / HaLow:"+NumToStr(Halow,1.2,True)+"
HaClose:"+NumToStr(Haclose,1.2, True);

P = ParamField("Price field",-1);
MA30 = MA( P, 30);
MA50 = MA( P, 50);
MAcondup =  L > MA30  AND L > MA50  ;
MAconddn = MA30 > h  AND MA50 > h ;
printf (" \n Condition up = %g , \n Condition down = %g ", MaCondup,MaConddn );
MaCondup = ExRem( MaCondup , MaConddn );
MaConddn = ExRem( MaConddn , Macondup );
Buy = MaCondup AND Status("BarInRange");
Cover = Buy ;
Sell = MaConddn AND Status("BarInRange") ;
Short = Sell ;
printf (" \n Condition up = %g , \n Condition down = %g ", MaCondup,MaConddn );

dist = -15;
upcolor = colorBlue;
PlotShapes( MAcondup*shapeUpArrow, upcolor, 0, L-2, dist );
PlotShapes( MAcondup*shapeHollowUpArrow, colorLightYellow, 0, L-2, dist );
dncolor = colorBlue;
PlotShapes( MAconddn*shapeDownArrow, dncolor, 0, H+2, dist );
PlotShapes( MAconddn*shapeHollowDownArrow, colorLightYellow, 0, H+2, dist );

_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("MA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();