TradingView 调整时区

TradingView Adjust for Timezone

我最近写了一个简短的脚本来强调股票市场的开盘和收盘,我想在期货图表上看到这个(即 ES1!)。

study("Open & Close", overlay=true)
openColor = na(time(timeframe.period, "0930-1030")) ? na : color.green
closeColor = na(time(timeframe.period, "1500-1600")) ? na : color.red
bgcolor(openColor)
bgcolor(closeColor)

问题是给定的时间范围字符串(例如“0930-1030”)仍在东部时间进行评估,因此 10:30-11:30 和 16:00-17:00 结束被突出显示。

如何让 TradingView 知道 syminfo.timezone

timetimenow 总是 return UTC 时间。您将需要使用其他 built-ins 来获取交易所时区的时间信息:second, minute, hour, year, month, dayofmonth, dayofweektimestamp() 例如:
https://www.tradingview.com/pine-script-docs/en/v4/essential/Sessions_and_time_functions.html#built-in-variables-for-working-with-time

[编辑:2020.09.15 16:00 — LucF]

//@version=4
study("Open & Close", "", true)
zone = input("GMT-5")
c_bgOpen = input(color.green)
c_bgClose = input(color.red)
o1 = timestamp(zone, year, month, dayofmonth, 09, 30)
o2 = timestamp(zone, year, month, dayofmonth, 10, 30)
c1 = timestamp(zone, year, month, dayofmonth, 15, 00)
c2 = timestamp(zone, year, month, dayofmonth, 16, 00)
c_bg = time >= o1 and time <= o2 ? c_bgOpen : time >= c1 and time <= c2 ? c_bgClose  : na
bgcolor(c_bg)