Signal generated when price cross high of first uptrend candle and vice versa Code

I have tried a lot but not succeeded.Condition is Buy signal should generated when high of first uptrend candle cross and sell signal should generated when low of first downtrend candle cross on lower.Filter of High+1 and Low-1.

_SECTION_BEGIN(“trend with pivot levels”);
uptrend= Signal(14)<MACD(12);
downtrend= Signal(14)>MACD(12);
SetBarFillColor( IIf( uptrend, colorGreen, colorRed ) );
Plot( C, “Price”, IIf( uptrend, colorGreen, colorRed ), styleCandle );
Buy= uptrend;
Sell=downtrend;
Cover=Buy;
Short=Sell;
Filter = Buy OR Sell;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );

_SECTION_END();

Thanx In Advance

For the above condition you can check Trend Alert indicator available in expert advisor page from below given link