Back

4hr history bars

I'm able to receive 4 hour bars using a consolidator and it works great. But i'd like to be able to grab 4 hour bars also.

If i use the History() call it works okay for 1 hour bars but how can i request 4 hour bar history?

Thanks.

Update Backtest







You can't get 1h bars as such via history or natively. You can however put them into a consolidator as well to get 4 h bars.

The main problem with the approach in QC is you might not get the bars other traders see (the devil is in the details), and if your algo is relying on the supposed behavior of other traders than that may be an issue or not.

0

Hi Petter. Thanks for your reply. I was actually able to receive 1hr history bars by calling;

    var history = History ( change.Symbol, m_backFillPeriod, Resolution.Hour );

And the iterating the bars with;

    foreach ( var data in history.OrderByDescending ( x => x.Time ).Take ( m_backFillPeriod ) ) {

But i'm not sure how to 'fill in' my indicator. I tried calling the Update() method on the indicator but it didn't work

E.g.

    myDnchianChannels[symbol].Update ( new IndicatorDataPoint ( data.EndTime, data.Close ) );

Note i'm using all of this for a real time algorithm not backtesting.

0

Update() should work when updating indicators on historical data. The algorithm below shows the indicator.Update() method working as expected while iterating through minute EURUSD data. In order to fix your issue try using data consolidators: feed the 1-hour history bars into to 4-hour consolidators and then have the indicators registered with the consolidated data bars.

0


@Gurumeher - Thanks yeah i understand how to use the consoloator. I can receive 4hr bars. My problem is that my real time algo. wants to have backfill data available E.g. last 100 bars. So far the best i can do is to call the history for 1hr bars which works Okay but then how do i get those into my indicator that's expecting 4hr bars?

0

So to clarify a bit i get the 4hr consolodated data via

var consolidator = new QuoteBarConsolidator ( TimeSpan.FromHours ( 4 ) );
consolidator.DataConsolidated += OnDataConsolidated;
SubscriptionManager.AddConsolidator ( contract.Symbol, consolidator );

And then i get a callback to

public void OnDataConsolidated ( object sender, QuoteBar quoteBar )

Which is good but how can i call History? I cannot call History from OnDataCosolidated as the quoteBar period is 4 hours and only hour bars are supported for history call

0

Ok so figured it out. Posting here in case anyone else has similar problem

It's super simple. Finding out how took some time. All you have to do is pass the trade bars returned via a history call to the consolodator. Then the OnDataConsolidated method will get called for each of the history bars. Simple and elegant.

// Get 100 hours of history and pump in into the consolidator

var history = History<TradeBar> ( contract.Symbol, 100, Resolution.Hour );
foreach ( TradeBar tradeBar in history ) {
consolidator.Update ( tradeBar );
}
1

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