Overall Statistics Total Trades353Average Win2.96%Average Loss-0.55%Compounding Annual Return-9.995%Drawdown23.300%Expectancy0.093Net Profit-2.450%Sharpe Ratio0.241Probabilistic Sharpe Ratio35.257%Loss Rate83%Win Rate17%Profit-Loss Ratio5.41Alpha-0.41Beta-1.187Annual Standard Deviation0.748Annual Variance0.559Information Ratio0.529Tracking Error1.283Treynor Ratio-0.152Total Fees\$814.55
import decimal as d
from datetime import timedelta
import numpy
from datetime import datetime

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(2020, 1, 1)    #Set Start Date
self.SetEndDate(2020, 3, 26)      #Set End Date
self.SetCash(60000)             #Set Strategy Cash

#Simple moving average
self.sma = {}
self.sma[equity.Symbol] = self.SMA(equity.Symbol, 60, Resolution.Minute)

self.smas = {}
self.smas[equity.Symbol] = self.SMA(equity.Symbol, 100, Resolution.Minute)

self.fastest = self.TEMA("DIA", 15, Resolution.Minute)
# create a 13 day exponential moving average
self.fast = self.EMA("VOO", 5, Resolution.Daily)

# create a 48 day exponential moving average
self.slow = self.EMA("VOO", 10, Resolution.Daily)

self.SetWarmUp(timedelta(days=20))

self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.AfterMarketOpen("SPY", 1), self.EveryDayAfterMarketOpen)

def EveryDayAfterMarketOpen(self):

# wait for our slow ema to fully initialize
if self.IsWarmingUp: return

# define a small tolerance on our checks to avoid bouncing
tolerance = 0.00015

if self.fast.Current.Value > self.slow.Current.Value:
# if the fast is greater than the slow, we'll go long
self.SetHoldings("SPXL", .3, True)
self.SetHoldings("TQQQ", .5, True)
self.SetHoldings("UDOW", .2, True)
print("bull")

if self.slow.Current.Value > self.fast.Current.Value:
self.SetHoldings("SPXS", .3, True)
self.SetHoldings("SDOW", .2, True)
self.SetHoldings("EDZ", .5, True)
print("bear")