Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-0.764
Tracking Error
0.147
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
import datetime

class CalmMagentaSnake(QCAlgorithm):
    
    openPeriod = 0
    closePeriod = 0

    def Initialize(self):
        #set timezone to ET
        self.SetTimeZone("America/New_York")
        
        #algo basics
        self.SetStartDate(2015, 1, 1)
        self.SetEndDate(2021, 12, 31)
        self.SetCash(100000)
        
        #add NASDAQ100 Emini future security object and filter to frontmonth only 
        self.NQ = self.AddFuture(Futures.Indices.NASDAQ100EMini, Resolution.Minute)
        self.NQ.SetFilter(timedelta(0), timedelta(90))
    
        #close out all open positions at market close
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose(self.NQ.Symbol, 0), self.ClosePositions)

    def OnData(self, data):
        #filter for specific future contract data object
        for chain in data.FutureChains:
            if chain.Key.Value == Futures.Indices.NASDAQ100EMini:
                if self.front_NQ is None or ((self.front_NQ.Expiry-self.Time).days <= 1):
                    contracts = list(filter(lambda x: x.Expiry >= self.Time + timedelta(days = 10), chain.Value))
                    self.front_NQ = sorted(contracts, key = lambda x: x.Expiry)[0]
                    self.front_NQ = self.front_NQ.Symbol
            
        now = datetime.datetime.now()
        
        if now.hour == 9 and now.minute == 30:
            self.closePeriod = self.Securities[self.front_NQ].Close
        
        if now.hour == 16 and now.minute == 00:
            self.openPeriod = self.Securities[self.front_NQ].Open
            
        if self.closePeriod == 0 or self.openPeriod == 0:
            return
    
        change = (self.closePeriod - self.openPeriod) / self.openPeriod

        if now.hour == 9 and now.minute == 31 and self.change >= 0:
            self.SetHoldings(self.front_NQ, 1)
        elif now.hour == 9 and now.minute == 31 and self.change < 0:
            self.SetHoldings(self.front_NQ, -1)
        
    def ClosePositions(self):
        self.Liquidate()