Sell (Exit/SL) criteria is not working

Dear All,

I have been struggling to figure out the issue as why one of the sell criteria in my code isnt functioning (although simple criteria). I am posting the code as well as the related snapshot. The idea is to "Buy" when price bounces from 52 week low (entry above high of Signal bar) and exit when 52 week high comes (which is working fine) or when price closes below the Low of "bottom" signal bar ( SL - which isnt working).

Code is as follows:

pds=252;
DonchianUpper =HHV(Ref(H,-1),pds);
DonchianLower = LLV(Ref(L,-1),pds);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;
Lastweekvolume= HHV(Ref(V,-1),7);

Plot(DonchianUpper,"DU",colorGreen,styleThick);
Plot(DonchianMiddle,"DM",colorBlack,styleThick);
Plot(DonchianLower,"DL",colorRed,styleThick);

Bottom = Low <= DonchianLower ;
Bottomcandlelow= ValueWhen(Bottom,Low);
Bottomcandlehigh= ValueWhen(Bottom,High);

BarLimit = 20;

Buy= Close > Bottomcandlehigh AND BarsSince(Bottom) <= BarLimit;
Sell = Close <= Bottomcandlelow OR Close >= DonchianUpper;

Buy=ExRem(Buy,Sell);
Sell= ExRem(Sell,Buy);

PlotShapes(IIf(Sell, shapeDownArrowSell, shapeNone),colorBlack, 0,H, Offset=-55);
PlotShapes(IIf(Buy, shapeUpArrow
Buy, shapeNone),colorGreen, 0,L, Offset=-45);

Filter =1;
SetSortColumns(2) ;
SetOption("NoDefaultColumns", True);
AddTextColumn(Name(),"Name");
AddColumn( DateTime(), "Date", formatDateTime );
AddColumn(Bottomcandlelow,"Blow");
AddColumn(Bottomcandlehigh,"Bhigh");

image

@akumaar53,

As a long time member, you should have seen the notice to be a Verified member.

Please, search and follow the steps to get Verified (Search Verified or Verified badge).

Additionally, please use the Code Blocks ("</>") when posting code. That let's the other forum members who are interested in helping you out, to quickly and easily grab your code and test it out.

2 Likes

My account is verified long back, if i am not wrong. Please see, and guide if something else needed for the same from my end.

verified

Does the "User name at forum" match your User name here? It looks too short in the picture.

1 Like

License verified. Thanks for pointing out dear, since i am have multiple licenses...the username mismatch was there. Now rectified!!

@akumaar53,

I think you need to learn the Ref() command. I suspect that your Buy and Sell tests are comparing to the "current bar".

So try:

 Sell = Close <= Ref(Bottomcandlelow,-1)  OR Close >= Ref(DonchianUpper, -1);

Let us know if that helps.

2 Likes

Thank you so much @snoopy.pa30. Sometimes smallest of things we miss and it makes the complete difference. I am kind of embarrassed too...how i missed it. But always a learning and hence this forum comes to rescue.

Thanks you again