StopLoss for EMA Crossover

How to add a 0.50% STOP LOSS to below EMA Crossover Code

<<_SECTION_BEGIN("EMA CROSSOVER");>>
<<SetChartOptions(0,chartShowArrows|chartShowDates);
<<(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) >><<{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));>>
<<SetBarFillColor( IIf(Open > Close, colorRed, colorGreen) ); >>
<<Plot( Close, "Price", IIf( Close > Open,colorGreen, colorRed ), styleCandle ) ;>>

<<Plot(EMA(Close,25),"25-EMA",colorOrange,styleLine);>>
<<Plot(EMA(Close,50),"50-EMA",colorBlueGrey,styleLine);>>

<<Buy = Cross(EMA(Close,25),EMA(Close,50));>>
<<Cover = Cross(EMA(Close,25),EMA(Close,50));>>
<<Short = Cross(EMA(Close,50),EMA(Close,25));>>
<<Sell = Cross(EMA(Close,50),EMA(Close,25));>>

<<PlotShapes(BuyshapeUpArrow,colorWhite,0,H,Offset=-40);>>
<<PlotShapes(Sell
shapeDownArrow,colorYellow,0,L,Offset=-40);>>

<<RequestTimedRefresh( 1,onlyvisible=False );>>
<<RequestTimedRefresh( 1,onlyvisible=False );>>

<<_SECTION_END();>>

@Siddhesh, next time you plan to post some code, please, use the mandatory code tags.

Just press </> button then paste or type your formula.

Also, be sure to remove all extraneous characters such as << and >> that you probably received by copying that code from some site.

Regarding the StopLoss it is enough to add the ApplyStop() function, even if using it with a 0.50% stop makes very little sense to me since the stop will probably be triggered too many times.

ApplyStop(stopTypeLoss, stopModePercent, 0.5);  // 0.50% may be too close  

I encourage you to study the documentation and to experiment the additional parameters.

5 Likes