Pivot point for next day

Viewed 40

I have drawn levels based previous day high low. But I want to place that level on next day. I tried lot not luck. Can anyone please help me here.

//@version = 4
study(title="Previous days highs and lows00", overlay = true)
   
PrevBars = input(title = "Show previous highs and lows?", type =input.bool, defval=true)
condition = not(timeframe.isweekly or timeframe.ismonthly) 

h = security(syminfo.tickerid,"D",high,barmerge.gaps_off,barmerge.lookahead_on) 
l = security(syminfo.tickerid,"D",low,barmerge.gaps_off,barmerge.lookahead_on)

//plotshape(series = condition and PrevBars ? h[1] : na, title = "Previous high",color = #0E6720,location=location.absolute ,transp=0,editable = true)
//plotshape(series = condition and PrevBars ? l[1] : na, title = "Previous low",color =#AF0D26,location = location.absolute ,transp=0, editable = true)

// Draw lines from the previous highs and lows
newSession = change(time('D'))
count = barssince(newSession)


vR1 = h  + (h - l) * 0.10
vR2 = h  + (h - l) * 0.30

vS1 = l - (h - l) * 0.10
vS2 = l - (h - l) * 0.30

vP1 = h - (h - l) *  0.50
vP2 = l + (h - l) *  0.50

plotshape(series = condition and PrevBars ? vR1[1] : na, title = "Previous high",color = #0E6720,location=location.absolute ,transp=0,editable = true)
plotshape(series = condition and PrevBars ? vR2[1] : na, title = "Previous high",color = #0E6720,location=location.absolute ,transp=0,editable = true)
1 Answers

If you have the values you have several simple options for the display.
The "plots" are capable of taking an "offset" parameter that can print your result bars back/forward.

offset (integer) Shifts shapes to the left or to the right on the given number of bars. Default is 0.

So do the following:

plotshape(series = condition and PrevBars ? vR1[1] : na, title = "Previous high", offset = 1, color = #0E6720,location=location.absolute ,transp=0,editable = true)  
plotshape(series = condition and PrevBars ? vR2[1] : na, title = "Previous high", offset = 1, color = #0E6720,location=location.absolute ,transp=0,editable = true)

It may be more representative to use lines instead of plots in some cases (I'd suggest it for you). It depends on your preference.

line.new(bar_index, condition and PrevBars ? vR1[1] : na, bar_index + 1, condition and PrevBars ? vR1[1] : na)  
line.new(bar_index, condition and PrevBars ? vR2[1] : na, bar_index + 1, condition and PrevBars ? vR2[1] : na)

The pine script documentation has all the answers.

Final note: I'd rather use only the latest version Pine Script v5. It has more functionality.

Related