Overall Statistics |
Total Trades 30 Average Win 0.14% Average Loss -0.11% Compounding Annual Return 0.067% Drawdown 0.400% Expectancy 0.045 Net Profit 0.074% Sharpe Ratio 0.121 Probabilistic Sharpe Ratio 16.090% Loss Rate 53% Win Rate 47% Profit-Loss Ratio 1.24 Alpha 0 Beta 0.002 Annual Standard Deviation 0.005 Annual Variance 0 Information Ratio -0.652 Tracking Error 0.294 Treynor Ratio 0.355 Total Fees $30.00 Estimated Strategy Capacity $160000000.00 |
class NadionResistanceShield(QCAlgorithm): #class DataConsolidationAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 1, 1) # Set Start Date self.SetEndDate(2021, 2, 1) self.SetCash(50000) # Set Strategy Cash self.tickers = ["SPY"] self.symbolDataBySymbol = {} self.trade = True # Before the open self.EnableAutomaticIndicatorWarmUp = True for symbol in self.tickers: self.AddEquity(symbol, Resolution.Hour) '''For the below 3 EMA's, you can convert them to 4H bars using the colidator method''' macd = self.MACD(symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Daily, Field.Close) ema10 = self.EMA(symbol, 10, Resolution.Hour, Field.Close) sma200 = self.SMA(symbol, 200, Resolution.Daily, Field.Close) sma20 = self.SMA(symbol, 20, Resolution.Daily, Field.Close) sma50 = self.SMA(symbol, 50, Resolution.Daily, Field.Close) sma7 = self.SMA(symbol, 7, Resolution.Hour, Field.Close) #sma7 = self.SMA(symbol, 7, Resolution.Minute, Field.Close) ema20 = self.EMA(symbol, 20, Resolution.Hour, Field.Close) ema7 = self.EMA(symbol, 7, Resolution.Hour, Field.Close) #ema7 = self.EMA(symbol, 7, Resolution.Minute, Field.Close) ema9 = self.EMA(symbol, 9, Resolution.Hour, Field.Close) rsi = self.RSI(symbol, 14, Resolution.Daily) wilr_up = self.WILR(symbol, 10, Resolution.Daily) wilr = self.WILR(symbol, 14, Resolution.Daily) atr = self.ATR(symbol, 14, Resolution.Daily) self.atr=[] for i in self.tickers: self.atr.append(self.ATR(i, 14)) '''Consolidator method''' smaConsolidate = ExponentialMovingAverage(20, MovingAverageType.Simple) # create the 4 hour data consolidator fourHourConsolidator = TradeBarConsolidator(timedelta(hours=4)) self.SubscriptionManager.AddConsolidator(symbol, fourHourConsolidator) # register the 4 hour consolidated bar data to automatically update the indicator self.RegisterIndicator(symbol, smaConsolidate, fourHourConsolidator) #self.Schedule.On(self.DateRules.EveryDay(self.tickers), #self.TimeRules.AfterMarketOpen(self.tickers, -5), # Action(self.beforeTheOpen)) symbolData = SymbolData(symbol, ema10, sma200, sma20, sma50, sma7, ema20, ema7, ema9, rsi, wilr, wilr_up, atr, smaConsolidate) self.symbolDataBySymbol[symbol] = symbolData def beforeTheOpen(self): for i in range(len(self.tickers)): continue self.Log("ATR: {0}".format(self.atr[i].Current.Value)) self.spy = self.AddEquity("SPY", Resolution.Daily) # Before the open #self.Schedule.On(self.DateRules.EveryDay(self.tickers), # self.TimeRules.AfterMarketOpen(self.tickers, -5), # Action(self.beforeTheOpen)) #set the following between 1 - 4 hours depending on buy frequency self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.Every(timedelta(hours=2)), self.buySignals) self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.Every(timedelta(hours=2)), self.sellSignals) self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.AfterMarketOpen("SPY"), self.tradeStart) self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.BeforeMarketClose("SPY"), self.tradeEnd) #self.AddRiskManagement(TrailingStopRiskManagementModel(0.03)) self.SetWarmUp(timedelta(days=50)) def tradeStart(self): self.trade = True def tradeEnd(self): self.trade = False def buySignals(self): if self.trade == False: self.stopBuyPrice = self.spy.Close + 3 self.stopLossPrice = self.stopBuyPrice - 10 self.profitTarget1 = self.stopBuyPrice + 10 self.profitTarget2 = self.stopBuyPrice + 20 return for symbol, symbolData in self.symbolDataBySymbol.items(): #if not self.Portfolio[symbol].Invested and (self.Securities[symbol].Close > symbolData.ema7.Current.Value) and (symbolData.ema7.Current.Value > symbolData.atr.Current.Value) and (symbolData.sma20.Current.Value > symbolData.sma50.Current.Value): # self.SetHoldings(symbol, .1, False, "Buy Signal") if not self.Portfolio[symbol].Invested and (self.Securities[symbol].Close > symbolData.sma200.Current.Value) and (symbolData.wilr.Current.Value < symbolData.wilr_up.Current.Value) and (symbolData.rsi.Current.Value < 30): self.SetHoldings(symbol, .1, False, "Buy Signal") # def sellSignals(self): if self.trade == False: return for symbol, symbolData in self.symbolDataBySymbol.items(): if self.Portfolio[symbol].Invested and (self.Securities[symbol].Close < symbolData.sma7.Current.Value): self.Liquidate(symbol, "Sell Signal") class SymbolData: def __init__(self, symbol, ema10, sma200, sma20, sma50, sma7, ema20, ema7, ema9, rsi, wilr, wilr_up, atr, smaConsolidate): self.Symbol = symbol self.ema10 = ema10 self.sma200 = sma200 self.sma20 = sma20 self.sma50 = sma50 self.sma7 = sma7 self.ema20 = ema20 self.ema7 = ema7 self.ema9 = ema9 self.rsi = rsi self.wilr = wilr self.wilr_up = wilr_up self.atr = atr #self.emaConsolidate = emaConsolidate self.smaConsolidate = smaConsolidate