Search code examples
timepine-scriptpine-script-v5tradingview-api

How can I draw a line of a specific candle in a specific time of a specific character?


I want to draw a line of a specific candle in a specific time (9:30) of a specific character (Open price) as a step line; when next candle at 9:30 opens, the line takes new value of new candle. I tried to do it myself but it does not look like I would like it to look like.

So I input Data as open, probably time date is a problem; I put it as session, but input.time does not seeem to work; at least with my skills. I extract the data to the value (Data * 1) because it's constant line of opening price and plot it.

Could ANYONE change it to work the way it should work; like constant, horizontal line from 9:30 to next 9:30 candle, then starting from thew new 9:30 candle (step line?)

//@version=5
indicator("ONE LINE", overlay=true)

show1 = input(true, "LINE ONE", inline="LINE ONE")
color1 = input(#ff0000, "", inline="LINE ONE")


LineOneData = input.source(open, title="LINE ONE")
LineOneDate = input.session("0930-0931")
LineOneValue = LineOneData * 1

plot(show1 ? LineOneValue : na, color=color1, linewidth=4, title="LINE ONE")



Solution

  • You must reassign the var LineOneValue

    //@version=5
    indicator("ONE LINE", overlay=true)
    
    show1 = input(true, "LINE ONE", inline="LINE ONE")
    color1 = input(#ff0000, "", inline="LINE ONE")
    
    
    LineOneData = input.source(open, title="LINE ONE")
    LineOneDate = input.session("0930-0931")
    
    issession = not na(time(timeframe.period,LineOneDate))
    var LineOneValue = 0.0
    LineOneValue := issession ? LineOneData * 1 : LineOneValue
    
    plot(show1 ? LineOneValue : na, color=color1, linewidth=4, title="LINE ONE")
    

    e.g.