High-Tight Flag (Power Play) Detection

Hello everyone,

If you are a Mark Minervini fan or even last year's US Investing Champion, Leif Soreide, you know they absolutely love high-tight flags, or what is also called a power play.

You also know I post stuff related to Mark's strategy quite often, as I'm a huge fan and been to his Master Trader Program, and am a Private Access member.

So what's the easiest way to detect high-tight flag or power play using Amibroker?

Well here's the code:

//HTF detection

// Loop backwards, set detection limit to 15 weeks (pole 8 weeks
// This finds the bar location of the highest value in the detection area
PHBar 	 = BarCount - HHVBars(H, 15*5);
PoleHigh = HHV(H, 15*5);
	
// Flag Low is the lowest price since PoleHigh
FlagLow = LLV(L, BarCount - PHBar);
	
// Pole Low is assumed to be < 8 weeks prior to PoleHigh
PoleLow = Ref(LLV(L, 40), -(BarCount - 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 BarCount - PHBar > 5;

It's pretty simple and the logic is like this if you assume you should only look back max 15 weeks:

  • The easiest part of the formation to find is the top of the pole. So I use HHV and HHVBars functions to find it
  • Now that I know where the high of the pole is, I can find the low of the flag by using LLV as a function of location of the pole-top
  • I can then find the bottom of the pole, by Ref-erencing the pole-top and checking its LLV of the past 8 weeks
  • Finally I can use this info to see if the pattern is indeed detected, be ensuring the pole represents a price increase of > 100%, the flag is not deeper than 25% and the flag has had some time to consolidate, 5 days. You can of course tune this to what you want for your purposes.

The reason to use LLV, HHV and HHVbars is so that we can keep it simple with matrix calculations (and you can use this to backtest the pattern's performance). Also the difference in price of the last eight weeks from pole bottom to pole top may be less than 100%. However the lowest price within that period can be between that period, representing a pole that increases > 100% in less than 8 weeks, which is still valid.

If you see any errors or improvements, please feel free to share!

Here are some patterns for this week that were detected:

$PENN
PENN

$ZM
AM

$TRIL
TRIL

$FBRX
FBRX

Example of a false positive:

$IMMU (bought out stock)
IMMU

Enjoy!
Mike

13 Likes

Not an error but redundant code parts related to use of BarCount there...

BarCount - BarCount is zero so you can just remove all BarCount calculation completely.

What I mean is (and I'm really not trying to be smart a.. but just trying to make it clearer):

BarCount - PHBar

which is this

BarCount - (BarCount - HHVBars(H, 15*5))

which is

BarCount - BarCount + HHVBars(H, 15*5)

which is just this

HHVBars(H, 15*5);

So...

//HTF detection

// Loop backwards, set detection limit to 15 weeks (pole 8 weeks
// This finds the bar location of the highest value in the detection area
PHBar 	 = HHVBars(H, 15*5);
PoleHigh = HHV(H, 15*5);
	
// 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, 40), -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;
7 Likes

If it is really meant prior to PoleHigh then you could modify to

// Pole Low is assumed to be < 8 weeks prior to PoleHigh
PoleLow = Ref(LLV(L, 40), -PHBar-1);

in order to shift one more bar back from PoleHigh bar.

since LLV includes current bar:

AFL Function Reference - LLV

Calculates the lowest value in the ARRAY over the preceding periods (periods includes the current day).

4 Likes

Absolutely, not sure why I missed that when I was cleaning up the code.

Thanks!

Although i think the top of the pole should be counted.... Won't make a big difference.

Thanks again for sharing Mike! I look forward to trying this out especially since this is one I have been looking at specifically adding to my normal analysis.

1 Like

Thanks for sharing Mike! Time to review the power play concept :smiley:

1 Like

I'd like to see if I can create some extra code to check the quality of the pole and flag, but meh, I can do that by eye for now. :slight_smile:

1 Like

Curious, is Pull Back buy the same as the Power Play?

Nope. Pullback buys are when stocks pivot but then come back in, usually for a couple days or so. You can buy more or start your first position when the price rises above the lowest candle of the pullback.

Power play is described above. You can buy a pullback within a power play if it occurs, of course.

4 Likes

Very interesting, thanks for sharing.

I remember having done some work on the high tight flag in the past... I am copying the code here for others to benefit as well... the logic is the same as what rocketPower posted but I remember one of the issues I have had is that the exploration returned so many one-shot-up stocks instead of nice and steady climb up in the pole...

I have not reviewed in a while but it still seems to work pretty well at finding high tight flags as well.


mainPer = 50 ; 

Bars = BarIndex();

Slope1 = LinearReg( C, mainPer/2 ) / LinRegIntercept( C, mainPer/2 );
Slope2 = LinearReg( C, mainPer	 ) / LinRegIntercept( C, mainPer   );
Slope3 = LinearReg( C, mainPer*2 ) / LinRegIntercept( C, mainPer*2 );

Correlation1 = Correlation( Bars, C, mainPer/2 );
Correlation2 = Correlation( Bars, C, mainPer   );
Correlation3 = Correlation( Bars, C, mainPer*2 );

minSlp = 1.80;
minCor = 0.60;

Check1 = Slope1 >= minSlp AND Correlation1 >= minCor;
Check2 = Slope2 >= minSlp AND Correlation2 >= minCor;
Check3 = Slope3 >= minSlp AND Correlation3 >= minCor;

Substitute = Ref( H, -Bars + 1 );

Avg1 = IIf( Bars <= mainPer/2 , Substitute, MA( C, mainPer/2 ) );
Avg2 = IIf( Bars <= mainPer   , Substitute, MA( C, mainPer   ) );
Avg3 = IIf( Bars <= mainPer*2 , Substitute, MA( C, mainPer*2 ) );

Line = Min( Avg1, Min( Avg2, Avg3 ) );

Pole_Trigger = Cross( C, Line );
Pole_Start = BarsSince( Pole_Trigger );
Pole_Low = ValueWhen( Pole_Trigger, L, 1 );

Flag_Start = Max( HHVBars( H + ATR( mainPer / 10 ), Pole_Start ), HHVBars( C + ATR( mainPer / 10 ), Pole_Start ) );
Flag_Top = Ref( H, -Flag_Start );
Flag_Low = Ref( C, -LLVBars( C, Flag_Start - 1 ) );

Flag_Support = Sum( C < MA( C, mainPer ), Flag_Start );
Pole_Check = Ref( Check1, -Flag_Start ) OR Ref( Check2, -Flag_Start ) OR Ref( Check3, -Flag_Start );

Pole_Depth = Flag_Top / Pole_Low;
Flag_Depth = Flag_Low / Flag_Top;

// flag footprint
// minimum 80% in the pole
// maximum 30% flag depth
// minimum 15 days in the pole
// minimum 5 days on the flag

Flag = Pole_Depth >= 1.8 AND Flag_Depth >= 0.7 AND Pole_Start >= 15 AND Flag_Start >= 5 AND Flag_Support == 0 AND Pole_Check == 1;

PlotShapes( Flag*shapeSmallCircle, colorBlue, 0, Low );

6 Likes

Nice! I've seen some well seasoned, successful traders play those HTFs whose pole was straight up, as long as it's not a buyout or merger, it can still work!

2 Likes

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