Hi, I am new to Quantconnect. I am trying to build a strategy using the standard ADX indicator but I am not able to update the indicator and plot the indicator. I would appreciate it if someone can help me out on this. Thanks! Here's the code and error messages:
import numpy as np
class StandardIndicatorsProject(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 10, 29)
self.SetEndDate(2021, 10, 29)
self.SetCash(10000) # Set Strategy Cash
self.stock = self.AddEquity('MSFT', Resolution.Daily).Symbol
self.adx = AverageDirectionalIndex(self.stock, 14)
# initialize the indicator with the daily history close price
history = self.History(self.stock, 200, Resolution.Daily)
for time, row in history.loc[self.stock].iterrows():
self.adx.Update(time, row["close"])
def OnData(self, data):
# update the indicator value with the new input close price every day
if data.Bars.ContainsKey(self.stock):
self.adx.Update(data[self.stock].EndTime, data[self.stock].Close)
if not self.adx.IsReady: return
self.Plot("Close", "today", data[self.stock].Close)
self.Plot("Indicator", "adx", self.adx.Current.Value)
Error Messages:
During the algorithm initialization, the following exception has occurred: NotSupportedException : AverageDirectionalIndex does not support the `Update(DateTime, decimal)` method. Use one of the following methods instead: Update(TradeBar), Update(QuoteBar)
at QuantConnect.Indicators.IndicatorBase`1.Update(DateTime time, Decimal value) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Indicators/IndicatorBase.cs:line 235
at Initialize
self.adx.Update(time in main.py: line 21
NotSupportedException : AverageDirectionalIndex does not support the `Update(DateTime, decimal)` method. Use one of the following methods instead: Update(TradeBar), Update(QuoteBar)
at QuantConnect.Indicators.IndicatorBase`1.Update(DateTime time, Decimal value) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Indicators/IndicatorBase.cs:line 236
Vladimir
Winston Chan,
Try this way.
Louis Szeto
Hi Winston, Vladimir
Thank you for your help, Vladimir!
We would like to point out that for the manually updating ADX indicator, we’ll have to use a TradeBar/QuoteBar object to update the indicator, rather than just end time and close:
Best
Louis
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.
Vladimir
Louis Szeto,
Thank you for your comment.
I have created an algorithm that compares 3 different ways to calculate the ADX indicator.
Why do we’ll have to use a TradeBar object to update the indicator if,
with the appropriate warming up setting, all three return exactly the same results?
Alexandre Catarino
Hi Vladimir
It has to use a Bar object (TradeBar or QuoteBar) but not (Time, Price) pair to update ADX since it requires multiple inputs from a bar (OHLC) to compute its values. As per its application, if we're using a non-time-interval bar (e.g. volume/dollar Renko bars) to update the indicator, a manual-updating style would be needed.
Best regards,
Alex
Vladimir
Alexandre Catarino,
Thank you for your comment.
In my last post, I compared 3 different ways to calculate the ADX indicator.
Are they all valid or just the one with history update?
Gowestyang
Hello! I also have a question relevant to this topic
When warming up ADX, I found it takes double dates of the input period to get it ready.
For example:
I found that this indicator only became ready at the 10th daily data point.
Another example:
In this case, it became ready at the 12th daily data point.
May I know why there is such a “doubling” relationship?
Derek Melchin
Hi Gowestyang,
The Average Directional Index indicator calculates its value by using an internal WilderMovingAverage indicator, which has a warm-up period that matches the integer we pass to the ADX method above. This WilderMovingAverage is updated with values from other internal indicators (PositiveDirectionalIndex and NegativeDirectionalIndex), which each have a warm-up period that is 1 greater than the integer we pass to the ADX method above. Therefore, to warm up the WilderMovingAverage indicator, we need twice as many samples as the integer we pass to the ADX method.
To view the full implementation of the Average Directional Index indicator, see AverageDirectionalIndex.cs in the LEAN GitHub repository.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Winston Chan
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!