First off all, credit goes to AlphAngel for the development of this implementation, which he or she did in C#. See the link to the original thread here. Managing futures indicators can be a complex task and I didn't find much on the forums so I did my best to replicate AlphAngel's implementation using Python. This implementation doesn't have any trading logic embedded but can be added relatively simply. Feel free to propose changes and update the code for anyone working with futures in Python.
Brian Weber
Hey Brian. Thank you for the code example. I have a few questions/comments:
How are you handling the rollover to the next contract? Does self._contract always get updated to the most recent contract to trade? For a day trading algorithm I think calling OnEndOfDay to Liquidate all positions is ideal. But I'm not not sure about the rollover since I'm printing to log when a contract should be expired, but self._contract and self._nextContract are still the same.
Also for entering trades and checking indicator logic, would you use specify this in the OnHour method?
Thanks for any help you can provide!
Brian Weber
I was able to get the futures contract to rollover successfully with this algorithm.
Brian Weber
Here is the code.
Brian Christopher
Brian Weber thanks, if you get it to work with different futures contracts please post it.
Brian Christopher
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!