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
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)