Overall Statistics |
Total Trades 2320 Average Win 0.54% Average Loss -0.36% Compounding Annual Return 39.081% Drawdown 27.200% Expectancy 0.099 Net Profit 96.194% Sharpe Ratio 1.393 Probabilistic Sharpe Ratio 65.365% Loss Rate 56% Win Rate 44% Profit-Loss Ratio 1.48 Alpha 0.266 Beta 0.105 Annual Standard Deviation 0.202 Annual Variance 0.041 Information Ratio 0.538 Tracking Error 0.241 Treynor Ratio 2.687 Total Fees $14041.53 Estimated Strategy Capacity $48000000.00 Lowest Capacity Asset QQQ RIWIV7K5Z9LX |
#region imports from AlgorithmImports import * #endregion # Trading QC Super Trend Indicator # -------------------------------------------- STOCK = "QQQ"; BAR = 1; SL = -0.0145; TP = 0.01; ATR = 1; MULT = 0.1; #wil m 0.2 and kama 0.16 spy 3 0.1.. A1M0.1 A2M0.2 A1M0.16 # -------------------------------------------- class SuperTrendIndicator(QCAlgorithm): def Initialize(self): self.SetStartDate(DateTime(2020, 5, 17, 9, 30, 0)) self.SetEndDate(DateTime(2022, 6, 1, 16, 0, 0)) self.SetCash(200000) res = Resolution.Hour #ATR = int(self.GetParameter("ATR_A")) #MULT = float(self.GetParameter("MULT_A")) self.stock = self.AddEquity(STOCK, res).Symbol consolidator = TradeBarConsolidator(timedelta(hours = BAR)) self.Consolidate(self.stock, timedelta(hours = BAR), self.BarHandler) self.st = SuperTrend(ATR, MULT, MovingAverageType.Kama) self.RegisterIndicator(self.stock, self.st, consolidator) self.heikin_ashi = self.HeikinAshi(STOCK, Resolution.Hour) self.RegisterIndicator(STOCK, self.heikin_ashi, consolidator) #self.mari= IndicatorExtensions.Of(self.st, self.heikin_ashi) # extension, uhhmmm self.SetWarmUp(5*BAR*ATR, res) #Close every friday #self.Schedule.On(self.DateRules.Every(DayOfWeek.Friday), self.TimeRules.At(16, 0), self.FridayClosed) #Liquidate at 10k loss #self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.Every(timedelta(minutes=10)), self.LiquidateUnrealizedLosses) #Close Every Friday #def FridayClosed(self): #self.Liquidate(self.stock) #self.Log(f"Friday at 4pm: Fired at: {self.Time}") #liquidate at 10k loss #def LiquidateUnrealizedLosses(self): # Liquidate any unrealized loss of over 10000 dollars or can use percentage of available funds, #if self.Portfolio.TotalUnrealizedProfit < -10000: #self.Log(f"Liquidated due to unrealized losses at: {self.Time}") #self.Liquidate() def BarHandler(self, consolidated): if self.IsWarmingUp: return if not self.st.IsReady: return if not self.heikin_ashi: return self.Plot(STOCK, "Price", self.Securities[self.stock].Price) self.Plot(STOCK, "Super Trend", self.st.Current.Value) #stop trading at 3:30 every Friday #stop_time = self.Time.replace(day=5, hour=15, minute=30, second=0) #if self.Time >= stop_time: #return pnl = self.Securities[self.stock].Holdings.UnrealizedProfitPercent if self.heikin_ashi.Current.Value > self.st.Current.Value: # Bullish self.SetHoldings(self.stock, 1, True, "Buy Signal") elif self.heikin_ashi.Current.Value < self.st.Current.Value: # Bearish self.SetHoldings(self.stock, -1, True, "Sell Signal") #self.Liquidate(self.stock, "Sell Signal") if self.Portfolio[self.stock].Invested: if pnl < SL: self.Liquidate(self.stock, "Stop Loss") #elif pnl > TP: #self.Liquidate(self.stock, "Take Profit") """ Examples Multiple Indicators https://www.quantconnect.com/forum/discussion/12143/help-with-strategy-execution/p1 FRAMA indicator FractalAdaptiveMovingAverage https://www.quantconnect.com/forum/discussion/7873/indicator-extension-help/p1 Rolling Window Example https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/RollingWindowAlgorithm.py Kalman Filter https://www.quantconnect.com/forum/discussion/12768/share-kalman-filter-crossovers-for-crypto-and-smart-rollingwindows/p1 https://www.quantconnect.com/forum/discussion/11788/another-digital-filter-laguerre-filter/p1 """