| Overall Statistics |
|
Total Trades 230 Average Win 0.53% Average Loss -0.35% Compounding Annual Return 16.805% Drawdown 4.300% Expectancy 0.232 Net Profit 9.521% Sharpe Ratio 1.782 Probabilistic Sharpe Ratio 73.819% Loss Rate 51% Win Rate 49% Profit-Loss Ratio 1.53 Alpha 0.069 Beta 0.264 Annual Standard Deviation 0.065 Annual Variance 0.004 Information Ratio -0.646 Tracking Error 0.095 Treynor Ratio 0.44 Total Fees $332.09 Estimated Strategy Capacity $76000000.00 Lowest Capacity Asset QQQ RIWIV7K5Z9LX Portfolio Turnover 107.03% |
# region imports
from AlgorithmImports import *
# endregion
class CasualRedOrangeBadger(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 6, 1)
self.SetEndDate(2022, 1, 1)
self.SetCash(100000)
self.symbol = "QQQ"
self.AddEquity(self.symbol, Resolution.Hour)
self.AddEquity("PSQ",Resolution.Hour)
self.macd = self.MACD(self.symbol, 30, 150, 20)
self.macd.Updated+= lambda sender, updated:self.macd_windows.Add(self.macd.Histogram.Current.Value)
self.macd_windows = RollingWindow[float](2)
self.ema_30 = self.EMA(self.symbol, 30)
self.ema_120 = IndicatorExtensions.EMA(self.ema_30, 150)
self.psq_ema_30 = self.EMA("PSQ", 30)
self.psq_ema_120 = self.EMA("PSQ", 150)
self.psq_dif = IndicatorExtensions.Minus(self.psq_ema_30, self.psq_ema_120)
self.psq_dif.Updated += lambda sender, updated:self.psq_dif_window.Add(self.psq_dif.Current.Value)
self.psq_dif_window = RollingWindow[float](2)
self.stoch = self.STO(self.symbol, 20, 2, 10)
self.stoch_dif = IndicatorExtensions.Minus(self.stoch.StochK, self.stoch.StochD)
self.stoch_dif.Updated += lambda sender, updated:self.stoch_dif_window.Add(self.stoch_dif.Current.Value)
self.stoch_dif_window = RollingWindow[float](2)
self.dif = IndicatorExtensions.Minus(self.ema_30, self.ema_120)
self.dif.Updated+=self.UpdateDif
self.dif_window = RollingWindow[float](2)
self.PlotIndicator("EMA", self.ema_30,self.ema_120)
# self.Schedule.On(self.DateRules.EveryDay("QQQ"), self.TimeRules.BeforeMarketClose("QQQ"), lambda :self.Liquidate())
def OnData(self, data: Slice):
hour = self.Time.hour
self.Plot("MovingAverageConvergenceDivergence", "histogram", self.macd.Histogram.Current.Value)
for symbol, trade_bar in data.Bars.items():
self.Plot("Close","price",trade_bar.Close)
if self.dif_window.IsReady:
if self.dif_window[0]>self.dif_window[1]and self.dif_window[0]>0 and hour>10:
signal = 2
self.SetHoldings(self.symbol, 1)
elif self.stoch_dif_window[0]>self.stoch_dif_window[1] and self.stoch.StochK.Current.Value > self.stoch.StochD.Current.Value and hour>10 and self.dif_window[0]>0:
self.SetHoldings(self.symbol,1)
signal=0
else:
signal = -2
self.Liquidate()
self.Plot("IN_OUT","Signal",signal)
def UpdateDif(self,sender, updated):
self.dif_window.Add(self.dif.Current.Value)