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
$ZM
$TRIL
$FBRX
Example of a false positive:
$IMMU (bought out stock)
Enjoy!
Mike