Hi all,
I can't get this algo to start trade on Paper trading. Any idea why ? Backtest works fine, but when I deploy it Live and use broker Paper Trading it does not execute any trades at all.
# KOK 02-11-2021
# Trade setup with multiple tickers
# ------------------------------------------------------------------------------------
STOCKS = ["SE", "GMAB", "ZIM", "U", "CELH", "PYPL", "CVNA", "DOCU", "FUBO", "SQ", "SONO", "ROKU", "PFE", "MELI", "GS", "LMND", "MDB", "MRNA", "NIO", "DM", "NFLX", "AAPL", "MSFT", "GOOGL", "TX", "ABNB", "TSLA", "NVDA", "UPST", "CRWD", "NET", "SNOW", "MTTR", "GRVY"]; #
MA_F = 6; MA_S = 25; MA_50 = 60; FAST = 12; SLOW = 26; SIGN = 9; LEV = 0.95; RSI_Signal = 14
# ------------------------------------------------------------------------------------
class SimpleStockTrade_KOK(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 11, 1)
#self.SetEndDate(2021, 4, 1)
#self.SetCash(20000)
res = Resolution.Daily
#SMA setup
self.fast_sma = {}
self.slow_sma = {}
self.slowSMA_50 = {}
#MACD setup
self.macd = {}
self.signalDeltaPercent = {}
#RSI setup
self.rsi = {}
#Day count
self.daycount = {}
self.tolerence_exit = {}
self.stocks = [self.AddEquity(ticker, Resolution.Minute).Symbol for ticker in STOCKS]
for sec in self.stocks:
self.fast_sma[sec] = self.SMA(sec, MA_F, res)
self.slow_sma[sec] = self.SMA(sec, MA_S, res)
self.slowSMA_50[sec] = self.SMA(sec, MA_50, res)
self.macd[sec] = self.MACD(sec, FAST, SLOW, SIGN, MovingAverageType.Exponential, res)
self.rsi[sec] = self.RSI(sec, RSI_Signal, MovingAverageType.Simple, res)
self.daycount[sec] = 0
self.SetWarmUp(23400) # How to calculate this number ?
def OnData(self, data):
if self.IsWarmingUp: return
if self.Time.time() != time(9, 31): return
for sec in self.stocks:
if not (self.fast_sma[sec].IsReady) or not (self.slow_sma[sec].IsReady): continue
if not (self.macd[sec].IsReady): continue
self.signalDeltaPercent[sec] = (self.macd[sec].Current.Value - self.macd[sec].Signal.Current.Value)/self.macd[sec].Fast.Current.Value
if self.Portfolio[sec].Quantity <= 0:
if self.slow_sma[sec] < self.fast_sma[sec] and self.signalDeltaPercent[sec] > 0 and self.slow_sma[sec] > self.slowSMA_50[sec]:
self.SetHoldings(sec, LEV / 8)
elif self.Portfolio[sec].Quantity > 0 :
self.daycount[sec] = self.daycount[sec] + 1
if self.slow_sma[sec] > self.fast_sma[sec]:
self.Liquidate(sec)
Varad Kabade
Hi Karsten Ø. Kristensen,
We recommend adding the following in the Initialize method:
It's a good practice to add debug/log statements to algorithms running in the live mode so that we can understand its behavior and keep records to compare against backtests.
For further issues with live trading, please get in touch with support@quantconnect.com with the live deployment attached.
Best,
Varad Kabade
Karsten Ø. Kristensen
HI Varad,
Thank you very much for your feedback. Will modify and test again.
Best regards
Karsten
Karsten Ø. Kristensen
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!