Overall Statistics Total Trades10001Average Win0.01%Average Loss-0.01%Compounding Annual Return-99.998%Drawdown20.500%Expectancy-0.724Net Profit-20.485%Sharpe Ratio-25.288Probabilistic Sharpe Ratio0.200%Loss Rate91%Win Rate9%Profit-Loss Ratio2.06Alpha-9.459Beta0.387Annual Standard Deviation0.371Annual Variance0.138Information Ratio-25.621Tracking Error0.374Treynor Ratio-24.25Total Fees\$12338.08
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.previous = None

self.SetWarmUp(timedelta(days=20))

self.now = datetime.now()

def OnData(self, data):

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

# only once per day
#if self.previous is not None and self.previous.date() == self.Time.date():
#return
self.TimeRules.Every(TimeSpan.FromMinutes(60))

# define a small tolerance on our checks to avoid bouncing
tolerance = 0.00015
#holdings = self.Portfolio["SPXL", "TQQQ", "UDOW", "SPXS", "SDOW", "EDZ"].Quantity

#if holdings <= 0:
# we only want to go long if we're currently short or flat
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")

# we only want to liquidate if we're currently long
# if the fast is less than the slow we'll liquidate our long
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")

self.previous = self.Time