Al Brooks Style H1 / H2 or L1 / L2 indicator

armybender

Active member
Hi. Does anyone have an existing indicator, or have an idea how to program an indicator to display a "H1", "H2", "L1", or "L2" above or below bars in the style of Al Brooks' definitions?

It can get a little complex, because there are rules for "resetting the count", like double tops/bottoms, and new swing highs/lows, but even something simple like resetting the count after a major swing would be helpful.

Picture below.

6u0OCSG.jpg
 
Solution
Hi. Does anyone have an existing indicator, or have an idea how to program an indicator to display a "H1", "H2", "L1", or "L2" above or below bars in the style of Al Brooks' definitions?

It can get a little complex, because there are rules for "resetting the count", like double tops/bottoms, and new swing highs/lows, but even something simple like resetting the count after a major swing would be helpful.
Here is an example of how to keep track of the iteration and reset the count in certain cases, such as after a new swing low.
https://usethinkscript.com/threads/zigzag-price-price-change-bar-count-change-for-thinkorswim.9332/

Here is how to search the forum for more examples:...
Hi. Does anyone have an existing indicator, or have an idea how to program an indicator to display a "H1", "H2", "L1", or "L2" above or below bars in the style of Al Brooks' definitions?

It can get a little complex, because there are rules for "resetting the count", like double tops/bottoms, and new swing highs/lows, but even something simple like resetting the count after a major swing would be helpful.
Here is an example of how to keep track of the iteration and reset the count in certain cases, such as after a new swing low.
https://usethinkscript.com/threads/zigzag-price-price-change-bar-count-change-for-thinkorswim.9332/

Here is how to search the forum for more examples:
https://usethinkscript.com/threads/search-the-forum.12626/
 
Solution
Hi,

Can someone who's really skilled at Thinkscript create an indicator to label setups like Al Brooks describes? I believe there's an EasyLanguage version of it out there, or a NinjaTrader version, but I can't seem to find the code online to replicate it.

I've tried several times to create an indicator to label H1 / H2 and L1 / L2 setups as Al brooks describes. I've come close, but get into trouble with things like double tops / bottoms.

Here are the rules. I'll discuss "H" setups (new attempt to reverse in a downtrend), although they apply for "L" setups, just in the opposite direction. The study should handle both.

1. From a high point, when the price moves down, the first attempt to go higher is labeled a H1.
2. As the price continues downward below that (i.e. a series of lower swing lows) each subsequent attempt to reverse is labeled H2... H3... and so on.
3. The reversal attempt only needs to be a single tick above (H > H[1]) but it can be many ticks too.
4. A double top of swing highs "resets" the count back to zero.
5. A higher high of a swing hi also "resets" the count back to zero.
6. Because these patterns can happen in just a few bars, it's important to not make it a "swing" style indicator with a look forward / look back process - that would very clearly not work when a H2 setup occurs within 4 bars. This is one of the major challenges I've run into.

Here's a picture below with some of the setups labeled. My thought was to have it display numbers below with the count (H1, H2, H3...)


1690290143992.png


Thanks!
 
Hi,

Can someone who's really skilled at Thinkscript create an indicator to label setups like Al Brooks describes? I believe there's an EasyLanguage version of it out there, or a NinjaTrader version, but I can't seem to find the code online to replicate it.

I've tried several times to create an indicator to label H1 / H2 and L1 / L2 setups as Al brooks describes. I've come close, but get into trouble with things like double tops / bottoms.

Here are the rules. I'll discuss "H" setups (new attempt to reverse in a downtrend), although they apply for "L" setups, just in the opposite direction. The study should handle both.

1. From a high point, when the price moves down, the first attempt to go higher is labeled a H1.
2. As the price continues downward below that (i.e. a series of lower swing lows) each subsequent attempt to reverse is labeled H2... H3... and so on.
3. The reversal attempt only needs to be a single tick above (H > H[1]) but it can be many ticks too.
4. A double top of swing highs "resets" the count back to zero.
5. A higher high of a swing hi also "resets" the count back to zero.
6. Because these patterns can happen in just a few bars, it's important to not make it a "swing" style indicator with a look forward / look back process - that would very clearly not work when a H2 setup occurs within 4 bars. This is one of the major challenges I've run into.

Here's a picture below with some of the setups labeled. My thought was to have it display numbers below with the count (H1, H2, H3...)

here are some comments and questions,
i just say things like i see it. read it as factual, with no emotion. i'm just trying to ask questions that will help me (and others) understand your request.
please rewrite your rules after reading this.

it seems you want to find big and small, peaks and valleys. ( or maybe just big ones, i'm a little confused)
you don't mention a price parameter(open,high,low,close) very often, so i'm not sure what i am supposed to compare to what.

1. From a high point, when the price moves down, the first attempt to go higher is labeled a H1.
high point of what? close? , high ? low?
what is attemping to go higher than what? close and high? close and close?
why are your H labels pointing at the bar with the lowest low and not the bar after it that has a higher high? which bar do you want the bubble on?


2. As the price continues downward below that (i.e. a series of lower swing lows) each subsequent attempt to reverse is labeled H2... H3... and so on.
below what? the low of the higher high?
what is a lower swing lows? just say lower low
how many lower lows have to happen for a low to be considered a possible H ( a valley)
so look for small peaks and valleys... what defines them?


3. The reversal attempt only needs to be a single tick above (H > H[1]) but it can be many ticks too.
what is above what? close > high[1]? close > close[1]? high > high[1]?


4. A double top of swing highs "resets" the count back to zero.
what is a swing high? is that a big peak or a small peak? a higher high, within x bars before and after it? swing is a confusing word to me, it doesn't tell me anything.
a double top(words) and a higher top(in picture) are 2 different things. which do you want. a double implies 2 peaks in a row, 1 not nesesarily higher/lower then the previous one.


5. A higher high of a swing hi also "resets" the count back to zero.
doesn't rule #4, 2 peaks, make #5 unessesary? have to have 2 peaks for one to be higher than the previous one.


6. Because these patterns can happen in just a few bars, it's important to not make it a "swing" style indicator with a look forward / look back process - that would very clearly not work when a H2 setup occurs within 4 bars. This is one of the major challenges I've run into.
so what is the range of bars you want to look back and forward, for big peaks ( and small peaks)?


i think some counting formulas can be created to do what you want. just need to clarify the rules.
 
@halcyonguy really good questions. Thanks for asking. I'll try to clarify everything.

I get that this is really complex - it took me a while to understand. In fact, Al dedicates an entire chapter in his book to describing it, and it gets really nuanced.

Nearly everything I'm talking about is based on single bars, so when I say "above" or "below" I'm almost always talking about above or below a single bar.

Swings are really just a "push" up from a H1/H2/etc. or a push down from a L1/L2/etc.

"As the price continues downward..." means just moving below a place where an H was created.

This is super complex to describe, so I've created an image to try to illustrate these concepts. I've tried to address every possible situation in 32 bars. I hope my explanation of the image makes it clear.

I've also attached the Excel sheet I used to create the bars in case you want to ask about a specific situation you could always illustrate it. I use ALT + dragging the bars to get them to snap to the cells.

Bar # 10 is an H1 because the next bar ticks above it by 1 tick. Bar 10 is labeled as the H1 though - not bar 11. We want to mark the low point for Hs - high point for Ls.

Bar 14 is an H2 because it has a low that is LOWER than bar 10 and because bar 15 ticks above it.

Bar 11 is a L1 because bar 12 ticks below it, but bar 16 is NOT an L2, it is an L1 because it made a lower low below bar bar 10 (the lowest "swing point" that preceded bar 11's L1.

In other words, Hs form as the price progresses downwards - Ls form as the price progresses upwards.

Bars 18 and 21 could be H1 or NA and H2 or H3 because it contemplates an option to reset the count on a DB / DT.

Additionally, had bar 18's low been 1 tick higher, it would also not count as an H3 because it did not tick lower than bar 14 (the H2). Hs must move progressively lower.

As far as resetting the count, bar 24 ticks above the "push" up from bar 14, so it can no longer be a higher H count. It resets the count. Some people consider a DT as a higher high, so they say it resets the count. In that way, bar 18 could either be nothing (since it doesn't tick below bar 14) or an H1 (if we reset the count on the DT at bar 16).


1691519857511.png
 

Attachments

  • Bars.xlsx
    30.3 KB · Views: 188
@halcyonguy

I got it! Or, at least very close. The only thing I'm not able to get due to circular references is that it's currently looking at a bull signal bar (isBullSB) or bear signal bar (isBearSB) for the low, so I am not able to detect if the H or L setup occurs below the prior setup, and only if it occurs below a prior bull or bear signal bar.

Wondering if you have any thoughts on this.


Ruby:
# DESCRIPTION
# This study plots H1, H2, etc. and L1, L2, etc. labels above or below
# those signal bars based on Al Brooks' description of the seupts.


# DECLARATIONS
declare upper;


#USER INPUTS
input resetCountOnDTorDB = yes;
input barsBack = 10;


# DEFINITIONS AND CALCULATIONS
## Variable List
def isFlatTopSBEligible;
def isBullSB;
def lastBullSBLow;
def isHBar;
def lastHBarLow;
def isPushUp;
def lastPushUp;
def resetHCount;
def isHCountStillReset;
def hCount;

def isFlatBottomSBEligible;
def isBearSB;
def lastBearSBHigh;
def isLBar;
def lastLBarHigh;
def isPushDown;
def lastPushDown;
def resetLCount;
def isLCountStillReset;
def lCount;


## Standard variable calculations
### H Counting
isFlatTopSBEligible =
    fold hFold = 1 to barsBack
    with dt = Double.NaN
    while IsNaN(dt)
    do
    if GetValue(high, hFold) == high then
        Double.NaN
    else if GetValue(high, hFold) > high then
        yes
    else
        no;

isBullSB = (high[1] > high and high[-1] > high)                                 #Standard bull SB
            or (isFlatTopSBEligible and high[-1] > high);                       #DT to the left

lastBullSBLow = if isBullSB then low else lastBullSBLow[1];

isHBar = (low < lastBullSBLow[1] and isBullSB) or (isBullSB and isHCountStillReset);

lastHBarLow = CompoundValue(1, if isHBar then low else lastHBarLow[1], low);

isPushUp = if isHBar then yes else if isPushUp[1] and high >= high[1] then yes else no;

lastPushUp = if isPushUp[1] and !isPushUp then high[1]
             else if high > lastPushUp[1] then high
             else lastPushUp[1];

resetHCount = high > lastPushUp[1]
              or ( resetCountOnDTorDB and high == lastPushUp[1] );

isHCountStillReset = if !isBullSB and resetHCount then yes else isHCountStillReset[1];

hCount = CompoundValue(1,
         if isHBar and !resetHCount then hCount[1] + 1
         else if resetHCount then 0
         else hCount[1]
         , 0);

### L Counting
isFlatBottomSBEligible =
    fold lFold = 1 to barsBack
    with db = Double.NaN
    while IsNaN(db)
    do
    if GetValue(low, lFold) == low then
        Double.NaN
    else if GetValue(low, lFold) < low then
        yes
    else
        no;

isBearSB = (low[1] < low and low[-1] < low)                                 #Standard bear SB
            or (isFlatBottomSBEligible and low[-1] < low);                        #Db to the left

lastBearSBHigh = if isBearSB then high else lastBearSBHigh[1];

isLBar = (high > lastBearSBHigh[1] and isBearSB) or (isBearSB and isLCountStillReset);

lastLBarHigh = CompoundValue(1, if isLBar then high else lastLBarHigh[1], high);

isPushDown = if isLBar then yes else if isPushDown[1] and low <= low[1] then yes else no;

lastPushDown = if isPushDown[1] and !isPushDown then low[1]
             else if low < lastPushDown[1] then low
             else lastPushDown[1];

resetLCount = low < lastPushDown[1]
              or ( resetCountOnDTorDB and low == lastPushDown[1] );

isLCountStillReset = if !isBearSB and resetLCount then yes else isLCountStillReset[1];

lCount = CompoundValue(1,
         if isLBar and !resetLCount then lCount[1] + 1
         else if resetLCount then 0
         else lCount[1]
         , 0);


#PLOTS
plot hSetup = if hCount <> hCount[1] and hCount <> 0 then hCount else Double.NaN;
plot lSetup = if lCount <> lCount[1] and lCount <> 0 then lCount else Double.NaN;


#GLOBAL COLOR DEFINITIONS
DefineGlobalColor("Blue" , CreateColor(33, 150, 243));
DefineGlobalColor("Green", CreateColor(0, 155, 0));
DefineGlobalColor("Red", CreateColor(225, 105, 105));
DefineGlobalColor("Gray", CreateColor(181, 181, 181));
DefineGlobalColor("White", CreateColor(255, 255, 255));


#FORMATTING
hSetup.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
hSetup.SetDefaultColor(GlobalColor("Green"));
hSetup.SetLineWeight(2);
hSetup.HideBubble();

lSetup.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
lSetup.SetDefaultColor(GlobalColor("Red"));
lSetup.SetLineWeight(2);
lSetup.HideBubble();
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
410 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top