Overall Statistics Total Trades329Average Win2.96%Average Loss-0.09%Compounding Annual Return31.362%Drawdown4.300%Expectancy8.444Net Profit14.460%Sharpe Ratio3.209Loss Rate72%Win Rate28%Profit-Loss Ratio33.00Alpha0.481Beta-10.324Annual Standard Deviation0.086Annual Variance0.007Information Ratio2.976Tracking Error0.086Treynor Ratio-0.027Total Fees\$361.88
```import clr
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
import decimal as d
import math
import numpy as np
import pandas as pd
import statistics
from datetime import datetime, timedelta

class MovingAverageCrossAlgorithm(QCAlgorithm):

def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

self.SetStartDate(2017,9,9) #Set Start Date
self.SetEndDate(2018,3,8)   #Set End Date
self.SetCash(100000)             #Set Strategy Cash
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)

# Find more symbols here: http://quantconnect.com/data

# create exponential moving averages
self.SPY = self.EMA("SPY", 18, Resolution.Daily);
self.X = self.EMA("X", 15, Resolution.Daily);
self.TBF = self.EMA("TBF", 21, Resolution.Daily);
self.SHAK = self.EMA("SHAK", 50, Resolution.Daily);
self.HAL = self.EMA("HAL", 21, Resolution.Daily);

self.previous = None

def OnData(self, data):

#Define a small tolerance on our checks to avoid bouncing
tolerance = 0.007;

#SPY
if self.Securities["SPY"].Price > self.SPY.Current.Value * d.Decimal(1 + tolerance):
cash = self.Portfolio.Cash * d.Decimal(0.30)
number_of_shares = (cash/self.Securities["SPY"].Price)
self.MarketOrder("SPY", number_of_shares)

if self.Securities["SPY"].Price < self.SPY.Current.Value * d.Decimal(1 - tolerance):
self.Liquidate("SPY")

#X
if self.Securities["X"].Price > self.X.Current.Value * d.Decimal(1 + tolerance):
cash2 = self.Portfolio.Cash * d.Decimal(0.15)
number_of_shares2 = (cash2/self.Securities["X"].Price)
self.MarketOrder("X", number_of_shares2)

if self.Securities["X"].Price < self.X.Current.Value * d.Decimal(1 - tolerance):
self.Liquidate("X")

#TBF
if self.Securities["TBF"].Price > self.TBF.Current.Value * d.Decimal(1 + tolerance):
cash3 = self.Portfolio.Cash * d.Decimal(0.34)
number_of_shares3 = (cash3/self.Securities["TBF"].Price)
self.MarketOrder("TBF", number_of_shares3)

if self.Securities["TBF"].Price < self.TBF.Current.Value * d.Decimal(1 - tolerance):
self.Liquidate("TBF")

#SHAK
if self.Securities["SHAK"].Price > self.SHAK.Current.Value * d.Decimal(1 + tolerance):
cash4 = self.Portfolio.Cash * d.Decimal(0.07)
number_of_shares4 = (cash4/self.Securities["SHAK"].Price)
self.MarketOrder("SHAK", number_of_shares4)

if self.Securities["SHAK"].Price < self.SHAK.Current.Value * d.Decimal(1 - tolerance):
self.Liquidate("SHAK")

#HAL
if self.Securities["HAL"].Price > self.HAL.Current.Value * d.Decimal(1 + tolerance):
cash5 = self.Portfolio.Cash * d.Decimal(0.12)
number_of_shares5 = (cash5/self.Securities["HAL"].Price)
self.MarketOrder("HAL", number_of_shares5)

if self.Securities["HAL"].Price < self.HAL.Current.Value * d.Decimal(1 - tolerance):
self.Liquidate("HAL")

self.previous = self.Time```