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
-2.877
Tracking Error
0.044
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
import datetime

class CalmMagentaSnake(QCAlgorithm):
    
    def Initialize(self):
        #set timezone to ET
        self.SetTimeZone("America/New_York")
        self.SetStartDate(2017, 12, 1)
        self.SetEndDate(2017, 12, 31)
        self.SetCash(100000)
        
        self.openPeriod = 0
        self.closePeriod = 0
        
        #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))
        self.front_NQ = None

        #add equities to trade based on change in futures contract price
        self.TQQQ = self.AddEquity("TQQQ").Symbol
        self.SQQQ = self.AddEquity("SQQQ").Symbol
    
        #close out all open positions at market close
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose(self.TQQQ, 0), self.ClosePositions)
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose(self.SQQQ, 0), self.ClosePositions)

    def OnData(self, data):
        #filter for specific future contract data object
        for chain in data.FutureChains.Values:
            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.Contracts.Values))
                self.front_NQ = sorted(contracts, key = lambda x: x.Expiry)[0]
                #self.front_NQ = self.front_NQ.Symbol
        
        if self.front_NQ is None:
            return
        
        now = self.Time
        
        if now.hour == 9 and now.minute == 29:
            self.closePeriod = self.Securities[self.front_NQ.Symbol].Close
        
        if now.hour == 18 and now.minute == 00:
        #if now.hour == 16 and now.minute == 00:
            self.openPeriod = self.Securities[self.front_NQ.Symbol].Open
            
        if self.closePeriod == 0 or self.openPeriod == 0:
            return
    
        change = ((self.closePeriod - self.openPeriod) / self.openPeriod)*100
        
        if change >= 0.50:
            self.SetHoldings("TQQQ", 1)
            self.Debug("NQ OPEN: "+str(self.openPeriod)+" NQ Close: "+str(self.closePeriod)+" NQ Change: "+str(change))
            self.Debug(self.front_NQ)
            self.Debug("Sentiment is positive, buy TQQQ") 
            
        elif change < 0.50:
            self.SetHoldings("SQQQ", 1)
            self.Debug("NQ OPEN: "+str(self.openPeriod)+" NQ Close: "+str(self.closePeriod)+" NQ Change: "+str(change))
            self.Debug(self.front_NQ)
            self.Debug("Sentiment is negative, buy SQQQ")

    def ClosePositions(self):
        self.Liquidate()