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.