Overall Statistics
Total Trades
66
Average Win
2.44%
Average Loss
-4.32%
Compounding Annual Return
-97.845%
Drawdown
63.600%
Expectancy
-0.427
Net Profit
-49.971%
Sharpe Ratio
-0.855
Probabilistic Sharpe Ratio
4.028%
Loss Rate
63%
Win Rate
37%
Profit-Loss Ratio
0.56
Alpha
-1.062
Beta
1.249
Annual Standard Deviation
1.068
Annual Variance
1.14
Information Ratio
-0.986
Tracking Error
1.047
Treynor Ratio
-0.731
Total Fees
$122.10
class FuturesMovingAverageCrossOverExample2(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2018, 1, 1)    #Set Start Date
        self.SetEndDate(2018, 3,6)      #Set End Date
        self.SetCash(100000)             #Set Strategy Cash
        self.SetTimeZone('America/Los_Angeles') # Set timezone
        self.reset = True
        self.SymbolData = { }
        self.limitOrderL = None
        self.stopMarketOrderL = None
        self.limitOrderS = None
        self.stopMarketOrderS = None
        futureES = self.AddFuture(Futures.Indices.SP500EMini)
        futureES.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(360))
        self.Schedule.On(self.DateRules.Every(DayOfWeek.Tuesday), self.TimeRules.At(9, 30), self.ScheduleDemo)
        
    def OnData(self, slice):
        # Reset any open positions based on a contract rollover.
        if self.reset:
            self.reset = False
            self.Log('RESET: closing all positions')
            self.Liquidate()
            
    def OnOrderEvent(self, orderEvent):
        if orderEvent == self.limitOrderL and self.stopMarketOrderL!= None:
            self.stopMarketOrderL.Cancel
        elif orderEvent == self.stopMarketOrderL and self.limitOrderL!= None:
            self.limitOrderL.Cancel
        elif orderEvent == self.limitOrderS and self.stopMarketOrderS!= None:
            self.stopMarketOrderS.Cancel   
        elif orderEvent == self.stopMarketOrderS and self.limitOrderS!= None:
            self.limitOrderS.Cancel
        
    def OnSecuritiesChanged(self, changes):
        for s in changes.AddedSecurities:
            if s.Symbol not in self.SymbolData:
                macd = self.MACD(s.Symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute)
                self.SymbolData[s.Symbol] = macd
                
    def ScheduleDemo(self):
        for symbol, assetData in self.SymbolData.items():
            price = self.ActiveSecurities[symbol].Price
            if assetData:
                signalDeltaPercent = (assetData.Current.Value - assetData.Signal.Current.Value)
                currentPrice = price
                tolerance = 0.003
                stopLossPrice = currentPrice - 100
                profitTargetPrice = currentPrice + 50
                holdings = self.Portfolio[symbol].Quantity
                if holdings <= 0 and signalDeltaPercent < 0 and signalDeltaPercent < -tolerance :
                    # Go long
                    self.MarketOrder(symbol, 1)
                    self.limitOrderL = self.LimitOrder(symbol, -1, profitTargetPrice)
                    self.stopMarketOrderL = self.StopMarketOrder(symbol, -1, stopLossPrice)
                if  holdings >= 0 and signalDeltaPercent > 0 and signalDeltaPercent > tolerance :
                    #Go short
                    self.MarketOrder(symbol, -1)
                    self.limitOrderS = self.LimitOrder(symbol, 1, profitTargetPrice)
                    self.stopMarketOrderS = self.StopMarketOrder(symbol, 1, stopLossPrice)