remove consecutive signals before the last one

hello

"exrem" removes excessive signals after the first one
I try to remove consecutive signals before the last one (and keep the inbar signal)
like in this example below
Is there an efficient way to do it ?

Thanks for your help
Emilie

DotDist = Param("---DotDistance",12,1,50,1);

	Hi = H>Ref(H,-1) ;			
	Lo = L<Ref(L,-1);
							
	b4lastHi = IIf(Hi AND Ref(Hi,-1),1,0);
	b4lastLo = IIf(Lo AND Ref(Lo,-1),1,0);				
			
	BGColor = colorGrey40; // my background color
		
	IIf(Hi,PlotShapes(shapesmallCircle*Hi,colorwhite,0,H,DotDist),0);			
	IIf(b4lastHi,PlotShapes(shapesmallCircle*b4lastHi,BGColor,0,Ref(H,-1),DotDist,-1),0);
				
	IIf(Lo,PlotShapes(shapesmallCircle*Lo,colorwhite,0,L,-DotDist),0);			
	IIf(b4lastLo,PlotShapes(shapesmallCircle*b4lastLo,BGColor,0,Ref(L,-1),-DotDist,-1),0);