Overall Statistics
namespace QuantConnect 
{   
    /*
    *   QuantConnect University: How do I use a rolling window of data?
    *
    *   Our indicator library is a powerful collection of tools. Included in this collection is 
    *   the rolling window indicator for giving you easy access to a fixed length window of data.
    */
    public class QCURollingWindow : QCAlgorithm
    {
        RollingWindow<TradeBar> _window = new RollingWindow<TradeBar>(3600);
        private SimpleMovingAverage _smaRange;
        
        public override void Initialize()
        {
            SetStartDate(2013, 1, 1);         
            SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            SetCash(25000);
            AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute);
            _smaRange = SMA("SPY", 10, Resolution.Minute, x => Math.Abs(((TradeBar)x).Close - ((TradeBar)x).Open));
        }

        public void OnData(TradeBars data) 
        {   
            //Inject data into the rolling window.
            _window.Add(data["SPY"]);
            if (!_window.IsReady) return;
            
            var previousLow = _window[1].Low;
            var range = Math.Abs(data["SPY"].Close - data["SPY"].Open);
            if (range > 2 * _smaRange) {
            	Log("Abnormal bar size: " + range + ". Moving average: " + _smaRange);	
            }
            
            if (_window[0].Close > _window[3599].Close) {
                SetHoldings("SPY", -0.5);
            } else {
                SetHoldings("SPY", 0.5);
            }
        }
    }
}