Different results with updating indicator (by registering with a consolidator and by updating it in the event handler for consolidated bar)

I was following the instructions on getting the values from an indicator while using our consolidaor but I'm getting different results from what I believe to be equivalent programming code instructions. I'm using the CMO indicator as an example.

In the attached backtest, I have the following code

# access the 30 minute bar from the DataConsolidated events
        thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=30))

thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandle

self.cmo = self.CMO(self.symbol, period)

and in  the event handler

self.cmo.Update(bar.EndTime, bar.Close)

this provides me with a profit of 0.58%

but when I changed the code to

self.cmo.Update(bar.EndTime, bar.Close)

self.RegisterIndicator(self.symbol, self.cmo, thirtyMinuteConsolidator)

and remove the statemtn for manually updating in the consolidated, then I get him -2% loss.

I have seen both ways in the documentation and also in examples. Are these not equivalent? Thank you for any inputs

I cannot attach the second back test in this message for comparison. I hope that of the code can be changed by just cloning the algorithm making the modifications.

Update Backtest

This is the second back test which is providing me with -2% loss because of the code modifications described in the first message.



I looked at your backtests.

So in the first backtest you're not registering the indicator for which you want 30-minute consolidated data. Even though you're then calling the Update method on the indicator within your ThirtyMinuteBarHandler, my guess is that you're just updating it with minute data instead (the data frequency you're subscribed to) every 30 minutes. I think because the indicator is not registered, it doesn't understand it needs to consolidate any data.

I believe the examples you mention from the documentation refer to cases in which the indicator is manually updated using the Update method, but no consolidated data is required (data subscription is Daily and the indicator is also updated with daily data).

Second backtest uses the correct approach in my opinion.

I hope it helps and let's wait for other comments to confirm!



Thank you for your response and for taking the time to look at the backtests. When you mention that in the first back test, we may be updating the CMO with the 1 minute data, I wonder how is that possible?

self.cmo.Update(bar.EndTime, bar.Close)

The bar.EndTime and bar.Close are the parameters that pertain to the 30 minute bar. At least the value of bar.EndTime is being correctly printed out. 


Update Backtest


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.


This discussion is closed