Hi,
I am trying to write a strategy that works on multiple securities with the same strategy. Using the MACD-indicator on four different securities and if one of the four fits the condition, I want to buy an option for that security.
But everything one of the securities fits the condition, I buy options for all four securities instead of only one.
How do I select only the right security that fits the condition the entry a trade?
for symbol, macd in self.macd.items():
if macd.Current.Value < 0.5:
for symbol in self.symbols:
for kvp in data.OptionChains:
if kvp.Key == symbol:
chains = kvp.Value
self.BuyCall(chains)
Derek Melchin
Hi Alex,
Try the following snippet:
If that doesn't work, see Universes or attach a full backtest for more assistance.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Alex Veraart
Hi Derek, thanks for your reply.
Hereby the backtest. Instead of one order for one equity, I buy options for all equities every time.
Nico Xenox
Hey Alex Veraart,
I attached a backtest that trades the stocks that only pass the if statement above.
Hope it helps ;)
Alex Veraart
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!