LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
I'm tried a million things but I can't fix this error
My line 20 is self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday
During the algorithm initialization, the following exception has occurred: AttributeError : 'ScheduledEventsAlgorithm' object has no attribute 'SpecificTime' at Initialize in main.py:line 20 AttributeError : 'ScheduledEventsAlgorithm' object has no attribute 'SpecificTime'
Any ideas?
Also is there an easy way to copy and paste my project code?
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.
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.
Adam W
3.8k Pro
,
Can you paste the full scheduling code (i.e. lines 21-22)? You can attach a project if that makes it easier.
0
Jack Simonson
Pro
,
Hi Michael,
Can you attach a code snippet or a backtest of your project as Adam mentioned? It will help us easily identify the issue and provide you with a solution.
Figured out I could screenshot and upload to imageshack!
0
Adam W
3.8k Pro
,
The function you are calling, .SpecificTime(), has to be an attribute of the base algorithm:
class ScheduledEventsAlgorithm(QCAlgorithm):
def Initialize(self):
self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday),
self.TimeRules.At(*arg) ## Don't forget this part
self.SpecificTime)
def SpecificTime(self):
if not self.Portfolio.Invested:
# Do something
There's also a couple of other issues here and small design tips:
'pass' is not needed in .OnData(). It's mainly used as a placeholder for when the function is empty.
You are subscribed to Tick-level data for USDCAD. This means that .OnData() will be called with every tick, and so you will be setting portfolio holdings to 50 units of USDCAD ~1000 times/second (with every tick). As soon as that scheduled function hits, with the next tick you are immediately back to 50 units.
Don't forget the time rules argument in the scheduled function
Python is case-sensitive. Make sure you check the upper/lower cases (i.e. 'usdcad', 'self.ema25,current.value')
For nested functions inside functions (like where SpecificTime is currently), you do not need the self argument though it is harmless to do so
1
Fireball
7.6k Pro
,
Thanks! I think I captured most of your comments. I have it running now, but no trades are excuting which makes me think I have something else fundamentally wrong. There should definitely be situations where the EMA 8 is above or belowthe EMA 55 for entry. Added the backtest and an image of code.
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.
Loading...
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!