I searched everywhere in the documentation, asked the AI, and found absolutely nothing about it:
I set everything to UTC using self.set_time_zone("UTC").
In OnData, I output something with Plot, but it's displayed exactly 4 hours earlier.
Obviously, the time zone for the chart must be set separately.
But how can I do that?
from AlgorithmImports import *
class ChartingDemoAlgorithm(QCAlgorithm):
def Initialize(self):
self.set_time_zone("UTC")
self.SetStartDate(2024, 8, 12)
self.SetEndDate(2024, 8, 14)
self.set_brokerage_model(BrokerageName.BYBIT, AccountType.MARGIN)
self.crypto_future = self.AddCryptoFuture("BTCUSDT",Resolution.Minute, market="Bybit")
self.symbol = self.crypto_future.Symbol
self.chart = Chart("test")
self.chart.AddSeries(CandlestickSeries("candle"))
self.debug(f"{self.time_zone}")
# result: UTC
self.debug(f"{self.securities[self.symbol].exchange.hours.time_zone}")
# result: UTC
def OnData(self, slice: Slice):
if not slice.Bars.ContainsKey(self.symbol):
return
bar = slice.Bars[self.symbol] # None if not found
if self.Time.time() == time(5, 0):
self.Debug(f"self.Time: {self.Time}")
self.Debug(f"bar: {bar} bar.Time: {bar.Time} bar.EndTime: {bar.EndTime}")
self.Plot("test", "candle", bar.Open, bar.High, bar.Low, bar.Close)
Mia Alissi
Here's the corrected version of Kamran's code with the necessary adjustments:
Key Adjustments:
AddCryptoFuture
toadd_crypto
as there was no such methodAddCryptoFuture
in the API.Resolution.MINUTE
to ensure proper enum usage.self.symbol
to use thesymbol
property.Sources: Custom Charting Algorithm, Bybit Custom Data Crypto Regression Algorithm, Bybit Crypto Futures Regression Algorithm, Basic Template Crypto Algorithm, Extended Market Trading Regression Algorithm
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Kamran v. Kleist
Whatever the case, it has nothing to do with the question.
Because nothing has changed.
The issue is why the chart is using a different timeframe.
What is 3.? And if 1. is correct, why does it work?
Jared Broad
Hi Kamran,
You cannot edit the plot time zones - the set time zone changes the self.time timezone but not output results.
Best
Jared
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Kamran v. Kleist
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!