Timezone convertion between tickers (part 3)

后端 未结 1 1456
不知归路
不知归路 2021-01-26 18:04

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 tryi

相关标签:
1条回答
  • 2021-01-26 18:55

    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)
    

    0 讨论(0)
提交回复
热议问题