Back

Noob: Scheduling Event Error

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?

Update Backtest







0

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.


Can you paste the full scheduling code (i.e. lines 21-22)? You can attach a project if that makes it easier.

0

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.

0

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.


https://imagizer.imageshack.com/img924/2781/v7eyzW.png

 

0

Figured out I could screenshot and upload to imageshack!

0

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:

  1. 'pass' is not needed in .OnData(). It's mainly used as a placeholder for when the function is empty.
  2. 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.
  3. Don't forget the time rules argument in the scheduled function
  4. Python is case-sensitive. Make sure you check the upper/lower cases (i.e. 'usdcad', 'self.ema25,current.value')
  5. 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

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.

https://imagizer.imageshack.com/img923/9481/VmoTiO.png

 

0


Update Backtest





0

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...

This discussion is closed