1

Please help me to extend the plotted line till the end of present trading session. So that, the levels may appear on the chart from the beginning of current trading session.

//@version=5

indicator(title="fff", overlay=true)

// Get user input

disableRepaint = input.bool(title ="Disable Repainting?", defval=true)

pdl = request.security(syminfo.tickerid, "D", low[disableRepaint and barstate.isconfirmed ? 0 : 1]) 

pdh = request.security(syminfo.tickerid,"D", high[disableRepaint and barstate.isconfirmed ? 0 : 1])


P1 = (pdh-(pdh-pdl) * 0.756)

P2 = (pdl+(pdh-pdl) * 0.790)


//gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_off) //Does not repaint


plot(P1 == P1[1] ? P1 : na, style=plot.style_linebr,color=color.white, linewidth=2)
plot(P2 == P2[1] ? P2 : na,  style=plot.style_linebr,color=color.white,linewidth=2)
luizv
  • 618
  • 1
  • 12
  • 22

1 Answers1

0

You might want to have a look at Lines & boxes which is more flexible and have an extend parameter that can be controlled in a more precise way:
https://www.tradingview.com/pine-script-docs/en/v5/concepts/Lines_and_boxes.html

An example below:

indicator("Range", "", true)
string tfInput = input.timeframe("W", "Timeframe")
var hi = float(na)
var lo = float(na)
var line hiLine = na
var line loLine = na
var box hiLoBox = na
// Detect changes in timeframe.
bool newTF = ta.change(time(tfInput))
if newTF
    // New bar in higher timeframe; reset values and create new lines.
    hi := high
    lo := low
    hiLine := line.new(bar_index - 1, hi, bar_index, hi, width = 2)
    loLine := line.new(bar_index - 1, lo, bar_index, lo, width = 2)
    int(na)
else
    // On other bars, extend the right coordinate of lines.
    line.set_x2(hiLine, bar_index)
    line.set_x2(loLine, bar_index)
    int(na)

Not a direct answer to your question but hopefully a direction worth exploring that achieves what you want.

Dusty
  • 3
  • 5