How to find Local Highs and Local Lows on a Chart

Is there a way of keeping track of local highs and local lows on a chart? Ideally what I want to do is keep track of % runs and % draw downs between local highs and local lows on charts. So I was wondering if there was any way to make this?

I also only want to denote the runs that matter so only new highs or lows created by passing through the 38.2 and 61.8 fib retracements. This way we don't have to keep track of every reversal.

It should look something like this Running and Drawdown % - Imgur


Code:
# Draw Highs and Lows of Thing
# created by tradingwithmiggy
# 2022/10/22
# GAME PLAN
# 1. Variables Needed:
#       - A (Lagging)
#       - B (Leading)
#       - hh (keeps track of current local high)
#       - ll (keeps track of current local low)
# 2. You need to calculate the retracement using the distance of the hh and ll
#       and using A and B to know where we on the retracement.
# 3. CONDITIONAL: if the length of (A -> B) passes the retracement threshhold
#       then hh and ll need to be updated. (I feel like I still need to get clear on this statement)
#       a. A is lower than B (means trending upwards)
#           - Update hh
#           - ll remains the same
#           - Check if (A->B) is more than 38.2 retracement
#           - Update A = hh  &&  ll = B
#       b. A is higher than B (means trending downwards)
#           - Update ll
#           - hh remains the same
#           - Check if (A->B) is less than 61.8 retracement
#           - Update A = ll  &&  hh = B

def rth = getTime() >= RegularTradingStart(getYYYYMMDD()) and

          getTime() <= RegularTradingEnd(getYYYYMMDD());


def B = close;

def hh = if rth and !rth[1]
            then open
        else if rth and A < B and (B-A)/(hh-ll) > 38.2
            then max(max(open[0],close[0]), hh)
        else if rth and A > B and (B-A)/(hh-ll) < 61.8
            then hh[1]
        else hh[1];

def ll = if rth and !rth[1]
            then open
        else if rth and A < B and (B-A)/(hh-ll) > 38.2
            then ll[1]
        else if rth and A > B and (B-A)/(hh-ll) < 61.8
            then min(min(open[0],close[0]), ll)
        else ll[1];

def A = if rth and !rth[1]
            then open
        else if rth and A < B and (B-A)/(hh-ll) > 38.2
            then hh
        else if rth and A > B and (B-A)/(hh-ll) < 61.8
            then ll
        else A[1];

addChartBubble(yes, high[0], "A: " + round(A) +"\nB: " + round(B) +"\nhh: " + round(hh)+"\nll: " + round(ll), COLOR.CYAN);

def retracement = absValue(A-B)/(hh-ll);
 
Last edited:
Is there a way of keeping track of local highs and local lows on a chart? Ideally what I want to do is keep track of % runs and % draw downs between local highs and local lows on charts. So I was wondering if there was any way to make this?

I also only want to denote the runs that matter so only new highs or lows created by passing through the 38.2 and 61.8 fib retracements. This way we don't have to keep track of every reversal.

It should look something like this Running and Drawdown % - Imgur

can you describe your rules differently.

the word 'local' has no meaning on a chart.

i don't know what you mean by these , A (Lagging) , B (Leading) . prices of peaks and valleys?
...is B the peak or valley price that is nearest is the last bar?
...is A the peak or valley price that is before point B?

what defines a hi or low? , hh , ll


this might help, it finds peaks and valleys.

Code:
# peaks_valleys_off_robert_00

#------------------------
#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# define swing low points , robert payne
#------------------------

def bn = BarNumber();
def na = double.nan;

input length = 7;

def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);

def peak = high > highest(high[1], length - 1) and high == GetValue(highest(high, length), -offset);
def valley = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);

#-------------------------------------

def vert = 0.002;
plot z1 = if peak then high*(1+vert) else na;
z1.SetPaintingStrategy(PaintingStrategy.POINTS);
z1.SetDefaultColor(Color.cyan);
z1.setlineweight(3);
z1.hidebubble();

plot z2 = if valley then low*(1-vert) else na;
z2.SetPaintingStrategy(PaintingStrategy.POINTS);
z2.SetDefaultColor(Color.cyan);
z2.setlineweight(3);
z2.hidebubble();
#
 

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
316 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