When XLP Diverges From Recent High And Low (Amibroker And Tradestation)

The strategy in plain English:

 

  1. Calculate an average of the H-L over the last 25 days.
  2. Calculate the (C-L)/(H-L) ratio every day (IBS).
  3. Calculate a band 2 times lower than the high over the last 25 days by using the average from point number 1 (β€œATR”).
  4. If XLP closes under the band in number 3, and point 2 (IBS) has a higher value than 0.4, then go long at the close.
  5. Exit when the close is higher than yesterday’s high.

 

Click here for the original article.

 

Amibroker code:

 

range=MA((H-L),25);
OddisHigh=HHV(H,25);
OddisBand=OddisHigh – (range*2);

Buy= Close<OddisBand AND ibs<0.4;
buyPrice= C;
Sell= C>Ref(H,-1);
sellPrice= Close ;

 

This strategy works for short with these rules:

 

range=MA((H-L),50);

OddisLow=llV(L,10);

OddisBand=Oddislow + (range*2.9);

Short= Close>OddisBand AND ibs>0.85;

shortPrice= C;

Cover= C<Ref(C,-1); //exit when close is lower than yesterday’s close

coverPrice= Close ;

 

 

Tradestation code:

 

If c < (highest(h,25)-2*average((H-L),25)) And

IFF((H-L)<>0,((C-L))/(H-L),1) < 0.35

then buy (“When XLP diverg”) this bar at close;

If c>h[1] then Sell this bar at c;

 

Disclosure: We are not financial advisors. Please do your own due diligence and investment research or consult a financial professional. All articles are our opinions – they are not suggestions to buy or sell any securities.