Thank you for pointing me towards the post of High-Tight Flag referring to the same post and code made by fxshrat . I tried the following
//HTF detection
//https://forum.amibroker.com/t/high-tight-flag-power-play-detection/21895/2
//fxshrat
LowestPrice =LLV(C,52);
Change = (C/LowestPrice-1)*100 ;
// Loop backwards, set detection limit to 52 Days
// This finds the bar location of the highest value in the detection area
PHBar = HHVBars(H, 52);
PoleHigh = HHV(H, 52);
// Flag Low is the lowest price since PoleHigh
FlagLow = LLV(L, PHBar);
// Pole Low is assumed to be < 8 weeks prior to PoleHigh
PoleLow = Ref(LLV(L, 52), -PHBar);
// Detect HTF if Pole is > 100% and flag is at least 5 bars long and flag % change is < 25%
HTF = PoleHigh/PoleLow > 2 AND FlagLow/PoleHigh > 0.75 AND PHBar > 5;
Filter= HTF;
AddColumn (LowestPrice ,"LP-52",1.2);
Is this code correct Identifying the 100% move and only take stocks which are within 25% of that highest price?
I have no idea what you're looking for. You should describe for what kind of pattern you have in mind or trying to reach.
This will search for the absolute low PRIOR to the High within 52days which looks back for another 52days. So in total your range can be up to 104days.
// Pole Low is assumed to be < 8 weeks prior to PoleHigh
PoleLow = Ref(LLV(L, 52), -PHBar);
"Change" is unused in this code and can be deleted.
I am sorry, if my explanation is not clear. This is what I am trying to achieve
1.Calculate the lowest close for a stock in last 52 days. If a stock has less than 52 days data calculate lowest close for those many days.
2.Calculate percent change from lowest close of 52 days and select stocks which had 100% plus growth.
3.Find the highest price in the 100% move and only take stocks which are within 25% of that highest price.
I want to code the above so that I can have stocks which had significant move of 100% or more from the low of 52 days and are as of today within 25% of the high during the move.
dt = DateTime();
period = 52;
ll_bars = Ref(LLVBars(C,period),-1);
LowestPrice = Ref(L,-ll_bars);
dt_ll = Ref(dt,-ll_bars);
Change = (C/LowestPrice-1)*100;
hh = Ref(HighestSince(dt == dt_ll, C), -1);
cond = C >= 2*LowestPrice AND C > hh/1.25 AND C < hh;
Yeah or using HHV
period = 52;
ll_bars = Ref(LLVBars(C,period),-1);
LowestPrice = Ref(L,-ll_bars);
Change = (C/LowestPrice-1)*100;
hh = Ref(HHV(C,ll_bars), -1);
cond = C >= 2*LowestPrice AND C > hh/1.25 AND C < hh;
//HTF detection
//https://forum.amibroker.com/t/high-tight-flag-power-play-detection/21895/2
//fxshrat
// Loop backwards, set detection limit to 52 Days
// This finds the bar location of the highest value in the detection area
// maybe you want the lowest Low and not the lowest Close?
PLBar = LLVBars(C, 52);
PoleLow = LLV(C, 52);
// Look for the highest High after the lowest Low/Close within 52days
PoleHigh = HHV(H, PLBar);
// Close is within 25% from the PoleHigh AND move from low to high > 100%
Filter = C > PoleHigh*0.75 AND PoleHigh/PoleLow > 2;
@fxshrat was some seconds fast than me anyway good luck trading
from LowestPrice = Ref(L,-ll_bars);
to LowestPrice = Ref(C,-ll_bars-1);
and
from hh = Ref(HHV(C,ll_bars),-1);
to hh = Ref(HHV(C,ll_bars+1),-1);
since ll_bars is zero based and count starts from "current" bar.
So by adding 1 we catch hh that occurred right after LLV bar.
If you want to include HHV occurrences at LLV bar then you would have to change to +2 in hh line.
So,
period = 52;
ll_bars = Ref(LLVBars(C,period),-1);
LowestPrice = Ref(C,-ll_bars-1);
Change = (C/LowestPrice-1)*100;
hh = Ref(HHV(C,ll_bars+1),-1);
cond = C >= 2*LowestPrice AND C > hh/1.25 AND C < hh;
Also I have used hh/1.25 (as before) if you mean that hh shall be 25% away from "current" Close. If you mean that Close shall be max. 25% smaller than hh then use hh*0.75. So then hh would be 33.3% away from "current" Close (if being exactly there).