Overall Statistics
Total Trades
55814
Average Win
0.01%
Average Loss
-0.02%
Compounding Annual Return
-57.922%
Drawdown
98.500%
Expectancy
-0.965
Net Profit
-98.478%
Sharpe Ratio
-11.745
Loss Rate
97%
Win Rate
3%
Profit-Loss Ratio
0.37
Alpha
-0.86
Beta
0.024
Annual Standard Deviation
0.073
Annual Variance
0.005
Information Ratio
-7.078
Tracking Error
0.143
Treynor Ratio
-35.495
Total Fees
$55814.00
using System;
using System.Linq;
using QuantConnect.Indicators;
using QuantConnect.Models;
using MathNet.Numerics;

namespace QuantConnect.Algorithm.Examples
{
    public class QCUMovingAverageCross : QCAlgorithm
    {
        private const string Symbol1 = "SPY";
        private const string Symbol2 = "DIA";
        public int myTimeFrame = 60;
        public decimal mySlippageValue = 0.0002m;

        
        public StandardDeviation stdDev;
        public SimpleMovingAverage mySMA;
        public List<double> myDataList1 = new List<double>();
        public List<double> myDataList2 = new List<double>();
       
        public override void Initialize()
        {
            SetStartDate(2012, 06, 01);
            SetEndDate(2017, 04, 01);
            SetWarmup(TimeSpan.FromMinutes(myTimeFrame));

            AddSecurity(SecurityType.Equity, Symbol1, Resolution.Minute);
            AddSecurity(SecurityType.Equity, Symbol2, Resolution.Minute);
            Securities[Symbol1].SlippageModel = new ConstantSlippageModel((decimal) mySlippageValue);
            Securities[Symbol2].SlippageModel = new ConstantSlippageModel((decimal) mySlippageValue);

            stdDev = new StandardDeviation(myTimeFrame);
            mySMA = new SimpleMovingAverage(myTimeFrame);
        }
        
        DateTime myDate;
        decimal myOpenPrice1;
        decimal myOpenPrice2;
        public void OnData(TradeBars data)
        {
        	if(this.Time != myDate)
        	{
        		myDate = this.Time;
        		myOpenPrice1 = data[Symbol1].Open;
        		myOpenPrice2 = data[Symbol2].Open;
        	}
        
        	var myDifference = Math.Abs(((myOpenPrice1 - data[Symbol1].Close) / myOpenPrice1) - (1.0m *((myOpenPrice2 - data[Symbol2].Close) / myOpenPrice2)));
        	stdDev.Update(this.Time, myDifference);
        	mySMA.Update(this.Time, myDifference);
        	
            if (!stdDev.IsReady || !mySMA.IsReady) return;


           
            if (!Portfolio.Invested)
            {
                if (Math.Abs(myDifference) > ((2 * stdDev) + Math.Abs(mySMA)))
                {
        		    
                    if(((myOpenPrice1 - data[Symbol1].Close) / myOpenPrice1) > (1.0m *((myOpenPrice2 - data[Symbol2].Close) / myOpenPrice2)))
                    {
                    	
                    	SetHoldings(Symbol1, .1); // +
                    	SetHoldings(Symbol2, -.1);
                    }
                    else
                    {
                    	
                    	SetHoldings(Symbol1, -.1);
                    	SetHoldings(Symbol2, .1); // +
                    }
                }
            }
            else
            {
            	if (Math.Abs(myDifference) < ((0.5m * stdDev) + Math.Abs(mySMA))){Liquidate();}
            }


        }
    }
}