Create HH/HL indicator

ShoNuff

New member
Tradingvew has a nice HH/HL indicator. I don't see 1 in TOS. Is it possible to create 1 similar.

https://www.tradingview.com/script/bXic0E3l-Market-Structure-By-Leviathan/
1685970045981.png
 

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

I use it in conjunction with price action and RSI
If SleepyZ's suggestion above isn't what you're looking for, perhaps this adaptation of a Mobius indicator could be a start for you:

Code:
# Mobius
# Mobius on My Trade
# High_Low_Pivots(n value below 10) (Swing High Swing Low n value +21)
# V001.06.2012
# modified by vollermist in 2023, includes HH,LH,HL,LL bubbles
#input bias = {default long, short};
input n = 9;
def decimal_places = 2; #input decimal_places = 2 for stocks; #default 5 for forex etc.
input showPricesHL = yes;
input ShowLines = yes;
input showBubblesHL = yes;

def o = open;
def h = high;
def l = low;
def c = close;
def nan = Double.NaN;


def bar1 = BarNumber();
def ph;
def pl;
def isH = fold i = 1 
             to n + 1 
             with p = 1
             while p 
             do h > GetValue(h, -i);
ph = if (bar1 > n 
            and h == Highest(h, n) 
            and isH) 
            then RoundUp(h,decimal_places) 
            else Double.NaN;
def isL = fold j = 1 
            to n + 1 
            with q = 1
            while q 
            do l < GetValue(low, -j);
pl = if (bar1 > n 
            and l == Lowest(l, n) 
            and isL) 
            then RoundDown(l,decimal_places) 
            else Double.NaN;
rec phl = if !IsNaN(ph) 
             then RoundUp(ph,decimal_places) 
             else phl[1];
rec pll = if !IsNaN(pl) 
             then RoundDown(pl,decimal_places)
             else pll[1];

def pivotH = if showPricesHL then ph else nan;
plot pivotHigh = if showPricesHL then pivotH else nan;
pivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotHigh.SetDefaultColor(CreateColor(255,0,0));

plot pivotHighLine = if phl > 0 
                       then phl 
                       else Double.NaN;
pivotHighLine.SetHiding(!ShowLines);
pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotHighLine.SetDefaultColor(CreateColor(255,0,0));

plot pivotLow = if showPricesHL then pl else nan;
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetDefaultColor(CreateColor(0,255,0));

plot pivotLowLine = if pll > 0 
                      then pll 
                      else Double.NaN;
pivotLowLine.SetHiding(!ShowLines);
pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotLowLine.SetDefaultColor(CreateColor(0,255,0));
##############################################################
### Additions by vollermist

def unitriskA = pivotHighLine - pivotLow;
def unitriskB = pivotHigh - pivotLowLine;
def unitriskC = pivotHighLine - pivotLowLine;

def unitrisk = AbsValue(if !IsNaN(unitriskA) then unitriskA else if !IsNaN(unitriskB) then unitriskB else unitriskC);

############################
########## Bubbles #########
############################
def barnow = IsNaN(close[-1]) and !IsNaN(close);
def bubbleoffset = 0.01;

######################################
### HH, LH, HL, LL bubbles

def pHigh = GetValue(if !IsNaN(pivotHigh) then pivotHighLine[1] else pHigh[1], 0);
def pLow = GetValue(if !IsNaN(pivotLow) then pivotLowLine[1] else pLow[1], 0);
def HH = pivotHigh > pHigh;
def LH = pivotHigh < pHigh;
def HL = pivotLow > pLow;
def LL = pivotLow < pLow;

AddChartBubble(showBubblesHL and HH, text = "HH", "price location" = high + bubbleoffset, color = Color.LIME, yes);

AddChartBubble(showBubblesHL and LH, text = "LH", "price location" = high + bubbleoffset, color = Color.PINK, yes);

AddChartBubble(showBubblesHL and HL, text = "HL", "price location" = low - bubbleoffset, color = Color.LIGHT_GREEN, no);

AddChartBubble(showBubblesHL and LL, text = "LL", "price location" = low - bubbleoffset, color = Color.LIGHT_RED, no);
 
If SleepyZ's suggestion above isn't what you're looking for, perhaps this adaptation of a Mobius indicator could be a start for you:

Code:
# Mobius
# Mobius on My Trade
# High_Low_Pivots(n value below 10) (Swing High Swing Low n value +21)
# V001.06.2012
# modified by vollermist in 2023, includes HH,LH,HL,LL bubbles
#input bias = {default long, short};
input n = 9;
def decimal_places = 2; #input decimal_places = 2 for stocks; #default 5 for forex etc.
input showPricesHL = yes;
input ShowLines = yes;
input showBubblesHL = yes;

def o = open;
def h = high;
def l = low;
def c = close;
def nan = Double.NaN;


def bar1 = BarNumber();
def ph;
def pl;
def isH = fold i = 1
             to n + 1
             with p = 1
             while p
             do h > GetValue(h, -i);
ph = if (bar1 > n
            and h == Highest(h, n)
            and isH)
            then RoundUp(h,decimal_places)
            else Double.NaN;
def isL = fold j = 1
            to n + 1
            with q = 1
            while q
            do l < GetValue(low, -j);
pl = if (bar1 > n
            and l == Lowest(l, n)
            and isL)
            then RoundDown(l,decimal_places)
            else Double.NaN;
rec phl = if !IsNaN(ph)
             then RoundUp(ph,decimal_places)
             else phl[1];
rec pll = if !IsNaN(pl)
             then RoundDown(pl,decimal_places)
             else pll[1];

def pivotH = if showPricesHL then ph else nan;
plot pivotHigh = if showPricesHL then pivotH else nan;
pivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotHigh.SetDefaultColor(CreateColor(255,0,0));

plot pivotHighLine = if phl > 0
                       then phl
                       else Double.NaN;
pivotHighLine.SetHiding(!ShowLines);
pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotHighLine.SetDefaultColor(CreateColor(255,0,0));

plot pivotLow = if showPricesHL then pl else nan;
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetDefaultColor(CreateColor(0,255,0));

plot pivotLowLine = if pll > 0
                      then pll
                      else Double.NaN;
pivotLowLine.SetHiding(!ShowLines);
pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotLowLine.SetDefaultColor(CreateColor(0,255,0));
##############################################################
### Additions by vollermist

def unitriskA = pivotHighLine - pivotLow;
def unitriskB = pivotHigh - pivotLowLine;
def unitriskC = pivotHighLine - pivotLowLine;

def unitrisk = AbsValue(if !IsNaN(unitriskA) then unitriskA else if !IsNaN(unitriskB) then unitriskB else unitriskC);

############################
########## Bubbles #########
############################
def barnow = IsNaN(close[-1]) and !IsNaN(close);
def bubbleoffset = 0.01;

######################################
### HH, LH, HL, LL bubbles

def pHigh = GetValue(if !IsNaN(pivotHigh) then pivotHighLine[1] else pHigh[1], 0);
def pLow = GetValue(if !IsNaN(pivotLow) then pivotLowLine[1] else pLow[1], 0);
def HH = pivotHigh > pHigh;
def LH = pivotHigh < pHigh;
def HL = pivotLow > pLow;
def LL = pivotLow < pLow;

AddChartBubble(showBubblesHL and HH, text = "HH", "price location" = high + bubbleoffset, color = Color.LIME, yes);

AddChartBubble(showBubblesHL and LH, text = "LH", "price location" = high + bubbleoffset, color = Color.PINK, yes);

AddChartBubble(showBubblesHL and HL, text = "HL", "price location" = low - bubbleoffset, color = Color.LIGHT_GREEN, no);

AddChartBubble(showBubblesHL and LL, text = "LL", "price location" = low - bubbleoffset, color = Color.LIGHT_RED, no);
This is the best one I received its spot on. Is it possible to create a scanner that look at the most recent swing high or low and retrace certain percent?

Also is it possible to add the zig/zag lines to the script
1696425472253.png
 
Last edited by a moderator:
Glad my additions to Mobius code helped. I'm just a beginner picking up tidbits of knowledge to fill my specific needs. I'm sure that there are coders out there that can help you. I'm just not close to that level yet.
This is the best one I received its spot on. Is it possible to create a scanner that look at the most recent swing high or low and retrace certain percent?

Also is it possible to add the zig/zag lines to the script View attachment 19860
 
Last edited:
Glad my additions to Mobius code helped. I'm just a beginner picking up tidbits of knowledge to fill my specific needs. I'm sure that there are coders out there that can help you. I'm just not close to that level yet.
@vollermist have you noticed you need to refresh to see the higher highs and lower lows using this code? I didn't notice it until today 11/1/23 when a higher high didn't get plotted so I refreshed and there it was 😕

If SleepyZ's suggestion above isn't what you're looking for, perhaps this adaptation of a Mobius indicator could be a start for you:

Code:
# Mobius
# Mobius on My Trade
# High_Low_Pivots(n value below 10) (Swing High Swing Low n value +21)
# V001.06.2012
# modified by vollermist in 2023, includes HH,LH,HL,LL bubbles
#input bias = {default long, short};
input n = 9;
def decimal_places = 2; #input decimal_places = 2 for stocks; #default 5 for forex etc.
input showPricesHL = yes;
input ShowLines = yes;
input showBubblesHL = yes;

def o = open;
def h = high;
def l = low;
def c = close;
def nan = Double.NaN;


def bar1 = BarNumber();
def ph;
def pl;
def isH = fold i = 1
             to n + 1
             with p = 1
             while p
             do h > GetValue(h, -i);
ph = if (bar1 > n
            and h == Highest(h, n)
            and isH)
            then RoundUp(h,decimal_places)
            else Double.NaN;
def isL = fold j = 1
            to n + 1
            with q = 1
            while q
            do l < GetValue(low, -j);
pl = if (bar1 > n
            and l == Lowest(l, n)
            and isL)
            then RoundDown(l,decimal_places)
            else Double.NaN;
rec phl = if !IsNaN(ph)
             then RoundUp(ph,decimal_places)
             else phl[1];
rec pll = if !IsNaN(pl)
             then RoundDown(pl,decimal_places)
             else pll[1];

def pivotH = if showPricesHL then ph else nan;
plot pivotHigh = if showPricesHL then pivotH else nan;
pivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotHigh.SetDefaultColor(CreateColor(255,0,0));

plot pivotHighLine = if phl > 0
                       then phl
                       else Double.NaN;
pivotHighLine.SetHiding(!ShowLines);
pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotHighLine.SetDefaultColor(CreateColor(255,0,0));

plot pivotLow = if showPricesHL then pl else nan;
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetDefaultColor(CreateColor(0,255,0));

plot pivotLowLine = if pll > 0
                      then pll
                      else Double.NaN;
pivotLowLine.SetHiding(!ShowLines);
pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotLowLine.SetDefaultColor(CreateColor(0,255,0));
##############################################################
### Additions by vollermist

def unitriskA = pivotHighLine - pivotLow;
def unitriskB = pivotHigh - pivotLowLine;
def unitriskC = pivotHighLine - pivotLowLine;

def unitrisk = AbsValue(if !IsNaN(unitriskA) then unitriskA else if !IsNaN(unitriskB) then unitriskB else unitriskC);

############################
########## Bubbles #########
############################
def barnow = IsNaN(close[-1]) and !IsNaN(close);
def bubbleoffset = 0.01;

######################################
### HH, LH, HL, LL bubbles

def pHigh = GetValue(if !IsNaN(pivotHigh) then pivotHighLine[1] else pHigh[1], 0);
def pLow = GetValue(if !IsNaN(pivotLow) then pivotLowLine[1] else pLow[1], 0);
def HH = pivotHigh > pHigh;
def LH = pivotHigh < pHigh;
def HL = pivotLow > pLow;
def LL = pivotLow < pLow;

AddChartBubble(showBubblesHL and HH, text = "HH", "price location" = high + bubbleoffset, color = Color.LIME, yes);

AddChartBubble(showBubblesHL and LH, text = "LH", "price location" = high + bubbleoffset, color = Color.PINK, yes);

AddChartBubble(showBubblesHL and HL, text = "HL", "price location" = low - bubbleoffset, color = Color.LIGHT_GREEN, no);

AddChartBubble(showBubblesHL and LL, text = "LL", "price location" = low - bubbleoffset, color = Color.LIGHT_RED, no);
@SleepyZ @MerryDay any Idea why when using this indicator it needs to be refreshed in order to see the recent swings instead of it repainting them? I like this and I feel it provides an edge without being to busy but you have to always refresh after you see a swing high or low. PLEASE HELP
 
There have been a rash of posts recently, referencing that member's charts are not updating in real time.

You will need to contact ToS Support to address the issue.
https://usethinkscript.com/threads/how-to-contact-tos-support-for-thinkorswim.11520/

They generally do not address problems with custom studies, but it seems to be more of a chart updating issue. Which Schwab needs to be made aware of.

IMPORTANT: All of you experiencing this situation MUST report the problem.
They will need to see an uptick in this complaint before they will be able to isolate wherein the disconnect lies.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
428 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