Back

RegisterIndicator returns error " "This is a forward only indicator" when following example in docs

I was following the example given in the docs:

# request the daily equity data
self.AddEquity("SPY", Resolution.Daily)
# define a 10-period RSI indicator with indicator constructor
self.rsi = RelativeStrengthIndex(10, MovingAverageType.Simple)
# register the daily data of "SPY" to automatically update the indicator
self.RegisterIndicator("SPY", self.rsi, Resolution.Daily)

https://www.quantconnect.com/docs/algorithm-reference/indicators#Indicators-Indicator-Ready

And on the same lines, I added this code

self.adx = self.ADX(self.symbol, self.adx_period)

self.RegisterIndicator(self.symbol, self.adx, Resolution.Daily)

 

However, this returns an error

Runtime Error: This is a forward only indicator: ADX(IWM_min) Input: 2017-02-01 00:00:00Z Previous: 2017-02-02 09:30:00Z (Open Stacktrace)

(the date 2017-02-01 is because the start date is 2017-01-01)

 

But when I added this code

self.adx = self.ADX(self.symbol, self.adx_period, Resolution.Daily), I start getting values of ADX - which do not seem to be entirely accurate, but that is another story

This also produces some output of ADX

self.adx = self.ADX(self.symbol, self.adx_period, Resolution.Daily)

self.RegisterIndicator(self.symbol, self.adx, Resolution.Daily)

 

So which one is the recommended usage?

Update Backtest







In the Custom Period Indicators, we can read:
"In this method, you will recreate the basic indicator usage: create an indicator with its constructor and register the indicator for automatic updates with the RegisterIndicator() method."
It means, that you cannot use the two methods together like this:

self.adx = self.ADX(self.symbol, self.adx_period, Resolution.Daily)
self.RegisterIndicator(self.symbol, self.adx, Resolution.Daily)

because you would be updating self.adx with two consolidators. One is created by a self.RegisterIndicator call inside self.ADX and another one is the second statement in the snippet below.

The recommended method is Basic Indicator Usage which only works with the Resolution Enum.

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.


Thank you for your response. When I mentioned this code (which you state to be incorrect), I was just pointing out that this works (Perhaps the second line is redundant)

self.adx = self.ADX(self.symbol, self.adx_period, Resolution.Daily)

self.RegisterIndicator(self.symbol, self.adx, Resolution.Daily)

but the real problem that I'm facing is with this snippet of code which is recommended under the Automatic Update method in Custom Indicators at 

https://www.quantconnect.com/docs/algorithm-reference/indicators#Indicators-Indicator-Ready# request the daily equity data
self.AddEquity("SPY", Resolution.Daily)
# define a 10-period RSI indicator with indicator constructor
self.rsi = RelativeStrengthIndex(10, MovingAverageType.Simple)
# register the daily data of "SPY" to automatically update the indicator
self.RegisterIndicator("SPY", self.rsi, Resolution.Daily)

this approach is not working for me when I implement ADX with similar code like this. 

 

self.adx = self.ADX(self.symbol, self.adx_period)

self.RegisterIndicator(self.symbol, self.adx, Resolution.Daily)

can you please advise why the aforementioned code snippet is not working

0

In the attached algorithm, we should that there is no issue with this approach:

# request the daily equity data
self.AddEquity("SPY", Resolution.Daily)
# define a 10-period RSI indicator with indicator constructor
self.rsi = RelativeStrengthIndex(10, MovingAverageType.Simple)
# register the daily data of "SPY" to automatically update the indicator
self.RegisterIndicator("SPY", self.rsi, Resolution.Daily)
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.


Thank you again Alexandre Catarino  went through the code line by line

I think I have now found the problem. The reason is that when I am adding the security, I'm adding it with the resolution of minute

This is what the documentation says.

https://www.quantconnect.com/docs/algorithm-reference/indicators#Indicators-Indicator-Ready


"
The indicator resolution can be different from the resolution of your securities data. However, the resolution of the indicator should be equal to or higher than the resolution of your security."

When I read the phrase higher than the resolution of your security, my understanding is that if the resolution of the indicator ADX is daily then I can choose any of the resolution, which is of time period less then daily e.g minute or an hour.

In fact, do I not need at this resolution if I need to create a consolidated data bar for let's say 30 minutes for another indicator that needs to work along with ADX. ?

To demonstrate the problem, I have cloned the project that you have created in the previous message and have also added the code for ADX as well as creating a 30 minute bar handler.

To reproduce the problem, please an comment line number 19 

self.AddEquity("SPY", Resolution.Minute)



and comment out the line number 20.

 

self.AddEquity("SPY", Resolution.Minute)

I look forward to your helpful response and resolution of this issue. Many thanks again.

0


We should subscribe to a resolution that is equal to or higher than the consolidators and, consequently, the indicators. 
If we subscribe to daily data, we don't have data to consolidate 30 minutes bar. Thus, for 30-min consolidators, we cannot subscribe to hourly and daily data. On the other hand, for 2-hour consolidators, we can subscribe to hourly data too.

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.


"If we subscribe to daily data, we don't have data to consolidate 30 minutes bar. "

I agree. And by extension then the example that you gave in the second message 4 hours ago will not work if we have to use ADX at daily resolution and another indicator (say CMO) at thirty minute resolution. We will have to subscribe to the security using 

self.AddEquity("SPY", Resolution.Minute)

and not using 

self.AddEquity("SPY", Resolution.Daily)

which is what is being used in the code that you provided.

So can you please provide an example where there are at least 2 indicators one at a daily resolution and the other at 30 minute resolution (with a consolidated data bar)? 

The documentation has code to implement them separately in different algorithm. But there does not seem to be any way to combine them in same algorithm.

0

Here you can find an example with both methods to create indicators that are updated by the algorithm:

self.AddEquity("SPY", Resolution.Minute)

self.rsi30m = RelativeStrengthIndex(10, MovingAverageType.Simple)
self.RegisterIndicator("SPY", self.rsi30m, timedelta(minutes=30))

self.rsiDay = self.RSI("SPY", 10, MovingAverageType.Simple, Resolution.Daily)

If we don't need a consolidator to attach a method to, we can use RegisterIndicator method with the timedelta parameter.

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.


Thank you for keeping up and for spending the time to create an example. However I do need consolidator. The first reason is because as far as I understand, if I have to enter or exit A trade based on the indicator on 30 minutes period then I need to do it within the consolidators. And the second reason is that ultimately the indicator on the 30 minutes period is going to be a custom indicator which is going to use the CMO and then do some more mathematical transformations on it. So we need an example where the first indicator is based on a daily resolution and II indicator is based on 30 minute resolution with a consolidator.

 

The overall problem pattern is that in many cases, there would be one indicator which would be on a larger time frame and probably tell you the overall direction of the market and then there would be an indicator which would be on a 1 hour or 15 minutes time frame where the actual decision to enter or exit the trade would be made. This is probably something very common that a day trader would use. And I hope there is some standard solution for that. Thank you

0

An example with the consolidator can be found at the docs:

# request the equity data in minute resolution
self.AddEquity("SPY", Resolution.Minute)
# define a 10-period RSI indicator with indicator constructor
self.rsi = RelativeStrengthIndex(10, MovingAverageType.Simple)
# create the 30-minutes data consolidator
thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=30))
self.SubscriptionManager.AddConsolidator("SPY", thirtyMinuteConsolidator)
# register the 30-minute consolidated bar data to automatically update the indicator
self.RegisterIndicator("SPY", self.rsi, thirtyMinuteConsolidator)

thus I gave one without it to show all three possible third argument type of RegisterIndicator.

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.


Thank you. Yes that is the example of the consolidator that  I implemented. The issue here is that we get an error when we are implementing a consolidator and an indicator for 30 minutes along with another indicator with the resolution of one day. That example is not provided in the documentation as far as I see.

 

We have an example of an indicator implemented for daily resolution. We have a separate example of an indicator implemented for 30 minutes with a consolidator. And you have also provided an example of an indicator implemented for daily resolution and an indicator implemented for 30 minutes but without a consolidator.

The problem is only seen when we have an indicator implemented for daily resolution and an indicator implemented for 30 minutes with consolidator. And that is also the code that I have provided in V message in the chain of these messages. I have reproduced it by modifying the code that you had provided earlier in the morning today. Since I cannot attach a back test which has not succeeded and returned an error, that is why I provided explicit instructions on how to reduce the problem in the message number 5 in the chain of these messages.

I hope I am able to explain the problem. If not I can create a video explaining and posting the link here. Thanks

I

0

We have tried to make the documentation as comprehensible as we could without being repetitive and I added the missing examples (there is also other threads in this forum about this issue). I think you have enough information to put it all together even if I couldn't get exactly what you want to do.

You can attach a backtest "with an error":
Comment the lines that make the algorithm return an error and tell us which lines we should uncomment.

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.


You can attach a backtest "with an error":
Comment the lines that make the algorithm return an error and tell us which lines we should uncomment.

I already did that in the message number 5 in the chain of messages above. Here is the attached backtest and the lines that need to be uncommented

 

To reproduce the problem, please uncomment line number 19 

self.AddEquity("SPY", Resolution.Minute)


and comment out the line number 20.

self.AddEquity("SPY", Resolution.Daily)

As noted in the earlier messages, the problem is seen only when the underlying security is at a minute resolution AND ADX (the first indicator) is at a daily resolution AND CMO (the second indicator) is a thirty minute resolution with a thirty minute consolidator AND we access ADX value in the thirty minute consolidator. 

 

If we access ADX separately without CMO and thirty minute consolidator, the ADX values are ok and the underlying security at a daily resolution, there is no error.

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

 
";