Overall Statistics
Total Trades
114
Average Win
0.62%
Average Loss
-0.45%
Compounding Annual Return
12.759%
Drawdown
5.000%
Expectancy
0.199
Net Profit
5.115%
Sharpe Ratio
1.186
Probabilistic Sharpe Ratio
54.302%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
1.36
Alpha
0.026
Beta
0.28
Annual Standard Deviation
0.076
Annual Variance
0.006
Information Ratio
-1.265
Tracking Error
0.109
Treynor Ratio
0.321
Total Fees
$179.86
Estimated Strategy Capacity
$64000000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX
Portfolio Turnover
74.66%
# region imports
from AlgorithmImports import *
# endregion

class CasualRedOrangeBadger(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 1, 1)
        self.SetEndDate(2021, 6, 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)