Buy when cross ma15 and reverse if end bar not wif same direction

I wanna make it Buy when High cross the ma15
and when the bar end , if the C>ma15 then do nth, if C<ma15 then reverse at next bar open
Short also same case when the ma15 cross L, then short
and when the bar end, if the C<ma15 then do nth, if C>ma15 then reverse at next bar open

I try to make it by the following code but the result is out of my expectation as in the pic
Any suggestion


Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

Buy=Cross(H,ma15) OR Ref(C,-1)>ma15;
Sell = Cross(ma15,L) OR Ref(C,-1)<ma15;
Short= Cross(ma15,L) OR Ref(C,-1)<ma15;
Cover=Cross(H,ma15) OR Ref(C,-1)>ma15;


PlotShapes(IIf(Short, shapedownarrow, shapeNone),Colorwhite, 0,H, Offset=-63);  
PlotShapes(IIf(Cover, shapehollowuptriangle, shapeNone),Colorwhite, 0,L, Offset=-45);  

PlotShapes(IIf(Buy, shapeuparrow, shapeNone),Colorwhite, 0,L, Offset=-45);  
PlotShapes(IIf(Sell, shapehollowdowntriangle, shapeNone),Colorwhite, 0,H, Offset=-63);  

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.