Hi All,
Below is the exploration formula. As per condition, I want to list stock if only 52 week high is made in the last 6 months. Can anyone please guide me on how do I write such condition in AFL. Thanks in advance.
//step 1- stock within 25% range of 52 weeks high;
ah= HHV(High, 52);
a1= ah*0.75;
a2= Close > a1;
//step 2- eliminate stock below 30;
b1= Close > 30;
//step 3- 200 MA rising for 3 months, manual;
m1= MA(Ref(Close, -60), 200);
m2= MA(Close, 200) > m1;
//step 4- 50 MA above 200;
c1= MA(Close, 50) > MA(Close, 200);
//step 5- Close above MA200;
d1= Close > MA(Close,200);
d2= Close > MA(Close, 50);
//step 6- 100% up from 52week low;
eL= LLV(Low, 260);
e1= eL*2;
e2= Close > e1;
//step 7- 52 week high within the last 6 month
Regards,
Sumit
1 Like
Welcome SUMITJAIN!
I see you know how to code, so I'll assume you know how to put everything together using AND/OR logic, and you just need the formula for step 7.
When running on daily bars, and assuming a 252-days trading year, I would write it like this:
HHV(High, 126) == HHV(High, 252)
In other words, if the highest value over 6 months (= 126 days) is the same as over 1 year (= 52 weeks = 252 days), the highest 52-week high happened in the last 6 months.
That leaves room for the same exact high to have happened before the 6-months lookback period. In other words, if you want the most recent high to be strictly higher than the one that happened before the 6-months lookback period, then the logic needs to be changed, like maybe comparing HHV(High, 126) with Ref(HHV(High, 126), -126).
2 Likes
Copy
HHV(High, 126) == HHV(High, 252)
Hi Sir,
Thanks for reply. Will it still list the stock if 52 week high suppose happened 4 months ago?
Thanks again.
Kind regards,
Sumit
Yes, it will work. Below is a more detailed explanation, I think it will help if you look and draw on a chart.
Let's label "Highest High in the most recent 6 months" as 6MHH, and "Highest High in the most recent 12 months" as 12MHH.
There are 3 cases:
- 6MHH < 12MHH: in this case the highest 52-week high happened in the distant past, more than 6 months away
- 6MHH > 12MHH: this cannot ever happen, since the most recent 6 months are always part of the most recent 12 months
- 6MHH == 12MHH: the highest 52-week high happened at least one time in the most recent 6 months (it might have happened also more than 6 months ago, but what we know is that it also happened in the most recent 6 months). This is the case where you would need more code if you want one only occurrence of the same high (it's rare, but it can happen to have the same high more than once)
1 Like
Thanks a ton,Sir
very helpful.