I plan to create trading system with stop loss rule as follow:
If buy price less than DonchianLower30 than use DonchianLower30 as stop loss level, unless use DonchianLower20.
DonchianUpper20 =HHV(Ref(H,-1),20);
DonchianLower20 = LLV(Ref(L,-1),20);
DonchianUpper30 =HHV(Ref(H,-1),30);
DonchianLower30 = LLV(Ref(L,-1),30);
Plot(DonchianUpper20,"DU",colorBlue,styleLine);
Plot(DonchianLower20,"DL",colorBlue,styleLine);
Plot(DonchianUpper30,"DU",colorRed,styleLine);
Plot(DonchianLower30,"DL",colorRed,styleLine);
Buy = H > DonchianUpper20;
sellpoint = IIf(BuyPrice < DonchianLower30, DonchianLower30, DonchianLower20);
Sell = L < sellpoint;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0, L, Offset=-15);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed, 0, L, Offset=-15);
On picture above, sell signal souldn't occur yet because buy price is less than DonchianLower30.
How to fix the code?