One day I had the need to make a custom indicator and have it work on the underlying and on it's option contracts, I had no idea how to do it, so I threw some stuff together and ended up with this.
The whole point of it is that we cannot subscribe to an option contract symbols because the atm symbol changes and will expire at some point. We want a seamless update of quotebars of whatever timeframe. That is why we manually update the indicator this way. I left it to calls only for the sake of simplicity and just a simple moving average cross to give you guys this framework. I also made the “updateIndicators” function for ease of use if we ever want to trade multiple symbols. If anyone finds a way to use a for loop for this let me know I'd like that.
Hope you guys enjoy, let me know any bugs or changes you see!
P.S. I added the Plot part after I recorded my YT video it is in this backtest though.
Check out my YouTube to see more videos like this:
Mia Alissi
Based on the provided code, it seems that 'Joseph' is trying to create a custom indicator for an underlying equity and its option contracts. He is using a
CustomIndicator
class, which is not defined in the provided code. However, it's likely that this class is a user-defined class that inherits from one of the base Indicator classes provided by QuantConnect.The
updateIndicators
function is declared but not implemented. This function is supposed to update the indicators with new data. In theOnData
method, he checks if there are any invested options that are too close to expiration and liquidates them if necessary. Then, he calls theupdateIndicators
function.Here are some potential issues and suggestions:
The
updateIndicators
function is not implemented. You need to implement this function to update your indicators with new data.The
CustomIndicator
class is not defined in the provided code. Make sure this class is correctly implemented and inherits from one of the base Indicator classes provided by QuantConnect.The
calls
variable in theupdateIndicators
function is declared but not used. You might want to remove it if it's not necessary.The
OnData
function checks if there are any invested options that are too close to expiration and liquidates them. However, it doesn't handle the case when there are no invested options. You might want to add some logic to handle this case.The
consolidator
andconsolidators
variables are declared but not used. If these are not necessary, consider removing them to clean up your code.The
atmCall
variable is declared but not used. If this is not necessary, consider removing it to clean up your code.Remember, this is just a preliminary review based on the provided code. There might be other issues that are not visible without the full context of your algorithm.
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.
Joseph Matteo Scorsone
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!