Extend calculated level until crossed HL2

autolox

Member
I'd like have these plots extended until they are reached again whether that be on the same day or a day out into the future. Yes, on the chart below I do have the indicator running on a smaller timeframe chart. If necessary, I don't mind running it on a 1hr chart.

Being able to discern the frequency of how long it takes for these levels to be reached again by average, median, and/or maximum would be awesome but that feels like a HUGE ask.

TIA!!

Code:
plot fifty = hl2(period=aggregationperiod.hour)[1];
fifty.setdefaultcolor(color.cyan);
fifty.setpaintingstrategy(paintingstrategy.horizontal);
fifty.setstyle(curve.firm);

1704411077752.png
 
Solution
I'd like have these plots extended until they are reached again whether that be on the same day or a day out into the future. Yes, on the chart below I do have the indicator running on a smaller timeframe chart. If necessary, I don't mind running it on a 1hr chart.

Being able to discern the frequency of how long it takes for these levels to be reached again by average, median, and/or maximum would be awesome but that feels like a HUGE ask.

TIA!!

Code:
plot fifty = hl2(period=aggregationperiod.hour)[1];
fifty.setdefaultcolor(color.cyan);
fifty.setpaintingstrategy(paintingstrategy.horizontal);
fifty.setstyle(curve.firm);

View attachment 20620

See if this mod to naked poc script that I posted elsewhere here is what you are wanting...
I'd like have these plots extended until they are reached again whether that be on the same day or a day out into the future. Yes, on the chart below I do have the indicator running on a smaller timeframe chart. If necessary, I don't mind running it on a 1hr chart.

Being able to discern the frequency of how long it takes for these levels to be reached again by average, median, and/or maximum would be awesome but that feels like a HUGE ask.

TIA!!

Code:
plot fifty = hl2(period=aggregationperiod.hour)[1];
fifty.setdefaultcolor(color.cyan);
fifty.setpaintingstrategy(paintingstrategy.horizontal);
fifty.setstyle(curve.firm);

View attachment 20620

See if this mod to naked poc script that I posted elsewhere here is what you are wanting.

It creates a script to plot you hl2 lines, extended until crossed by price. The magenta lines are the one's that have not been crossed and have bubbles indicating how many bars back these originated.

It currently includes 10 plots. More plots can be created using the logic forr the 10.

The image shows the following indicator with your code overlaid in cyan to verify the indicator.
Screenshot 2024-01-05 082913.png
Code:
script v {
    input daysback = 0;
    input agg = aggregationPeriod.HOUR;
    def volp = hl2(period=agg)[1];
    def ymd  = VOLP;
    def y    = if ymd != ymd[1] then y[1] + 1 else y[1];
    def pc   = if IsNaN(close)
                  then pc[1] else
               if y == HighestAll(y) - daysback
                  then volp  else
               pc[1];
    plot x    = if y > HighestAll(y) - daysback and Between(pc, low, high)
           then BarNumber() else Double.NaN;

    plot poc = if IsNaN(LowestAll(x))
           then pc
           else if BarNumber() > LowestAll(x)
           then Double.NaN
           else pc;
}

DefineGlobalColor("B", Color.WHITE);
DefineGlobalColor("NB", Color.MAGENTA);

plot v1 =  v(1).poc;
v1.AssignValueColor(if IsNaN(LowestAll(v(1).x)) then GlobalColor("NB") else GlobalColor("B"));
v1.SetPaintingStrategy(PaintingStrategy.DASHES);
v1.SetLineWeight(1);

plot v2 =  v(2).poc;
v2.AssignValueColor(if IsNaN(LowestAll(v(2).x)) then GlobalColor("NB") else GlobalColor("B"));
v2.SetPaintingStrategy(PaintingStrategy.DASHES);
v2.SetLineWeight(1);

plot v3 =  v(3).poc;
v3.AssignValueColor(if IsNaN(LowestAll(v(3).x)) then GlobalColor("NB") else GlobalColor("B"));
v3.SetPaintingStrategy(PaintingStrategy.DASHES);
v3.SetLineWeight(1);

plot v4 =  v(4).poc;
v4.AssignValueColor(if IsNaN(LowestAll(v(4).x)) then GlobalColor("NB") else GlobalColor("B"));
v4.SetPaintingStrategy(PaintingStrategy.DASHES);
v4.SetLineWeight(1);

plot v5 =  v(5).poc;
v5.AssignValueColor(if IsNaN(LowestAll(v(5).x)) then GlobalColor("NB") else GlobalColor("B"));
v5.SetPaintingStrategy(PaintingStrategy.DASHES);
v5.SetLineWeight(1);

plot v6 =  v(6).poc;
v6.AssignValueColor(if IsNaN(LowestAll(v(6).x)) then GlobalColor("NB") else GlobalColor("B"));
v6.SetPaintingStrategy(PaintingStrategy.DASHES);
v6.SetLineWeight(1);

plot v7 =  v(7).poc;
v7.AssignValueColor(if IsNaN(LowestAll(v(7).x)) then GlobalColor("NB") else GlobalColor("B"));
v7.SetPaintingStrategy(PaintingStrategy.DASHES);
v7.SetLineWeight(1);

plot v8 =  v(8).poc;
v8.AssignValueColor(if IsNaN(LowestAll(v(8).x)) then GlobalColor("NB") else GlobalColor("B"));
v8.SetPaintingStrategy(PaintingStrategy.DASHES);
v8.SetLineWeight(1);

plot v9 =  v(9).poc;
v9.AssignValueColor(if IsNaN(LowestAll(v(9).x)) then GlobalColor("NB") else GlobalColor("B"));
v9.SetPaintingStrategy(PaintingStrategy.DASHES);
v9.SetLineWeight(1);

plot v10 =  v(10).poc;
v10.AssignValueColor(if IsNaN(LowestAll(v(10).x)) then GlobalColor("NB") else GlobalColor("B"));
v10.SetPaintingStrategy(PaintingStrategy.DASHES);
v10.SetLineWeight(1);
;

AddLabel(1, "Most Recent Naked --> POC: " +
if IsNaN(LowestAll(v(1).x)) then "V1: " + v1 else
if IsNaN(LowestAll(v(2).x)) then "V2: " + v2 else
if IsNaN(LowestAll(v(3).x)) then "V3: " + v3 else
if IsNaN(LowestAll(v(4).x)) then "V4: " + v4 else
if IsNaN(LowestAll(v(5).x)) then "V5: " + v5 else
if IsNaN(LowestAll(v(6).x)) then "V6: " + v6 else
if IsNaN(LowestAll(v(7).x)) then "V7: " + v7 else
if IsNaN(LowestAll(v(8).x)) then "V8: " + v8 else
if IsNaN(LowestAll(v(9).x)) then "V9: " + v9 else
if IsNaN(LowestAll(v(10).x)) then "V10: " + v10 else
"NO V", Color.YELLOW) ;


input showbubbles = yes;
input bubblemover = 3;
def b  = bubblemover;
def b1 = b + 1;

AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v1[b], "1NB " + v1 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v2[b], "2NB " + v2 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v3[b], "3NB " + v3 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v4[b], "4NB " + v4 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v5[b], "5NB " + v5 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v6[b], "6NB " + v6 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v7[b], "7NB " + v7 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v8[b], "8NB " + v8 , GlobalColor("NB"));
AddChartBubblE(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v9[b], "9NB " + v9 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v10[b], "10NB " + v10 , GlobalColor("NB"));


v1.HideBubble();
v2.HideBubble();
v3.HideBubble();
v4.HideBubble();
v5.HideBubble();
v6.HideBubble();
v7.HideBubble();
v8.HideBubble();
v9.HideBubble();
v10.HideBubble();
 
Solution

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

@SleepyZ - Thanks so much...but...

I've tried copying the complete code a couple of times to make sure I didn't miss any content, I've tried various symbols and tried hiding plots but still get this "0" valued plot which is causing the view to be nowhere close to the result you displayed.

Any ideas?

1704475249272.png
 
@SleepyZ - Thanks so much...but...

I've tried copying the complete code a couple of times to make sure I didn't miss any content, I've tried various symbols and tried hiding plots but still get this "0" valued plot which is causing the view to be nowhere close to the result you displayed.

Any ideas?

View attachment 20624

Here is a shared link to the chart I displayed that works for me. http://tos.mx/q3QDqGd
 
I hope your inbox here is LOADED TO THE BRIM with messages like

"SleepyZ you're a superstar!!"

Thank you for your very kind message!

I made an adjustment to the above code to allow you to more easily change the aggregation, price and how many to plot at the input screen. I also added 10 more plots.

Screenshot 2024-01-05 131152.png

Code:
script v {
    input daysback = 0;
    input agg = AggregationPeriod.HOUR;
    input price = FundamentalType.HL2;
    def volp = Fundamental(price, period = agg)[1];
    def ymd  = volp;
    def y    = if ymd != ymd[1] then y[1] + 1 else y[1];
    def pc   = if IsNaN(close)
                  then pc[1] else
               if y == HighestAll(y) - daysback
                  then volp  else
               pc[1];
    plot x    = if y > HighestAll(y) - daysback and Between(pc, low, high)
           then BarNumber() else Double.NaN;

    plot poc = if IsNaN(LowestAll(x))
           then pc
           else if BarNumber() > LowestAll(x)
           then Double.NaN
           else pc;
}

DefineGlobalColor("B", Color.WHITE);
DefineGlobalColor("NB", Color.MAGENTA);

input show_x_plots = 1;
input agg = AggregationPeriod.HOUR;
input price = fundamentalType.HL2;

def na = double.nan;

plot v1 =  if show_x_plots < 1 then na else v(1, agg = agg, price = price).poc;
v1.AssignValueColor(if IsNaN(lowestall(v(1, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v1.SetPaintingStrategy(PaintingStrategy.DASHES);
v1.SetLineWeight(1);

plot v2 =  if show_x_plots < 2 then na else v(2, agg = agg, price = price).poc;
v2.AssignValueColor(if IsNaN(lowestall(v(2, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v2.SetPaintingStrategy(PaintingStrategy.DASHES);
v2.SetLineWeight(1);

plot v3 =  if show_x_plots < 3 then na else v(3, agg = agg, price = price).poc;
v3.AssignValueColor(if IsNaN(lowestall(v(3, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v3.SetPaintingStrategy(PaintingStrategy.DASHES);
v3.SetLineWeight(1);

plot v4 =  if show_x_plots < 4 then na else v(4, agg = agg, price = price).poc;
v4.AssignValueColor(if IsNaN(lowestall(v(4, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v4.SetPaintingStrategy(PaintingStrategy.DASHES);
v4.SetLineWeight(1);

plot v5 =  if show_x_plots < 5 then na else v(5, agg = agg, price = price).poc;
v5.AssignValueColor(if IsNaN(lowestall(v(5, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v5.SetPaintingStrategy(PaintingStrategy.DASHES);
v5.SetLineWeight(1);

plot v6 =  if show_x_plots < 6 then na else v(6, agg = agg, price = price).poc;
v6.AssignValueColor(if IsNaN(lowestall(v(6, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v6.SetPaintingStrategy(PaintingStrategy.DASHES);
v6.SetLineWeight(1);

plot v7 =  if show_x_plots < 7 then na else v(7, agg = agg, price = price).poc;
v7.AssignValueColor(if IsNaN(lowestall(v(7, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v7.SetPaintingStrategy(PaintingStrategy.DASHES);
v7.SetLineWeight(1);

plot v8 =  if show_x_plots < 8 then na else v(8, agg = agg, price = price).poc;
v8.AssignValueColor(if IsNaN(lowestall(v(8, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v8.SetPaintingStrategy(PaintingStrategy.DASHES);
v8.SetLineWeight(1);

plot v9 =  if show_x_plots < 9 then na else v(9, agg = agg, price = price).poc;
v9.AssignValueColor(if IsNaN(lowestall(v(9, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v9.SetPaintingStrategy(PaintingStrategy.DASHES);
v9.SetLineWeight(1);

plot v10 =  if show_x_plots < 10 then na else v(10, agg = agg, price = price).poc;
v10.AssignValueColor(if IsNaN(lowestall(v(10, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v10.SetPaintingStrategy(PaintingStrategy.DASHES);
v10.SetLineWeight(1);
;

plot v11 =  if show_x_plots < 11 then na else v(11, agg = agg, price = price).poc;
v11.AssignValueColor(if IsNaN(lowestall(v(11, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v11.SetPaintingStrategy(PaintingStrategy.DASHES);
v11.SetLineWeight(1);

plot v12 =  if show_x_plots < 12 then na else v(12, agg = agg, price = price).poc;
v12.AssignValueColor(if IsNaN(LowestAll(v(12, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v12.SetPaintingStrategy(PaintingStrategy.DASHES);
v12.SetLineWeight(1);

plot v13 =  if show_x_plots < 13 then na else v(13, agg = agg, price = price).poc;
v13.AssignValueColor(if IsNaN(LowestAll(v(13, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v13.SetPaintingStrategy(PaintingStrategy.DASHES);
v13.SetLineWeight(1);

plot v14 =  if show_x_plots < 14 then na else v(14, agg = agg, price = price).poc;
v14.AssignValueColor(if IsNaN(LowestAll(v(14, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v14.SetPaintingStrategy(PaintingStrategy.DASHES);
v14.SetLineWeight(1);

plot v15 =  if show_x_plots < 15 then na else v(15, agg = agg, price = price).poc;
v15.AssignValueColor(if IsNaN(LowestAll(v(15, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v15.SetPaintingStrategy(PaintingStrategy.DASHES);
v15.SetLineWeight(1);

plot v16 =  if show_x_plots < 16 then na else v(16, agg = agg, price = price).poc;
v16.AssignValueColor(if IsNaN(LowestAll(v(16, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v16.SetPaintingStrategy(PaintingStrategy.DASHES);
v16.SetLineWeight(1);

plot v17 =  if show_x_plots < 17 then na else v(17, agg = agg, price = price).poc;
v17.AssignValueColor(if IsNaN(LowestAll(v(17, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v17.SetPaintingStrategy(PaintingStrategy.DASHES);
v17.SetLineWeight(1);

plot v18 =  if show_x_plots < 18 then na else v(18, agg = agg, price = price).poc;
v18.AssignValueColor(if IsNaN(LowestAll(v(18, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v18.SetPaintingStrategy(PaintingStrategy.DASHES);
v18.SetLineWeight(1);

plot v19 =  if show_x_plots < 19 then na else v(19, agg = agg, price = price).poc;
v19.AssignValueColor(if IsNaN(LowestAll(v(19, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v19.SetPaintingStrategy(PaintingStrategy.DASHES);
v19.SetLineWeight(1);

plot v20 =  if show_x_plots < 20 then na else v(20, agg = agg, price = price).poc;
v20.AssignValueColor(if IsNaN(LowestAll(v(20, agg = agg, price = price).x)) then GlobalColor("NB") else GlobalColor("B"));
v20.SetPaintingStrategy(PaintingStrategy.DASHES);
v20.SetLineWeight(1);
;

AddLabel(1, "Most Recent Naked --> POC: " +
if IsNaN(LowestAll(v(1).x)) then "V1: " + v1 else
if IsNaN(LowestAll(v(2).x)) then "V2: " + v2 else
if IsNaN(LowestAll(v(3).x)) then "V3: " + v3 else
if IsNaN(LowestAll(v(4).x)) then "V4: " + v4 else
if IsNaN(LowestAll(v(5).x)) then "V5: " + v5 else
if IsNaN(LowestAll(v(6).x)) then "V6: " + v6 else
if IsNaN(LowestAll(v(7).x)) then "V7: " + v7 else
if IsNaN(LowestAll(v(8).x)) then "V8: " + v8 else
if IsNaN(LowestAll(v(9).x)) then "V9: " + v9 else
if IsNaN(LowestAll(v(10).x)) then "V10: " + v10 else
if IsNaN(LowestAll(v(11).x)) then "V11: " + v11 else
if IsNaN(LowestAll(v(12).x)) then "V12: " + v12 else
if IsNaN(LowestAll(v(13).x)) then "V13: " + v13 else
if IsNaN(LowestAll(v(14).x)) then "V14: " + v14 else
if IsNaN(LowestAll(v(15).x)) then "V15: " + v15 else
if IsNaN(LowestAll(v(16).x)) then "V16: " + v16 else
if IsNaN(LowestAll(v(17).x)) then "V17: " + v17 else
if IsNaN(LowestAll(v(18).x)) then "V18: " + v18 else
if IsNaN(LowestAll(v(19).x)) then "V19: " + v19 else
if IsNaN(LowestAll(v(20).x)) then "V20: " + v20 else
"NO V", Color.YELLOW) ;


input showbubbles = yes;
input bubblemover = 3;
def b  = bubblemover;
def b1 = b + 1;

AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v1[b], "1NB " + v1 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v2[b], "2NB " + v2 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v3[b], "3NB " + v3 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v4[b], "4NB " + v4 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v5[b], "5NB " + v5 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v6[b], "6NB " + v6 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v7[b], "7NB " + v7 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v8[b], "8NB " + v8 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v9[b], "9NB " + v9 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v10[b], "10NB " + v10 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v11[b], "11NB " + v11 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v12[b], "12NB " + v12 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v13[b], "13NB " + v13 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v14[b], "14NB " + v14 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v15[b], "15NB " + v15 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v16[b], "16NB " + v16 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v17[b], "17NB " + v17 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v18[b], "18NB " + v18 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v19[b], "19NB " + v19 , GlobalColor("NB"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), v20[b], "20NB " + v20 , GlobalColor("NB"));


v1.HideBubble();
v2.HideBubble();
v3.HideBubble();
v4.HideBubble();
v5.HideBubble();
v6.HideBubble();
v7.HideBubble();
v8.HideBubble();
v9.HideBubble();
v10.HideBubble();
v11.HideBubble();
v12.HideBubble();
v13.HideBubble();
v14.HideBubble();
v15.HideBubble();
v16.HideBubble();
v17.HideBubble();
v18.HideBubble();
v19.HideBubble();
v20.HideBubble();

#
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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