Hello,
If you look at the backtest (just look at the main.py file, ignore the others since they are irrelevant), we can see that the CandleStick chart only plots partially, while the rest of the charts plot completely. The cause of this is likely caused by the block on line 57. I was forced to add a 'if data[self.equity_str] is not None:' when creating the candstick plots since I sometimes would get hit with an error halfway through my backtest:
'NoneType' object has no attribute 'Open'I was not able to attach that backtest, which is why I'm attaching this one as reference. Is this a bug? Or am I doing something wrong when building the candlestick chart?
Thanks in advance for the help!
Rahul Chowdhury
Hey Alphaalpha,
We need to check whether there is bar data available in the current slice data before trying to access OHLC data. Sometimes there may be bar data missing, which is causing the error. We can check with
if data.Bars.ContainsKey(self.equity_str): self.candles.AddPoint(time + timedelta(minutes=1), data[self.equity_str].Open) self.candles.AddPoint(time + timedelta(minutes=2), data[self.equity_str].High) self.candles.AddPoint(time + timedelta(minutes=3), data[self.equity_str].Low) self.candles.AddPoint(time + timedelta(minutes=4), data[self.equity_str].Close)
Best
Rahul
Ernay
Apologies for the noob question, but where does the candlestick / RSI plot show up when running the strategy? I didn't see it in the backtest results or anywhere else. Thanks.
Rahul Chowdhury
Hey Ernie,
You will need to select your custom chart in the Select Chart table in the backtest page. As a guide, you can use this YouTube video which shows to navigate the backtest page
Best
Rahul
Ernay
thank you Rahul!
Alphalpha
Hey Rahul! Sorry for the late reply. So your answer of checking that the data exists would be the same as this snippet that already exists in my code above (line 64, right above the plotting section, just like yours):
if data[self.equity_str] is not None:
My question is more so as to why this happens. If you try to run my backtest, you can see that it plots the chart but has a gap between July 27th 2009 and Nov 23rd 2009. The data is essentially missing here.
However, if you change the date parameters to a narrower timeframe e.g.
self.SetStartDate(2009, 8, 1) # Set Start Date self.SetEndDate(2010, 1, 1)
The plot is actually populated! So I find it weird that the data effectively exists for the same time period but chooses to expose itself only for certain narrow timeframes. Looks like a bug to me, so just wanted to make sure I'm not actually mis-implementing something.
Jack Simonson
Hi,
The data is not being plotted because there are too many data points to be shown on the plot. If you change the resolution to daily data, it will plot OHLC data over the period where it isn't being shown in the current backtest. Similarly, if you change to minute resolution, you'll see that the dates plotted are even fewer. You can use the data explorer to verify that the data does exist during the timeframe you mentioned (July - Nov 2009)
Alphalpha
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!