Back

Weekly momentum rotation

Was trying to modify an Algo, need it to enter trades weekly, and to add a moving average filter, if anyone can help, seems can't get data either.

Update Backtest








Thanks for attaching the code. After a few Debug() statements and tracking the data it looks like the data is being populated. Where the issue lies is the line currentWeek = Time.ToString("WWW") which seems to have substituted by currentMonth = Time.ToString("MMM"). By reading the C# documentation it looks like "WWW" is not a valid format string. "MMM" abbreviates the months but weeks can not be abbreviated. The link below shows the possible format strings. Once this issue is fixed, then the code will enter the conditional statement if(Time.ToString("WWW") != currentWeek). At the moment they are both equal to "WWW".

I advice using Debug statements to find errors like these. The bottom link points to the Documentation on using Log and Debug.

https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings

https://www.quantconnect.com/docs/algorithm-reference/logging-and-debug
0

Hi Gurumeher,



Yes I was trying to change it to weekly so just tried that format wasn’t sure if it would work.



How can we make it trade weekly?



Best,

Elsid
0

The algorithm can be tailored to trade weekly using a Scheduled Event. A function that executes the trades can be called during self.DateRules.Every(DayOfWeek.Monday). This will code will execute the scheduled event every Monday. This documentation goes into setting up a scheduled event in greater detail and this code is a good reference to see the scheduled event in the context of an entire algorithm. In this specific case, it is quite simple - some code will be shifted around into the scheduled event handler.

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