# How to find the Highest Price in a specified % Move

Hello,

I tried to code a Exploration scan using the following conditions

1. Calculate the lowest close for a stock in last 52 days.
2. Calculate percent change from lowest close
3. Find the highest price in the 100% move and only take stocks which are within 25% of that highest price
``````LowestPrice =LLV(C,52);
Change = (C/LowestPrice-1)*100 ;
``````

I am not understanding to frame the logic for the point No.3 above. How to find the Highest price in the 100% move from the LowestClose of 52 days.

I feel this is not correct HHV(Close,52) * 1.25 ?

It sounds like you are searching for High Tight Flags.... I think you find it here what you are looking for.

2 Likes

You can use the concept of internal bar strength, just applied to the pattern instead of a single bar.

(Close-Low) / (High-Low) > 0.75

...where the close is the current close, the low is the base of the flagpole and the high is the highest high of the pattern.

1 Like

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;

``````

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.

1 Like

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.

Thank you

``````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;
``````
1 Like

Is this what you are looking for?

``````//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

1 Like

Thank you @fxshrat and @paddy for the kind help.

Small correction

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).

2 Likes

Thank you for revisiting the post and updating the corrections.

Tough not the intention of the original post. Out of curiosity to learn may I know how to plot the values of LowestPrice, hh and Change on chart.

Thank you

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.