Back

How to update several Rolling Windows with multiple TradeBarConsolidators ?

I am working on a strategy that uses multiple time frames of the VWAP indicator and I struggle to get the rolling window updated. For normal price bars, I get the first entry (current price) from the rolling window but strangely enough not the second, previous, one. 

The big hazzle is all about when using a TradeBarConsolidator for 10, 15, and 60 minutes. I get the VWAP updated, that seems to work, but for magic reasons, I cannot get the updated value in the rolling window.

I have tried updating the RollingWindow in the BarHandler, like so:

self.window_vwap_fifteen.Add(self.vwap_fifteen.Current)

However, that throws a runtime error:

Runtime Error: Trying to dynamically access a method that does not exist throws a TypeError exception.

Technically, I could use the scheduler to update the RollingWindow every 10 / 15 / 60 minute, but I am concerned that would not correctly time sync let alone it looks a like a pretty stupid solution. 

Is there a good way to update the rolling window(s) of an indicator on multiple timeframes? 

I really don't know what's so hard, so any help (in python) is appreciated. Backtest attached. 

Thanks in advance!

Marvin 

 

Update Backtest








0

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.


First of all, I don't see that you're doing any kind of checking of whether self.tradeBar_Window is ready. Your problem could be that you're trying to access index [1] before two samples have been pushed onto the window. I don't see why your other code shouldn't work.

I haven't used volume indicators before but an easier way to subscribe indicators directly onto consolidators would be the following lambda code in C#:

var vwap_ten = new VolumeWeightedAveragePriceIndicator(sym, VWAPPeriod);
var tenMinutesConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(10));
tenMinutesConsolidator.DataConsolidated += (sender, data) => { vwap_ten.Update(data) };

Not sure if the same can be achieved in Python though.

0

Thank you Douglas,

this is the weirdest part: when I add a check to test if tradeBar_Window is ready, the algo never executes so essentially the rolling window is never flipping the flag to ready. The attached backtests shows the issue in a comment. Therefore, I have disabled the check for now. 

Also, I register my indicators to auto-update like so:

# Register the consolidated bar data to automatically update the indicator 
# https://www.quantconnect.com/docs/algorithm-reference/indicators
  self.RegisterIndicator(self.sym, self.vwap_ten, tenMinutesConsolidator)

That seems to work. I am pretty sure there is a more functional / pythonic way but I stick with the working code base until I get the annoying bugs fixed. When I try the sample code from the documentation [1] to add an indicator to the rolling window, I get an AttributeError.

In a nutshell, there are multiple issues going on here so I have filed a ticket with the support to sort this out. Will post an update after I checked with them,

Anyway, thanks for your help.

[1] https://www.quantconnect.com/docs/algorithm-reference/rolling-window

 

 

0


SOLVED:

There is a sample backtest for FOREX, which I have adapted to my case.

https://www.quantconnect.com/forum/discussion/5616/error-consolidated-data-indicator-and-rolling-window

 

0

Update Backtest





0

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.


Loading...

This discussion is closed