简体   繁体   中英

Pine Script (TradingView) get next session details

Using Pine Script I could draw a custom line with below code.

l = line.new(timestamp(2020, 04, 07, 09, 15), 17500, timestamp(2020, 04, 08, 09, 15), 17500, xloc.bar_time)
line.delete(l[1])

I would like to draw a custom line for next trading day (something like below image).

Is there a way to find upcoming trading day's timestamp in Pine Script??

在此处输入图像描述

This will work on 24/7 markets. You'll probably need to make adjustments when you can test on a live market:

//@version=4
study("", "", true)
y  = high
x1 = timestamp(year(timenow), month(timenow), dayofmonth(timenow) + 1, 9, 30)
x2 = timestamp(year(timenow), month(timenow), dayofmonth(timenow) + 2, 9, 30)
var line l = na
if barstate.islast
    if na(l)
        // Only create line once, then update it.
        l := line.new(x1, y, x2, y, xloc.bar_time)
        // Make 2 if blocks same type so compiler doesn't complain.
        int(na)
    else
        line.set_xy1(l, x1, y)
        line.set_xy2(l, x2, y)
        int(na)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM