Hi,
Can we plot a candlestick chart on the minute resolution in the backtest for the stocks we trade? If so, how can we do that?
Thank you in advance.
QUANTCONNECT COMMUNITY
Hi,
Can we plot a candlestick chart on the minute resolution in the backtest for the stocks we trade? If so, how can we do that?
Thank you in advance.
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.
Mia Alissi
To plot a candlestick chart on the minute resolution in a backtest for the stocks you trade, you can follow these steps using QuantConnect's API:
Initialize the Algorithm: Set the start and end dates, initial cash, and add the equity with minute resolution.
Create a Chart: In the
initialize
method, create aChart
object to hold the candlestick series.Add Candlestick Series: Use
CandlestickSeries
to add a candlestick series to the chart for the stock you are trading.Add the Chart to the Algorithm: Use
self.add_chart(chart)
to add the chart to your algorithm.Consolidate Data: Use the
self.consolidate
method to consolidate minute data into the desired time frame for plotting.Plot Data: In the
on_data
method, useself.plot
to plot the candlestick data on the chart.Run the Backtest: Execute the backtest to visualize the candlestick chart in the results.
Here's a sample implementation:
This code sets up a candlestick chart for the SPY stock using minute resolution data. The
on_consolidated
method is used to plot the candlestick data on the chart. You can adjust the symbol and time frame as needed for your specific use case.Sources: Custom Charting Algorithm, Charting - QuantConnect.com, Alternative Data - QuantConnect.com, Forex - QuantConnect.com, CFD - QuantConnect.com
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.
RIF87
Do we need on_consolidated method even if we already using minute resolution?
Louis Szeto
Hi RIF87
Indeed you don't need to! Just using the trade bar received is fine.
Best
Louis
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.
RIF87
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!