股票代码之间的时区转换 [英] Timezone convertion between tickers

查看:49
本文介绍了股票代码之间的时区转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为股票代码 ES1! 上的背景着色,用于那些属于股票代码 SPX 交易时段内的柱.
我们可以使用

当我们将代码切换到 ES1! 时,黄色背景也从 09:30 开始.
原因是

SPXAmerica/New_York 时区交易,即 UTC-4.
ES1! 在时区 America/Chicago 进行交易,即 UTC-5.

因此,当 SPX 在纽约 09:30 开始交易时,芝加哥只有 08:30.
因此,我需要 ES1! 图表上的黄色背景从 08:30 开始.
但是,不可能获得 时间(分辨率,会话) 要在另一个时区评估的函数.

我需要的是一个 time() 函数还考虑了时区.
理想情况下是这样的:

t1 = time(timeframe.period, "0930-1600", "America/New_York")

当当前柱落在纽约交易时段内时,这将在 ES1! 上返回一个非 na 值.
我知道当前的 时间(分辨率,会话)功能.

有没有人有解决方案或解决方法?

可以使用security来计算时间:

t1 = security("SPX", timeframe.period, time(timeframe.period, "0930-1600"))bgcolor(t1 ? color.yellow : na)

更新

正如 Bjorn Mistiaen 在评论中注意到的,gaps 参数必须设置为 barmerge.gaps_on:

t1 = security("SPX", timeframe.period, time(timeframe.period, "0930-1600"), gaps=barmerge.gaps_on)bgcolor(t1 ? color.yellow : na)

I'm attempting to color the background on ticker ES1! for those bars that fall within the trading session of ticker SPX.
We can use the
time(resolution, session) function to find out if a bar is in a specified session.

t1 = time(timeframe.period, "0930-1600")
bgcolor(t1 ? color.yellow : na)

This works when it's used on ticker SPX.
You can see that all bars have a yellow background, as expected.
Why? Because SPX trades between 09:30 and 16:00 in the timezone of the SPX ticker, which is America/New_York.

When we switch the ticker to ES1!, the yellow background ALSO starts at 09:30.
The reason for that is that the session parameter in the time(resolution, session) function, is evaluated in the timezone of the current ticker.

SPX trades in timezone America/New_York, which is UTC-4.
ES1! trades in timezone America/Chicago, which is UTC-5.

So, when SPX starts trading in New York at 09:30, it's only 08:30 in Chicago.
Therefore, I need the yellow background on the ES1! chart to start at 08:30.
However, it's not possible to get the time(resolution, session) function to be evaluated in another timezone.

What I need is a time() function that also takes the timezone into account.
Ideally like this:

t1 = time(timeframe.period, "0930-1600", "America/New_York")

This would return a non-na value on ES1! when the current bar falls within the New York trading session.
I know this is not possible with the current time(resolution, session) function.

Does anyone have a solution or workaround for this?

解决方案

You can use security to calculate the time:

t1 = security("SPX", timeframe.period, time(timeframe.period, "0930-1600"))
bgcolor(t1 ? color.yellow : na)

UPDATE

As Bjorn Mistiaen noticed in comments, the gaps parameter must be set to barmerge.gaps_on:

t1 = security("SPX", timeframe.period, time(timeframe.period, "0930-1600"), gaps=barmerge.gaps_on)
bgcolor(t1 ? color.yellow : na)

这篇关于股票代码之间的时区转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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