Your code is incomplete and no within code tags.
m = MA( Close, 20 );
Buy = Cross( Close, m );
Sell = Cross( m, Close );
Plot( C, "Price", colorDefault, styleBar );
function sum_since(cond, array) {
return SumSince(cond,array)+ValueWhen(cond,array);
}
NOT_visible = Ref(Status("barvisible"),-1) == 0;
first_buy = Buy AND sum_since(NOT_visible,Buy)==1;
first_sell = Sell AND sum_since(NOT_visible,Sell)==1;
PlotShapes(IIf(first_buy, shapeSquare, IIf(Buy,shapeUpArrow, shapeNone)), colorGreen, 0, L );
PlotShapes(IIf(first_sell, shapeSquare, IIf(Sell,shapeDownArrow, shapeNone)) , colorRed, 0, H );
Or using Cum and reducing bars.
period = 20;
m = MA( Close, period );
Buy = Cross( Close, m );
Sell = Cross( m, Close );
Plot( C, "Price", colorDefault, styleBar );
first_buy = Buy AND Cum(Buy)==1;
first_sell = Sell AND Cum(Sell)==1;
PlotShapes(IIf(first_buy, shapeSquare, IIf(Buy,shapeUpArrow, shapeNone)), colorGreen, 0, L );
PlotShapes(IIf(first_sell, shapeSquare, IIf(Sell,shapeDownArrow, shapeNone)), colorRed, 0, H );
SetBarsRequired(period);