Overall Statistics |
Total Trades 6 Average Win 1.37% Average Loss 0% Compounding Annual Return -6.493% Drawdown 4.100% Expectancy 0 Net Profit -1.043% Sharpe Ratio -0.506 Probabilistic Sharpe Ratio 24.894% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha -0.057 Beta 0.058 Annual Standard Deviation 0.101 Annual Variance 0.01 Information Ratio -0.967 Tracking Error 0.166 Treynor Ratio -0.877 Total Fees $9.00 |
# I schedule signal Before trade - Say 8AM # I schedule trade after market open - Say 10AM # I need daily indicators updated for signal before trade class IndicatorsTest(QCAlgorithm): def Initialize(self): self.SetStartDate(2021,1,1) self.SetEndDate(2021,2,28) self.SetCash(100000) self.QQQ = self.AddEquity("QQQ", Resolution.Daily).Symbol self.TickerTable = {} self.rsi = self.RSI(self.QQQ, 14, MovingAverageType.DoubleExponential, Resolution.Daily) self.rsiSMA = IndicatorExtensions.SMA(self.rsi,14) self.macd = self.MACD(self.QQQ, 12,26,9,MovingAverageType.Exponential, Resolution.Daily) self.macdSMA = IndicatorExtensions.SMA(self.macd,9) self.rc = self.RC(self.QQQ,12, 2, Resolution.Daily) self.ppo = self.PPO(self.QQQ, 10,12, MovingAverageType.Exponential, Resolution.Daily) self.ppoSMA = IndicatorExtensions.SMA(self.ppo,10) self.sma = self.SMA(self.QQQ,50,Resolution.Daily) # symbolData = SymbolData(self.QQQ, rsi, rsiSMA, macd, macdSMA, rc, ppo, ppoSMA,sma) # self.TickerTable[self.QQQ] = symbolData self.Log(f"{self.Time}, Price, RSI, RSI_SMA, PPO, PPO_SMA, SLOPE, MACD, MACD_SMA, HIST, SMA") self.SetWarmUp(timedelta(days=120)) # Minimum should be RSI period X 2 + 1 # --------------------------------------------------- Schedules -------------------------------------------- # self.Schedule.On(self.DateRules.EveryDay("QQQ"),self.TimeRules.At(8,0), self.LogIndicator) # We update the indicators in OnData instead of in this scheduled event. self.Schedule.On(self.DateRules.EveryDay("QQQ"),self.TimeRules.AfterMarketOpen("QQQ",30), self.Trade) # FYI, you can use -30 if you want to send an order before Market opens. # ------------------------------------------------- On Data ----------------------------------------------------- def OnData(self, data): if self.IsWarmingUp: return # Indicators will be updated every time OnData is run, which is everytime it is fed new data. self.QQQ_RSI = self.rsi.Current.Value self.QQQ_RSI_SMA = self.rsiSMA.Current.Value self.QQQ_PPO = self.ppo.Current.Value self.QQQ_PPO_SMA = self.ppoSMA.Current.Value self.QQQ_MACD = self.macd.Current.Value self.QQQ_MACD_SMA = self.macdSMA.Current.Value self.QQQ_MACD_Signal = self.macd.Signal.Current.Value self.QQQ_MACD_Histogram = self.macd.Histogram.Current.Value self.QQQ_SLOPE = self.rc.Slope.Current.Value self.QQQ_SMA = self.sma.Current.Value self.Log(f"Before Trade: {self.Time}, {self.Securities[self.QQQ].Price}, {self.QQQ_RSI}, {self.QQQ_RSI_SMA}, {self.QQQ_PPO}, {self.QQQ_PPO_SMA}, {self.QQQ_SLOPE}, {self.QQQ_MACD}, {self.QQQ_MACD_SMA}, {self.QQQ_MACD_Histogram}, {self.QQQ_SMA}") # Alternatively, you can also place the trade logic here: self.Trade() # ----------------------------------------- Trade After Market open------------------------------------------ def Trade(self): self.Log("Trading logic and execution here") if self.QQQ_RSI < 30: self.SetHoldings(self.QQQ, 1) else: self.Liquidate() # self.QQQ_RSI = self.TickerTable[self.QQQ].Rsi.Current.Value # self.QQQ_RSI_SMA = self.TickerTable[self.QQQ].RsiSMA.Current.Value # self.QQQ_PPO = self.TickerTable[self.QQQ].Ppo.Current.Value # self.QQQ_PPO_SMA = self.TickerTable[self.QQQ].PpoSMA.Current.Value # self.QQQ_MACD = self.TickerTable[self.QQQ].Macd.Current.Value # self.QQQ_MACD_SMA = self.TickerTable[self.QQQ].MacdSMA.Current.Value # self.QQQ_MACD_Signal = self.TickerTable[self.QQQ].Macd.Signal.Current.Value # self.QQQ_MACD_Histogram = self.TickerTable[self.QQQ].Macd.Histogram.Current.Value # self.QQQ_SLOPE = self.TickerTable[self.QQQ].Rc.Slope.Current.Value # self.QQQ_SMA = self.TickerTable[self.QQQ].Sma.Current.Value # self.Log(f"Trade open: {self.Time}, {self.Securities[self.QQQ].Price}, {self.QQQ_RSI}, {self.QQQ_RSI_SMA}, {self.QQQ_PPO}, {self.QQQ_PPO_SMA}, {self.QQQ_SLOPE}, {self.QQQ_MACD}, {self.QQQ_MACD_SMA}, {self.QQQ_MACD_Histogram}, {self.QQQ_SMA}") # ----------------------------------------- Log Indicators Before Market Open-------------------------------- # def LogIndicator(self): # # I NEED TO UPDATE INDICATORS HERE - Before trade # self.QQQ_RSI = self.TickerTable[self.QQQ].Rsi.Current.Value # self.QQQ_RSI_SMA = self.TickerTable[self.QQQ].RsiSMA.Current.Value # self.QQQ_PPO = self.TickerTable[self.QQQ].Ppo.Current.Value # self.QQQ_PPO_SMA = self.TickerTable[self.QQQ].PpoSMA.Current.Value # self.QQQ_MACD = self.TickerTable[self.QQQ].Macd.Current.Value # self.QQQ_MACD_SMA = self.TickerTable[self.QQQ].MacdSMA.Current.Value # self.QQQ_MACD_Signal = self.TickerTable[self.QQQ].Macd.Signal.Current.Value # self.QQQ_MACD_Histogram = self.TickerTable[self.QQQ].Macd.Histogram.Current.Value # self.QQQ_SLOPE = self.TickerTable[self.QQQ].Rc.Slope.Current.Value # self.QQQ_SMA = self.TickerTable[self.QQQ].Sma.Current.Value # self.Log(f"Before Trade: {self.Time}, {self.Securities[self.QQQ].Price}, {self.QQQ_RSI}, {self.QQQ_RSI_SMA}, {self.QQQ_PPO}, {self.QQQ_PPO_SMA}, {self.QQQ_SLOPE}, {self.QQQ_MACD}, {self.QQQ_MACD_SMA}, {self.QQQ_MACD_Histogram}, {self.QQQ_SMA}") # ---------------------------------------------- SymbolData -------------------------------------------------- # class SymbolData: # def __init__(self, symbol, rsi, rsiSMA, macd, macdSMA, rc, ppo, ppoSMA, sma): # self.Symbol = symbol # self.Rsi = rsi # self.RsiSMA =rsiSMA # self.Macd = macd # self.MacdSMA = macdSMA # self.Rc = rc # self.Ppo = ppo # self.PpoSMA = ppoSMA # self.Sma = sma