2

我正在开发一个指标,通过更改图表背景来显示自定义时区会话。

为此,我使用此功能来检查一个柱是否在我定义的时间会话之一内:

InSession(sess) => na(time(period, sess)) == false

哪里sess有类似的东西"0130-0800"

但它在周末没有画任何东西。该time()函数似乎只在工作日检查其输入。但我在每天开放的加密货币中使用这个指标。

有什么办法可以延长time()检查到周末?如果没有,你能想出另一种方法来检查柱是否在时间范围内吗?

PS:这是完整的指标代码:https ://es.tradingview.com/script/NMjZ2616/

4

1 回答 1

5

您只需将字符串添加":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)

感谢https://www.tradingview.com/u/pequet/

于 2018-06-03T20:52:06.983 回答