Previous day high and low for the last 10 days script with lines on the chart.

Solution
I'm looking for:

Previous day high and low for the last 10 days script with lines on the chart.

Any suggestions

This will plot up to 10 previous day's highs/lows.
You can limit how many of these that you want to use at input show_x_previous
Image shows 6 of 10 based upon input, for example

Screenshot 2025-04-28 113958.jpg
Code:
#Example_Previous_Days_HL_for_show_x_previous_days
#

script hl {

    input lookback = 0;

    def n   = lookback;
    def na  = Double.NaN;
    def h   = high;
    def l   = low;
    def bn  = BarNumber();
    def ymd = GetYYYYMMDD();
    def capture  = !IsNaN(close) and ymd != ymd[1];
    def dayCount = CompoundValue(1,
                   if capture then dayCount[1] + 1 else dayCount[1], 0);
    def thisDay...
I'm looking for:

Previous day high and low for the last 10 days script with lines on the chart.

Any suggestions

This will plot up to 10 previous day's highs/lows.
You can limit how many of these that you want to use at input show_x_previous
Image shows 6 of 10 based upon input, for example

Code:
#Example_Previous_Days_HL_for_show_x_previous_days
#

script hl {

    input lookback = 0;

    def n   = lookback;
    def na  = Double.NaN;
    def h   = high;
    def l   = low;
    def bn  = BarNumber();
    def ymd = GetYYYYMMDD();
    def capture  = !IsNaN(close) and ymd != ymd[1];
    def dayCount = CompoundValue(1,
                   if capture then dayCount[1] + 1 else dayCount[1], 0);
    def thisDay  = (HighestAll(dayCount) - dayCount) ;

    def hh       = if thisDay == n and thisDay[1] == n + 1
                   then h
                   else if thisDay == n and h > hh[1]
                   then h
                   else hh[1];
    def hhigh    = if thisDay == n and h == hh then BarNumber() else na;
    def hhnan    = if IsNaN(hh) then hhnan[1] else hh;

    plot hhplot  = if BarNumber() >= HighestAll(hhigh) then (hhnan) else na;

    def ll       = if thisDay == n and thisDay[1] == n + 1
                   then l
                   else if thisDay == n and l < ll[1]
                   then l else ll[1];
    def llow  = if thisDay == n and l == ll then BarNumber() else na;
    def llnan = if IsNaN(ll) then llnan[1] else ll;

    plot llplot = if BarNumber() >= HighestAll(llow) then (llnan) else na;
}

input show_x_previous = 10;
input show_today = no;
def na = Double.NaN;
plot H0 = if !show_today then na else hl(0).hhplot;
plot L0 = if !show_today then na else hl(0).llplot;
plot H1 = if show_x_previous < 1 then na else hl(1).hhplot;
plot L1 = if show_x_previous < 1 then na else  hl(1).llplot;
plot H2 = if show_x_previous < 2 then na else  hl(2).hhplot;
plot L2 = if show_x_previous < 2 then na else  hl(2).llplot;
plot H3 = if show_x_previous < 3 then na else  hl(3).hhplot;
plot L3 = if show_x_previous < 3 then na else  hl(3).llplot;
plot H4 = if show_x_previous < 4 then na else  hl(4).hhplot;
plot L4 = if show_x_previous < 4 then na else  hl(4).llplot;
plot H5 = if show_x_previous < 5 then na else  hl(5).hhplot;
plot L5 = if show_x_previous < 5 then na else  hl(5).llplot;
plot H6 = if show_x_previous < 6 then na else  hl(6).hhplot;
plot L6 = if show_x_previous < 6 then na else  hl(6).llplot;
plot H7 = if show_x_previous < 7 then na else  hl(7).hhplot;
plot L7 = if show_x_previous < 7 then na else  hl(7).llplot;
plot H8 = if show_x_previous < 8 then na else  hl(8).hhplot;
plot L8 = if show_x_previous < 8 then na else  hl(8).llplot;
plot H9 = if show_x_previous < 9 then na else  hl(9).hhplot;
plot L9 = if show_x_previous < 9 then na else  hl(9).llplot;
plot H10 = if show_x_previous < 10 then na else hl(10).hhplot;
plot L10 = if show_x_previous < 10 then na else  hl(10).llplot;

DefineGlobalColor("H", Color.GREEN);
DefineGlobalColor("L", Color.RED);
H0.SetDefaultColor(GlobalColor("H"));
L0.SetDefaultColor(GlobalColor("L"));
H1.SetDefaultColor(GlobalColor("H"));
L1.SetDefaultColor(GlobalColor("L"));
H2.SetDefaultColor(GlobalColor("H"));
L2.SetDefaultColor(GlobalColor("L"));
H3.SetDefaultColor(GlobalColor("H"));
L3.SetDefaultColor(GlobalColor("L"));
H4.SetDefaultColor(GlobalColor("H"));
L4.SetDefaultColor(GlobalColor("L"));
H5.SetDefaultColor(GlobalColor("H"));
L5.SetDefaultColor(GlobalColor("L"));
H6.SetDefaultColor(GlobalColor("H"));
L6.SetDefaultColor(GlobalColor("L"));
H7.SetDefaultColor(GlobalColor("H"));
L7.SetDefaultColor(GlobalColor("L"));
H8.SetDefaultColor(GlobalColor("H"));
L8.SetDefaultColor(GlobalColor("L"));
H9.SetDefaultColor(GlobalColor("H"));
L9.SetDefaultColor(GlobalColor("L"));
H10.SetDefaultColor(GlobalColor("H"));
L10.SetDefaultColor(GlobalColor("L"));

input showbubbles = yes;
input bubblemover = 3;
def   bn    = BarNumber();
def   mover = showbubbles and bn == HighestAll(bn - bubblemover);
AddChartBubble(mover , H0, "H0", H0.TakeValueColor());
AddChartBubble(mover , H1, "H1", H1.TakeValueColor());
AddChartBubble(mover , H2, "H2", H2.TakeValueColor());
AddChartBubble(mover , H3, "H3", H3.TakeValueColor());
AddChartBubble(mover , H4, "H4", H4.TakeValueColor());
AddChartBubble(mover , H5, "H5", H5.TakeValueColor());
AddChartBubble(mover , H6, "H6", H6.TakeValueColor());
AddChartBubble(mover , H7, "H7", H7.TakeValueColor());
AddChartBubble(mover , H8, "H8", H8.TakeValueColor());
AddChartBubble(mover , H9, "H9", H9.TakeValueColor());
AddChartBubble(mover , H10, "H10", H10.TakeValueColor());

AddChartBubble(mover , L0, "L0", L0.TakeValueColor());
AddChartBubble(mover , L1, "L1", L1.TakeValueColor());
AddChartBubble(mover , L2, "L2", L2.TakeValueColor());
AddChartBubble(mover , L3, "L3", L3.TakeValueColor());
AddChartBubble(mover , L4, "L4", L4.TakeValueColor());
AddChartBubble(mover , L5, "L5", L5.TakeValueColor());
AddChartBubble(mover , L6, "L6", L6.TakeValueColor());
AddChartBubble(mover , L7, "L7", L7.TakeValueColor());
AddChartBubble(mover , L8, "L8", L8.TakeValueColor());
AddChartBubble(mover , L9, "L9", L9.TakeValueColor());
AddChartBubble(mover , L10, "L10", L10.TakeValueColor());


#
 

Attachments

  • Screenshot 2025-04-28 113958.jpg
    Screenshot 2025-04-28 113958.jpg
    148.6 KB · Views: 10
Solution

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
277 Online
Create Post

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