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 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
# region imports from AlgorithmImports import * from datetime import datetime import numpy as np # endregion class FatBlackHamster(QCAlgorithm): def Initialize(self): self.SetStartDate(2023, 1, 5) # Set Start Date self.SetEndDate(2023, 1, 7) # Set end date self.SetCash(100000) # Set Strategy Cash #Initialize SPY before using consolidator self.spy = self.AddEquity("SPY", Resolution.Minute).Symbol #Create rolling window with 2 indeces #self.rollingWindow = RollingWindow[TradeBar](2) # create consolidator for 2 minute, twoMinConsolidator = TradeBarConsolidator(timedelta(minutes=2)) #attach the event handler, which is a function that will be called each time we produce a new consolidated piece of data twoMinConsolidator.DataConsolidated += self.TwoMinBarHandler #This call adds the 2min consolidator to the manager to receive updates from the engine self.SubscriptionManager.AddConsolidator("SPY", twoMinConsolidator) #create SMA indicators self.sma5 = self.SMA(self.spy, 5) self.sma35 = self.SMA(self.spy, 35) #Register indicators self.RegisterIndicator("SPY", self.sma5, twoMinConsolidator) self.RegisterIndicator("SPY", self.sma35, twoMinConsolidator) #create array to use later to compare ewo candles self.array = [0,0] #Warm up sma indicators self.SetWarmup(timedelta(days=35), Resolution.Minute) self.SetBenchmark("SPY") def OnData(self, data: Slice): pass #if not self.IsWarmingUp: #if certain part of strategy: #self.Debug(str(self.array[0]) + ", " + str(self.array[1])) #self.Debug("Buy Long") #self.Debug(str(self.Time)) #elif other part of strategy: #self.Debug(str(self.array[0]) + ", " + str(self.array[1])) #self.Debug("Buy Short") #self.Debug(str(self.Time)) #self.Debug(self.rollingWindow[0]) def TwoMinBarHandler(self, sender, consolidated): #This is the event handler for 2min trade bar defined in Init(). Each time the consolidator produces a new #2 minute bar, this function will be called automatically. The 'sender' parameter will be the instance of the #IDataConsolidator that invoked the event, but will almost never need that #Add 2min info to rolling window (he had dif parameter) #self.rollingWindow.Add(consolidated) if not self.IsWarmingUp: #Make EWO value for current 2min window twoMinEWO = self.sma5.Current.Value - self.sma35.Current.Value #Throw it into array and pop value from 2 bars ago self.array.pop(0) self.array.append(twoMinEWO) #self.Debug(str(twoMinEWO)) #self.Debug(str(self.Time)) #self.Debug(str(self.sma5.Current.Value)) #self.Debug(str(self.sma35.Current.Value)) #self.Debug(str(self.array[0]) + ", " + str(self.array[1])) self.Plot("Benchmark", "5SMA", self.sma5.Current.Value) self.Plot("Benchmark", "35SMA", self.sma35.Current.Value)