Overall Statistics
Total Trades
77958
Average Win
0.03%
Average Loss
-0.01%
Compounding Annual Return
20.363%
Drawdown
24.300%
Expectancy
0.180
Net Profit
145.909%
Sharpe Ratio
4.974
Loss Rate
60%
Win Rate
40%
Profit-Loss Ratio
1.95
Alpha
0.151
Beta
0.011
Annual Standard Deviation
0.031
Annual Variance
0.001
Information Ratio
0.402
Tracking Error
0.118
Treynor Ratio
13.991
Total Fees
$163752.44
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 = "VXX";
        private const string Symbol2 = "TVIX";
        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, 07);
            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) - (.5m *((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) > (.5m *((myOpenPrice2 - data[Symbol2].Close) / myOpenPrice2)))
                    {
                    	
                    	SetHoldings(Symbol1, .05); // +
                    	SetHoldings(Symbol2, -.1);
                    }
                    else
                    {
                    	
                    	SetHoldings(Symbol1, -.05);
                    	SetHoldings(Symbol2, .1); // +
                    }
                }
            }
            else
            {
            	if (Math.Abs(myDifference) < ((0.5m * stdDev) + Math.Abs(mySMA))){Liquidate();}
            }


        }
    }
}