Back

Daily indicator being updated using minute data

I have a CCI5 indicator using daily data

var cci = CCI(symbol, 5,MovingAverageType.Simple,Resolution.Daily);

but would like to use minute data to update the cci before the market closes to make a buy decision using the updated value of cci.

How would I do that?
Update Backtest








I have to use consolidators, only found out after asking the question!
1

Yes you've got it :) please post your solution for others coming to the thread 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.


Well I thought I had it figured using a daily consolidator and use the WorkingBar on the cci to update its value.

var consolidator = consolidators [symboldata.Symbol];
cci.Update (consolidator.WorkingBar);


but it turned out the cci was already updated with the values from the day I was looking at?

The question is when does a daily indicator get updated when we are also using minute data coming in in OnData?

I thought it would have been updated at the end of day?
0

The thing with the consolidators is that they don't have their own concept of time other than the input data stream, because of this, the way we do daily consolidation is waiting for the day to tick over, which happens when we receive a new piece of data on the next day.

The expected behavior is that daily consolidators will run just before the first market open bar for the registered symbol. Check out the logs in the attached algorithm. You'll notice that at 9:31am we emit the daily consolidated bar from the previous day. If you need special consolidation logic or timing (maybe you want it to emit at 3:50pm every day) you can implement your own consolidator. Have a peak at the various built-in consolidators here.
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.


Ok, so basically we are looking at old data which makes sense.

So I tried to make the timespan 6.75 hours for the consolidator which is just before the market closes in the US which seems to work.

var dailyConsolidator = new TradeBarConsolidator(TimeSpan.FromHours(6.75));

I will dig further into this because there seems to an issue with the value of the indicator compared to historical values.
0

How about if you update your indicator at the 16:00 (4:00 PM) bar of your one minute OnData()? Here I do it at 3:50PM.

if (this.Time.Hour == 15 && this.Time.Minute > 49 || this.Time.Hour == 16)
{
cci.Update data[symbol];
}


Don't register your indicator. Granted you do not get the automatic behavior you get by registering the indicator, but that is your issue: registering the indicator does not give you the behavior you want.

You will have to check that the 9:31AM value does not change your manual update.
0

I've attached an example of using the scheduled events feature. In this example I update an EMA at 5 minutes after market open and again at 5 minutes before market close. Not sure what this indicator would be good for :/ but thought it demo'd this feature well enough.

This can help you avoid cluttering the OnData method with code intended to run once per day.
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 clever with the scheduled events.

With regards to not registering the indicator the downside is that I need to handle everything myself.

If you look at how say stockcharts is doing it I guess they have everything until today updated automatically and then as the day progresses just updates the last entry in the indicator thus changing the value as you want.

Since indicator.Update seems to add a day for a daily indicator I'm not sure how to actually replace the last entry in it.

I looked in IndicatorBase.cs and couldn't find a way to do that.

But maybe this is not so important for me anymore since the actual value of the indicator is getting less important. More important is that the price is going down and then I add to my position - this is for a mean reversion algorithm.

So I will monitor number of consequent daily losses instead of hooking up to a specific indicator value which doesn't work that well I think - overfitting, overoptimization etc.
0

Just as a note, the reason this isn't easy is because the indicator's are typically implemented 'on-line' this means as data pipes through it updates the internal state of the indicator, whereas it would seem stockcharts instead performs indicator math on an array of values in bulk, making it easy to constantly update the most recent entry. The downside to the bulk approach is it can be very inefficient for various indicators.

Also, I agree with making the algorithm not overly sensitive to indicator values, this typically leads to overfitting. I often find it's better to code against the 'shape' of the indicator vs the actual value of the indicator, looking for things like rising, falling, topping, bottoming and zero crossings (for oscillators).
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.


Anyway, after testing I found the following:

CCI5.Update (bar);

where bar is a TradeBar actually works.

I think I got confused because my historical data was not up to date.

One thing: can one clone an indicator.
var clone = CCI5.Clone()

?

Because then I would be sure this clone was just temporary and not saving any state that the CCI5 should keep.
0

If your CCI is only 5 values you could just maintain a rollingwindow of history and compute the value on each ondata call, that's what it sounds like what you want to do. just make a new CCI, pump it full of the data from the rolling window + the current data point.
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.


Yes, of course. The rollingwindow is really handy.

Thanks.
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