Newbie here:
I am trying to add a schedule function to the algo below and keep getting an error stating
TypeError: No method matches given arguments for AfterMarketOpen: (<class 'list'>, <class 'int'>)
or
TypeError: "No method matches given arguments for AfterMarketOpen: (, )
Will appreciate any help I can get on how to correctly schedule it.
The scheduling parameter I am trying to add are to trade:
- Every day market is open,
- 10 minutes after market opens.
See algo below
import numpy as np
from datetime import timedelta
from datetime import date, timedelta, datetime
#class RSIAlgorithm(QCAlgorithm):
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
self.SetStartDate(2020,6,1) # Set Start Date
self.SetCash(4000) # Set Strategy Cash
self.Equities = ["SPY","AMC","GME","SENS","AMSC","SNDL","HARP","EH","LOOP","QFIB","IDT",
"BB","BTX","RCON","BGFV","SBOW","EDRY","BBW","CELH","DDS","RRD",
"NOTV","UAN","JYNT","RFP","LOVE","NTP","RICK","SI","CMBM","DEN","CTRN",
"BNTX","TGLS","TGB","HYRE","BCRX","AVID","BBIG","WINT","DOCU"]
for Symbol in self.Equities:
self.AddEquity(Symbol, Resolution.Daily).Symbol
self.rsi = self.RSI(Symbol, 14, Resolution.Daily)
self.macd = self.MACD(Symbol, 12, 26, 9, Resolution.Daily)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen(self.Equities, 10), self.EveryDayAfterMarketOpen)
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
# Make sure we are not warming up
if self.IsWarmingUp: return
for Symbol in self.Equities:
print(self.Portfolio[Symbol].AveragePrice)
print(self.Portfolio[Symbol].Price)
print(self.Portfolio[Symbol].Quantity)
print(self.Portfolio.Cash)
Vested = self.Portfolio.Invested
Aveprica = self.Portfolio[Symbol].AveragePrice
Nowprica = self.Portfolio[Symbol].Price
Quantity = self.Portfolio[Symbol].Quantity
Bpower = self.Portfolio.Cash
Rsi = self.rsi.Current.Value
Macd =self.macd.Current.Value
#The perfect Swing set up is Adx > 20 and Rsi > 60 and Macd > 0 and Cci > 100:
if not Vested and Bpower > Nowprica and Rsi > 60 and Macd > 0:
self.MarketOrder(Symbol, 1)
self.Log(Aveprica)
if Vested and Rsi < 30 and Macd < 0:
self.SetHoldings(Symbol, 0)
else:
pass
Vladimir
Lemuel Mwangi,
Try this way
Lemuel Mwangi
Vladimir, I tried your suggestion above. However, on the backtest, it seems the algo is only trading the first symbol in the list (in the case above "SPY") and ignoring all the other symbols. I tried removing putting another symbol as the first one and the same thing happened.
Not sure why it is doing that.
Louis Szeto
Hi Lemuel
I think you need to use just 1 symbol instead of a list to set that, because not all symbol exchange open at same time.
You should use
If you wish to do it for multiple different opening time equity, you should call for few times
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.
Varad Kabade
Hi Lemuel Mwangi,
In the above algorithm, we are just instantiating a single indicator in the Initialize method. We have made the following changes to Vladimir's algorithm to resolve the issues:
1.Created a symbol Data class to store indicators of the assets
2.Checking whether we are invested in the particular asset instead of overall invested.
Refer to the attached backtest.
Best,
Varad Kabade
Lemuel Mwangi
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!