我正在开发一个指标,通过更改图表背景来显示自定义时区时段。
为此,我使用此函数来检查一个柱是否在我定义的时间段之一内:
InSession(sess) => na(time(period, sess)) == false
sess
类似于 "0130-0800"
。
但它在周末不绘制任何东西。 time()
函数似乎只在工作日检查它的输入。但是我在每天开放的加密货币中使用这个指标。
有什么方法可以将 time()
检查延长到周末吗?如果不是,您能想出另一种方法来检查柱是否在时间范围内吗?
PS:这是完整的指标代码:https://es.tradingview.com/script/NMjZ2616/
最佳答案
您只需将字符串 ":1234567"
添加到 session 时间以包括周末和 ":12345"
以排除周末。
示例代码:
// InSession() determines if a price bar falls inside the specified session
InSession(sess) => na(time(period, sess)) == false
// === INPUTS ===
sessionHours=input(defval="0800-1400", type = session, title="Session Hours")
inputIncludeWeekends=input(title="Include Weekends?", type=bool, defval=true)
weekendsStr = inputIncludeWeekends ? ":1234567" : ":12345"
// === /INPUTS ===
bgcolor(color=InSession(sessionHours + weekendsStr)[1] ? red : na, title="Session Hours", transp=85)
关于time - TradingView Pine 脚本的周末 time() 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50669373/