I am a new face to algorithmic trading and have been studying strategies for a couple of weeks. I decided to have my hand at programming my own strategy to get my feet wet.
My strategy is a consolidation breakout with confirmation from Bollinger bandwidth increase. This is nowhere near my final implementation, but if this can make some good trades by itself then I'll move onto the full strategy.
Currently, my code works all the way up until I try to confirm the breakout with the Bollinger band values. I was stuck calculating consolidation but figured out a way around it, and now it will trade based on just that parameter. My main problem arises when I try to calculate certain formulas based on values.
For example, this is my formula for the Bollinger bandwidth calculation
self.bb = self.BB("SPY", 40, 2.0, Resolution.Minute)
if self.bb.IsReady()
UpperBand = self.bb.UpperBand.Current.Value
LowerBand = self.bb.LowerBand.Current.Value
MiddleBand = self.bb.MiddleBand.Current.Value
BandWidth = ((UpperBand-(LowerBand))/MiddleBand)
if "current price" > "SMA price" and BandWidth > 5
self.SetHoldings("SPY", 0.5)
In the "If "current price" > "SMA price"" the current price over SMA price works, I tested it alone and it made trades, not good ones but trades none the less. I always get an Attribute error in the Upper, Lower, and Middle band get current value lines. I am new to python and I know from writing in other languages that numbers are stored weirdly but I can't seem to get past this problem.
Karthik Kailash
All the values for LowerBand, UpperBand, and MiddleBand will be on the order of the price of SPY. So the BandWidth will almost never be more than 2. I cloned your backtest and added some debug statements to illustrate this
Trace Davis
I put the debug statement you suggested and I still have the same RunTime error I mentioned earlier. It says Object has no Attribute for the BandWidth calculation. I tried to take what others have done but I cannot find a solution that fixes this problem
Karthik Kailash
I experienced no runtime error when I cloned and ran the backtest you posted. The code you pasted is different from what was in your backtest.
Trace Davis
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!