Overall Statistics
namespace QuantConnect.Algorithm.CSharp
{ 
    public class PastClose : QCAlgorithm
    {
    	private Symbol _spy;
        
        private RollingWindow<TradeBar> Bar;
        private RollingWindow<BollingerBandState> BBWin;
        private BollingerBands _bb;
        
        public override void Initialize()
        {
            SetStartDate(2016, 01, 01);  //Set Start Date
            SetEndDate(2016, 12, 31);    //Set End Date
            SetCash(100000);             //Set Strategy Cash

            AddEquity("SPY", Resolution.Daily);
            _spy = Securities["SPY"].Symbol;
            
            Bar = new RollingWindow<TradeBar>(2);
            BBWin = new RollingWindow<BollingerBandState>(2);
            
            _bb = BB(_spy, 30, 2);
        }

        public void OnData(TradeBars data)
        {
        	Bar.Add(data[_spy]);
        	BBWin.Add(new BollingerBandState(_bb));
            
            if (!Bar.IsReady) return;
            
            if (Bar[0].Close < BBWin[0].UpperBand  && Bar[1].Close > BBWin[1].UpperBand && !Portfolio.HoldStock) 
            {
            	SetHoldings(_spy, 1);
            }
        }
    }
    
    // class to hold the current state of a bollinger band instance
    public class BollingerBandState
    {
    	public readonly decimal UpperBand;
        public readonly decimal MiddleBand;
        public readonly decimal LowerBand;
        public readonly decimal StandardDeviation;
        public BollingerBandState(BollingerBands bb)
        {
            UpperBand = bb.UpperBand;
            MiddleBand = bb.MiddleBand;
            LowerBand = bb.LowerBand;
            StandardDeviation = bb.StandardDeviation;
        }
    }
}