Back

How to apply two indicators on two different bars?

I am new to QuantConnect and I am trying to determine how to write an algorithm that deploys two indicators on two different bars. In my case I would like to use 15 minute bars, where the stochastic indicator is applied to the most recently completed 15 minute bar (let's call it bar -1), while the RSI indicator should be calculated from the currently developing 15 minute bar (bar 0). Is there a way to accomplish this?

Update Backtest








You could use a TradeBarConsolidator. The consolidator subscribes to the price data and then in the DataConsolidated event, you manually update your indicators. If you want to manually update an indicator, just create it with a standard constructor:

var rsi = new RelativeStrengthIndictor(etc, etc)

...and avoid using the factory method:

var rsi = RSI(etc, etc))

0

We can apply two indicators with data from 2 or more different bars. Like James said above, you will need to manually update the indicators. In order to choose which bar updates a given indicator, one option is to keep the history of bars in a rolling window:

private RollingWindow<TradeBar> _win;

For instance, if we want to update the Stochastic with the previous bar, we can use:

// Updates Stochastic with the previous bar
_sto.Update(_win[1]);

Please checkout the attached project with the implementation.

Normally indicators are calculated when the bar is completed, so it is not straightfoward how we could calculate an indicator from the currently developing bar. We could, for instance, use an indicator with a higher frequency instead.

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.


Hi James & Alexandre,

Thanks for the ideas. I will definitely give that a whirl. I like the idea of using a rolling window. I am curious though, would it be possible to work on a Resolution.Tick basis and then when 16 minutes have passed to pass the accumulation of those ticks into a rolling window to build a 15 minute bar?

0

One more question on this. I am poking around the API and I am seeing a few different classes and properties that I am wondering if they could do the trick? If I were to use a Resolution.Tick for an equity, and then use the tickConsolidator to access the workgingBar property, would that allow me to build up a 15 minute current bar? Is there a way to specify a 15 minute window for the workingBar on the tickConsolidator? And once the workingBar has reached the 15 minute limit, could I then somewho add the workingBar to a RollingWindow? Does this approach make sense?

0

You could use the workingBar but it sounds like you just want a consolidated bar at a shorter resolution, which will produce more predictable results.

0

We can access WorkingBar from the TradeBarConsolidator, so we do not need to use the highest resolution data.
I don't know if anyone else has ever used this approach. Please give it a try.

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.


Hi Alexandre,

I tried the WorkingBar approach, but unfortunately that did not seem to go anywhere. I have been trying a few different approaches to see if I can somehow get an indicator to calculate a value based on the current pricing. I created a consolidator and then attempted to manually update a temporary version of the RSI indicator as a way to get a . However it does not seem to update the indicator properly. Could you take a look at my code and see what I could do to calculate the indicator from the currently developing bar?

0


Mitch Christow  Alexandre example updates the values for stochastic and rsi in the consolidator which is called every 15 min (15 min bar). Why not yours?

Your indicator gets updated every minute in the ondata which is called on the given resolution.....every minute.

https://www.quantconnect.com/forum/discussion/2931/boot-camp---interactive-tutorial-system
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