我正在开发一个指标,通过更改图表背景来显示自定义时区会话。
为此,我使用此函数来检查一个条形是否在我定义的时间段之一内:
InSession(sess) => na(time(period, sess)) == false
Run Code Online (Sandbox Code Playgroud)
当sess
它的东西相似"0130-0800"
。
但它在周末没有画任何东西。该time()
函数似乎仅在工作日检查其输入。但我在每天开放的加密货币中使用这个指标。
有什么办法可以把time()
支票延长到周末吗?如果没有,您能想出另一种方法来检查柱线是否在时间范围内吗?
PS:这是完整的指标代码:https : //es.tradingview.com/script/NMjZ2616/
您只需将字符串添加":1234567"
到会话时间以包括周末和":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)
Run Code Online (Sandbox Code Playgroud)
感谢https://www.tradingview.com/u/pequet/