检测会话中断 [英] Detecting session breaks

查看:46
本文介绍了检测会话中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于休息时间的问题.

我知道您可以通过在图表的时间尺度上激活 Session Breaks 来将 Session Breaks 添加到图表中.
然后它在图表上显示为一条垂直线,每当出现会话中断时,表示新会话的开始.
Session Break 线可以在图表设置中进行格式化,在 Appearance > 下.会话中断.

I know that you can add Session Breaks to a chart by activating Session Breaks on the time scale of the chart.
It then appears as a vertical line on the chart, whenever a Session Break occurs, indicating the start of a new session.
That Session Break line can be formatted in the chart settings, under Appearance > Session Breaks.

我正在尝试检测 Pine Script 中的会话中断.
Pine Script 中是否有可靠方法来检测新会话的开始?
尤其是期货合约.

I'm trying to detect that Session Break in Pine Script.
Is there a reliable way in Pine Script to detect the start of a new session?
Especially for futures contracts.

通常,在会话停止和新会话开始之间会经过一段时间(暂停).
因此,我的想法是检查当前柱和上一个柱之间的时间差.
如果该时间差大于时间宽度"一个小节,这意味着有一个暂停".
因此,新的会话已经开始.
这种方法似乎在大多数情况下都有效.

Typically, there's an amount of time (a pause) that passes between the stop of a session and the start of a new session.
Therefore, my idea was to check the time difference between the current bar and the previous bar.
If that time difference is greater than the "time width" of one bar, that means that there's been a "pause".
Hence, a new session has started.
That approach seems to work for most of the days.

然而,当我查看期货代码 NYMEX:NG1! 时,这种逻辑似乎并不总是正确的.
该股票行情的某些日子似乎有暂停"中场.
我怀疑交易因那些暂停"而停止.瞬间.
通过比较 2020 年 10 月 27 日(正常日)与 2020 年 10 月 28 日(不规则日,会议期间暂停)可以看出一个例子.
例如,我将图表以 15 分钟的间隔放在 Exchange timezone 中.
绿色背景是我的代码检测会话中断.

However, when I look at futures ticker NYMEX:NG1!, that logic does not always seem to be correct.
Some days on that ticker seem to have "pauses" mid-session.
I suspect that trading was halted on those "pause" moments.
An example can be seen by comparing 27 Oct 2020 (normal day) to 28 Oct 2020 (irregular day with mid-session pauses).
For the example, I've put the chart in Exchange timezone on a 15 minute interval.
The green background is my code detecting session breaks.

2020 年 10 月 27 日(正常日子)
可以看到每个柱比上一个柱晚15分钟开始,这是正常的,也是预期的.
会话从 18:00 开始,每 15 分钟进行一次:

On 27 Oct 2020 (normal day)
You can see that each bar starts 15 minutes later than the previous bar, which is normal and expected.
The session starts at 18:00 and progresses per 15 minutes:

18:00 - 18:15 - 18:30 - 18:45 - 19:00 - 19:15 - 19:30 - 19:45 - 20:00 - 20:15 - etc...  

2020 年 10 月 28 日(不规则的一天,会议中间暂停)
您可以看到并非每个柱形都比前一个柱形晚 15 分钟开始.
会话也从 18:00 开始,每 15 分钟进行一次,但并非始终如一:

On 28 Oct 2020 (irregular day with mid-session pauses)
You can see that NOT each bar starts 15 minutes later than the previous bar.
The session also starts at 18:00 and progresses per 15 minutes, but NOT consistenly:

18:00 - 18:15 - 18:30 - (gap) - 19:15 - (gap) - 20:45 - (gap) 21:00 - 21:15 - 21:30 - 21:45 - (gap) - 22:30 - (gap) - 23:00 - (gap) - 23:45 - 00:00 - (gap) - 00:45 - (gap) - 03:00 - (gap) - 03:30 - (gap) - 03:45 - 04:00 - 04:15 - (gap) - 05:15 - 05:30 - (gap) - 06:00 - 06:15 - 06:30 - 06:45 - 07:00 - 07:15 - etc... (normal from here on).  

我用于检测会话中断的代码(上面屏幕截图中的绿色背景)

My code for detecting session breaks (green backgrounds in the screenshot above)

//@version=4
study("NewSession", overlay=true)

var bool    newSession      = na
var int     bar_width_in_ms = timeframe.multiplier * 60 * 1000

newSession := change(time) > bar_width_in_ms

bgcolor(newSession ? color.green : na, 70)

总之,我的问题是:
Pine Script 中是否有任何可靠 方法来检测新会话的开始?
尤其是期货合约.

In conclusion, my question is this:
Is there any reliable way in Pine Script to detect the start of a new session?
Especially for futures contracts.

推荐答案

您可以使用 change(time("1D")) 来跟踪一个每日柱线的结束位置和另一个柱线的开始位置:

You can use the change(time("1D")) to track where one daily bar ends and another begins:

//@version=4
study("NewSession", overlay=true)
newSession = change(time("1D"))
bgcolor(newSession ? color.green : na, 70)

这篇关于检测会话中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆