我想检测自定义会话的最后一条。我正在使用这里的代码:https://www.tradingcode.net/tradingview/last-session-bar/
总的来说,代码运行良好,但在某些情况下,它返回意外值。
下面的代码应该在每个15:45 (EDT)栏上绘制红色背景,因为它是美国纽约证券交易所会议(09:30-16:00 UTC-4)的最后一条。
//@version=5
indicator("last session bar",overlay = true)
// IsLastBarSession() returns 'true' when the current bar is the last
// of the specified session, adjusted for the given time zone (optional).
// Returns 'false' for other bars in the session, bars after the
// session, and when the time frame is day or higher.
IsLastBarSession(sessionTime, sessionTimeZone=syminfo.timezone) =>
var int lastBarHour = na
var int lastBarMinute = na
var int lastBarSecond = na
inSess = not na(time(timeframe.period, sessionTime, sessionTimeZone))
if not inSess and inSess[1]
lastBarHour := hour[1]
lastBarMinute := minute[1]
lastBarSecond := second[1]
hour == lastBarHour and minute == lastBarMinute and second == lastBarSecond
// Give the last bar of the 09:30 - 16:30 UTC-4 session a red background
bgcolor(IsLastBarSession("0930-1600", "UTC-4") ?
color.new(color.red, 80) : na)在大多数情况下,最后一条是正确的检测。
但是有时候它会比它应该提前90分钟检测到最后一根蜡烛(尽管图上有14:30-15:45的蜡烛)。为什么?
COMEX:GC1!
日期:7月5日
周期: 15m (与30m、1h、2h相同)
发布于 2022-07-09 07:13:46
代码是检查前一天的关闭时间,并使用它在当前天找到关闭,但自从前一天蜡烛关闭在14:15,它使用它的情节相同,我已经更正如下
//@version=5
indicator("last session bar",overlay = true,max_labels_count=500)
// IsLastBarSession() returns 'true' when the current bar is the last
// of the specified session, adjusted for the given time zone (optional).
// Returns 'false' for other bars in the session, bars after the
// session, and when the time frame is day or higher.
IsLastBarSession(sessionTime, sessionTimeZone=syminfo.timezone) =>
var int lastBarHour = na
var int lastBarMinute = na
var int lastBarSecond = na
inSess = not na(time(timeframe.period, sessionTime, sessionTimeZone))
not inSess and inSess[1]
// Give the last bar of the 09:30 - 16:30 UTC-4 session a red background
bgcolor(IsLastBarSession("0930-1600", "UTC-4") ?
color.new(color.red, 80) : na,-1)https://stackoverflow.com/questions/72919268
复制相似问题