Overall Statistics
Total Trades
3244
Average Win
0.05%
Average Loss
-0.07%
Compounding Annual Return
-0.443%
Drawdown
11.800%
Expectancy
-0.063
Net Profit
-1.888%
Sharpe Ratio
-0.046
Loss Rate
46%
Win Rate
54%
Profit-Loss Ratio
0.72
Alpha
-0.016
Beta
0.098
Annual Standard Deviation
0.059
Annual Variance
0.003
Information Ratio
-1.13
Tracking Error
0.126
Treynor Ratio
-0.027
Total Fees
$3244.00
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);
            }
        }
    }
}