Back

Using consolidated bars with indicators

I'm looking over some examples of how to consolidate bars. Inside the example "How Do I Use Consolidators" it shows how an event can be set up to trigger once per day while using minute resolution. I'm unsure about how I could use the consolidated bars with the indicators and then reference them minutely. I'm fairly new to QuantConnect and C# in general, having come from Quantopian its a bit of a learning curve.

Ideally what I'd like to do is have multuple indicators on multiple resolutions (10SMA, 20SMA, 14 RSI, etc, etc, and have each of the indicators work with 1min, 5min, 15min, 30min resolution) and have the entry/exit logic running every minute.

I appreciate any help or direction from somebody who might be in the knowhow here :)

Update Backtest








The procedure to add indicators to a consolidator to have them updated automatically with the desired resolution is:

private SimpleMovingAverage _sma;

// In Initialize
// Create Consolidator
var consolidator =
new TradeBarConsolidator(TimeSpan.FromMinutes(30));

// Create indicators
_sma = new SimpleMovingAverage(22);

// Register indicators to the consolidator
// to be updated at its frequency
RegisterIndicator("SPY", _sma, consolidator);

// Add the consolidator to the subscription
// manager to get updated with data from security
SubscriptionManager.AddConsolidator("SPY", consolidator);

If the goal is to create several indicators with multiple resolutions, we can put the above code snippet in a loop. Then we need to add the indicators to a dictionary to be able to access their values.

Please checkout the attached project for a working example.

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.


That's everything I need and then some, again, the help is much appreciated!

0

Another question... I need to access the previous value of an indicator. For example. at 10:00 I need the SMA of the 5min bars from 9:55-9:59. And, at 10:01 I'd still like to be able to access the bar from 9:55-9:59. I'm trying to save these in a variable like prev5minSMA at the end of the OnData loop but without some nasty code to check the minute on the clock or counters I'm stuck. I noticed in one example you could assign an event handler to the consolidator but for me to stick this in the "for" loop you provided I'd need to pass the minute to it as well I think?

Sorry if this all sounds a little sloppy, been a few years since I really dove into programming, especially with C#, thanks!

0

Currently, at the end of my OnData I've got something like this (if it helps you to understand my problem any)

if (prev_adx_5 != _adx[5]) prev_adx_5 = _adx[5];

The final goal is to check if two lines have crossed (DI Plus and DI Minus. Maybe theres a really simple answer to this but it's beyond me.

0

Also, I'd like to be able to check the slope of the lines (up or down). Sorry for all the consecutive posts but I seem unable to edit previous ones.

0

If you can please post new topics to new discussion threads -- this will help others find the topic later.

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.


Sorry, I figured since the topic was regarding consolidated bars and indicators it'd be appropriate here, I'll start a new thread.

0

We made this video to help with consolidators this morning; along with this blog post :)

https://www.quantconnect.com/blog/consolidators-data-build-bars/

https://www.youtube.com/watch?v=bbZy__qd1aA

 

1

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.


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