I'm trying to use an Indicator in combination with a RollingWindow as described here:
My project works with multiple tickers, so I don't have a simple self.symbol to refer to. In my Indicator update handler, I expected to be able to ask either the sender or the updated value which ticker it related to, but they are both returning emtpy strings.
I'm attaching a reduction that demonstrates the problem. I'm new to the platform so I don't rule out that I'm doing something wrong.
Derek Melchin
Hi Ralph,
It's not currently possible to get the symbol the indicator applies from inside the indicator's `Updated` handler. This is because the indicator object doesn't actually save the Symbol. For instance, when we create LogReturn indicator with the LOGR method, there is no Symbol object passed to the LogReturn constructor. See the source code here for reference.
A workaround is to manually create the LogReturn indicator and a daily consolidator, then we can register the indicator to receive automatic updates from the consolidator.
symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.logr = LogReturn(128) consolidator = TradeBarConsolidator(timedelta(days=1)) consolidator.DataConsolidated += self.consolidation_handler self.SubscriptionManager.AddConsolidator(symbol, consolidator) self.RegisterIndicator(symbol, self.logr, consolidator)
Accessing the symbol can then we done inside the `consolidation_handler`
def consolidation_handler(self, sender, bar): self.Plot("LOGR", str(bar.Symbol), self.logr.Current.Value)
See the attached backtest for reference.
Best,
Derek Melchin
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.
Ralph Zazula
OK. Thanks for the response.
Ralph Zazula
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!