Overall Statistics Total Trades120Average Win0.31%Average Loss-0.23%Compounding Annual Return-13.839%Drawdown6.600%Expectancy-0.097Net Profit-2.246%Sharpe Ratio-1.241Loss Rate61%Win Rate39%Profit-Loss Ratio1.34Alpha-0.151Beta0.059Annual Standard Deviation0.111Annual Variance0.012Information Ratio-2.082Tracking Error0.176Treynor Ratio-2.314Total Fees\$554.80
```using System;
using System.Linq;
using QuantConnect.Indicators;
using QuantConnect.Models;

namespace QuantConnect.Algorithm.Examples
{
/// <summary>
///
/// QuantConnect University: EMA + SMA Cross
///
/// In this example we look at the canonical 20/50 day moving average cross. This algorithm
/// will go long when the 20 crosses above the 50 and will liquidate when the 20 crosses
/// back below the 50.

// -------VATS CHANGES -----------
// 2) 1/50 period SMA cross
//
// -------VATS CHANGES -----------

/// </summary>

public class SMACross_test2 : QCAlgorithm
{
private const string Symbol = "SPY";

private SimpleMovingAverage fast;
private SimpleMovingAverage slow;

public override void Initialize()
{
SetStartDate(2016, 06, 01);
//SetEndDate(2015, 12, 31);
SetCash(100000);
Transactions.MarketOrderFillTimeout = TimeSpan.FromMinutes(10);

// define our daily trade bar consolidator. we can access the daily bar
// from the DataConsolidated events, this consolidator can only be used
// for a single symbol!

// attach our event handler. the event handler is a function that will be called each time we produce
// a new consolidated piece of data.
minConsolidator.DataConsolidated += OnFiveMinutes;

int fastPeriod = 2;
int slowPeriod = 4;
fast = new SimpleMovingAverage(Symbol + "_SMA_" + fastPeriod, fastPeriod);
slow = new SimpleMovingAverage(Symbol + "_SMA_" + slowPeriod, slowPeriod);

// we need to manually register these indicators for automatic updates
RegisterIndicator(Symbol, fast, minConsolidator);
RegisterIndicator(Symbol, slow, minConsolidator);
}

private void OnFiveMinutes(object sender, TradeBar consolidated)
{
_spyMinutes = consolidated;
//Log(consolidated.Time.ToString("o") + " >> " + Symbol  + ">> LONG  >> 100 >> " + Portfolio[Symbol].Quantity);

}

private DateTime previous;
{
// if you want code to run every five minutes then you can run it inside of here

// only once per day
// Commented the following line to simulate intraday - Vats
//if (previous.Date == data.Time.Date) return;

// in OnData, returns outside of 9am - 2pm
//if (Time.Hour <= 9 || Time.Hour > 16) return;

const decimal tolerance = 0 * 0.10000m;
var holdings = Portfolio[Symbol].Quantity;
Log(data[Symbol].Price + "//" + fast + "//" + slow);

{
if (fast > slow * (1 + tolerance))
{
if (holdings <= 0)
{
// Log (System.DateTime.Now.Hour.ToString()) ;
// Log("BUY  >> " + holdings + "@ price " + Securities[Symbol].Price);
SetHoldings(Symbol, 1);
// Log("NET POSITION BEFORE NEXT TRANSACTION >> " + holdings);
}
}

if (fast < slow)
{
if (holdings > 0)
{
//Log (System.DateTime.Now.Hour.ToString()) ;
//Log("SELL >> " + holdings + "@ price " + Securities[Symbol].Price);
SetHoldings(Symbol, -1);
//Liquidate(Symbol);
}
}
}

}