股票代码之间的时区转换(第 3 部分) [英] Timezone convertion between tickers (part 3)
问题描述
正如
为了可视化该时差,我创建了一个小脚本来绘制两个时区的时间.
//@version=4研究(Nymex-CME 时间",shorttitle="时间")time_cl1 = security("CL1!", timeframe.period, time(timeframe.period), gaps=barmerge.gaps_on)//UTC-4 Nymextime_es1 = security("ES1!", timeframe.period, time(timeframe.period), gaps=barmerge.gaps_on)//UTC-5 CME情节(time_cl1,time_cl1",color.blue)情节(time_es1,time_es1",color.red)
由于两个股票代码在相隔 1 小时的时区交易,我预计会出现 1 小时的时差.
然而,令我惊讶的是,两个时间总是完全相同.
我不明白.
不是应该有1小时的差异吗?
time()
是交易所时区的时间,当通过 security()
查看时,还将取决于每个代码的条形图如何相互映射.此外,这两个市场的开始/收盘时间有 1 小时的增量.
在这里,我们获取 Unix 时间,然后在图表时区的上下文中将其转换为小时:
//@version=4研究(Nymex-CME 时间",shorttitle="时间")time_cl1 = security("CL1!", timeframe.period, timestamp(year, month, dayofmonth, hour, minute, second), gaps=barmerge.gaps_on)//UTC-4 Nymextime_es1 = security("ES1!", timeframe.period, timestamp(year, month, dayofmonth, hour, minute, second), gaps=barmerge.gaps_on)//UTC-5 CMEhour_cl1 = hour(security("CL1!", timeframe.period, timestamp(year, month, dayofmonth, hour, minute, second), gaps=barmerge.gaps_on))//UTC-4 Nymexhour_es1 = hour(security("ES1!", timeframe.period, timestamp(year, month, dayofmonth, hour, minute, second), gaps=barmerge.gaps_on))//UTC-5 CME情节(time_cl1,time_cl1",color.blue)情节(time_es1,time_es1",color.red)情节(hour_cl1,hour_cl1",color.blue)情节(hour_es1,hour_es1",color.red)
As mentioned in the answer to Timezone convertion between tickers by Dennis T,
we can use the security() function to get the time in another timezone.
Now I was trying to get times from 2 different timezones.
Ticker CL1!
trades on Nymex
in New York, in timezone UTC-4
.
Ticker ES1!
trades on CME
in Chicago, in timezone UTC-5
.
We can see that from the symbol info
In order to visualize that time difference, I've created a small script that plots the time in both timezones.
//@version=4
study("Nymex-CME times", shorttitle="Time")
time_cl1 = security("CL1!", timeframe.period, time(timeframe.period), gaps=barmerge.gaps_on) // UTC-4 Nymex
time_es1 = security("ES1!", timeframe.period, time(timeframe.period), gaps=barmerge.gaps_on) // UTC-5 CME
plot(time_cl1, "time_cl1", color.blue)
plot(time_es1, "time_es1", color.red)
Since both tickers are traded in timezones that are 1 hour apart, I expected to see a 1 hour time difference.
To my surprise however, both times are always exactly the same.
I don't understand that.
Shouldn't there be a 1 hour difference?
time()
is the time in the exchange's time zone and when viewed through security()
, will also be dependent on how the bars from each ticker are mapped to each other. Also, those two markets have a one hour delta in their starting/closing time.
Here, we fetch the Unix time but then convert it to hours in the context of the chart's timezone:
//@version=4
study("Nymex-CME times", shorttitle="Time")
time_cl1 = security("CL1!", timeframe.period, timestamp(year, month, dayofmonth, hour, minute, second), gaps=barmerge.gaps_on) // UTC-4 Nymex
time_es1 = security("ES1!", timeframe.period, timestamp(year, month, dayofmonth, hour, minute, second), gaps=barmerge.gaps_on) // UTC-5 CME
hour_cl1 = hour(security("CL1!", timeframe.period, timestamp(year, month, dayofmonth, hour, minute, second), gaps=barmerge.gaps_on)) // UTC-4 Nymex
hour_es1 = hour(security("ES1!", timeframe.period, timestamp(year, month, dayofmonth, hour, minute, second), gaps=barmerge.gaps_on)) // UTC-5 CME
plot(time_cl1, "time_cl1", color.blue)
plot(time_es1, "time_es1", color.red)
plot(hour_cl1, "hour_cl1", color.blue)
plot(hour_es1, "hour_es1", color.red)
这篇关于股票代码之间的时区转换(第 3 部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!