How to draw a vertical line at a certain time in pinescript on Tradingview?

前端 未结 1 663
不知归路
不知归路 2021-01-16 07:44

I would like to draw a vertical line, every day at a certain local time (e.g. 08:00 GMT+1).

Since my last post about vertical lines, pine-script has been updated to

相关标签:
1条回答
  • 2021-01-16 08:10

    Version 1

    One version of the timestamp() function can use a timezone parameter:

    //@version=4
    study("Line at time", overlay=true)
    targetTime = timestamp("GMT+1", year, month, dayofmonth, 08, 00, 00)
    bgcolor(targetTime == time ? color.silver : na, transp = 0)
    
    // Debugging: these plots lines in separate window
    plot(targetTime, "targetTime", color.orange)
    plot(time, "time")
    

    Chart is shown with UTC+1 times and indicator is set to "No Scale" not to disrupt price scale:

    Version 2

    With this version you can choose:

    • A from/to hour range
    • To show the line on weekdays only
    • Between bgcolor or vline mode
    //@version=4
    study("Line at time",overlay=true)
    fromHour = input(7)
    toHour = input(10)
    weekdaysOnly = input(true)
    useVline = input(false)
    dayIsOk = not weekdaysOnly or (dayofweek != dayofweek.saturday and dayofweek != dayofweek.sunday)
    t1 = timestamp("GMT+2", year, month, dayofmonth, fromHour, 00, 00)
    t2 = timestamp("GMT+2", year, month, dayofmonth, toHour, 00, 00)
    timeIsOk = (time >= t1) and (time <= t2)
    bgcolor( not useVline and timeIsOk and dayIsOk ? color.orange : na, transp = 80)
    if useVline and timeIsOk and dayIsOk
        line.new(bar_index, low * .9999, bar_index, high * 1.0001, xloc.bar_index, extend.both, #FF8000ff, line.style_solid, 1)
    

    0 讨论(0)
提交回复
热议问题