I have attempted the solution displayed here: https://www.quantconnect.com/forum/discussion/5591/help-me-to-plot-candlesticks/p1/comment-27480 but I can't get plotting of 1 minute candles to work. My resulting plot only contains a single candle.
Here is my simplified SymbolData class which handles the plotting:
class SymbolData:
def __init__(self, algorithm, symbol):
self.algorithm = algorithm
self.symbol = symbol
self.ticker = symbol.Value
# Create a consolidator to update the indicators
self.consolidator = TradeBarConsolidator(1)
self.consolidator.DataConsolidated += self.OnDataConsolidated
# Register the consolidator to update the indicators
algorithm.SubscriptionManager.AddConsolidator(symbol, self.consolidator)
# Plotting
charting_time = algorithm.Time.strftime("%Y-%m-%d")
self.trade_chart_name = f"{symbol.Value}-{charting_time}-Trading"
self.trading_chart = Chart(self.trade_chart_name)
self.candles = Series(f"{self.ticker}", SeriesType.Candle)
self.trading_chart.AddSeries(self.candles)
algorithm.AddChart(self.trading_chart)
def OnDataConsolidated(self, sender: object, consolidated_bar: TradeBar) -> None:
self.candles.AddPoint(consolidated_bar.EndTime - timedelta(seconds=59), consolidated_bar.Open)
self.candles.AddPoint(consolidated_bar.EndTime - timedelta(seconds=58), consolidated_bar.High)
self.candles.AddPoint(consolidated_bar.EndTime - timedelta(seconds=57), consolidated_bar.Low)
self.candles.AddPoint(consolidated_bar.EndTime, consolidated_bar.Close)
Nico Xenox
Hey Haakon Flaarønning,
a little while ago someone had the same problem but because QC isnt a plotting platform the best solution is to follow the instructions in this chat. With a little help of Derek I made a code that will display your consolidated data in the jupyter notebook:
Even though you have to save the data in the objectstore it is the best solution we came up with. The smaller the resolution gets the more impossible it is for the platform to print the sticks.
Hope it helps ;)
Haakon
Hey Nico Xenox, thanks for the input! 😊
It's a pity that plotting candlestick charts in the QC backtest isn't available although I get that QC is not a plotting platform. Saving to the object store and creating the chart in a research notebook is a decent solution, although it is a bit more job, especially if you have multiple charts to plot. In that case, it may be better to fetch data through a history call (in a research notebook), and analyze the backtest order object to plot candles and trades.
Anyway, in my opinion, plotting candlestick charts in the algo backtest is a key feature which I hope gets implemented at some point. :)
Haakon
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!