Hi QuantConnect Community! I would like to ask your help.
Into Research Notebook, I want to calculate ADX indicator using consolidated data. I created a TradeBar object and add parameters in order to Update indicator. However, the results of
adx.Update(trade_bar)
Is always False. I haven't been able to solve this problem.
Could you help me to find what is the mistake here? Below is the block of code:
# DF is DataFrame with consolidated data (OHLCV). The index is a DateTime object.
# Previously, I dropped NaN values from DataFrame.
# Define instance for ADX -> period=14 is the default value
adx = AverageDirectionalIndex(period=14)
# Dictionary to hold consolidated ADX values.
adx_values = {'time': [], 'positiveDI': [], 'negativeDI': []}
# DI+ and DI- requires a TradeBar object.
trade_bar = TradeBar()
# Iterate through consolidated dataframe.
for item in DF.itertuples():
time = item.Index
# Add parameters to "trade_bar" object
trade_bar.Open = item.Open
trade_bar.High = item.High
trade_bar.Low = item.Low
trade_bar.Close = item.Close
trade_bar.EndTime = item.Index
trade_bar.Volume = item.Volume
# Update indicator with consolidated data
adx.Update(trade_bar)
# If indicator values are ready, append data to dictionary previosly defined
if adx.IsReady:
adx_values['time'].append(time)
adx_values['positiveDI'].append(adx.PositiveDirectionalIndex.Current.Value)
adx_values['negativeDI'].append(adx.NegativeDirectionalIndex.Current.Value)
# Create indicator dataframe from dictionary
consolidated_adx = pd.DataFrame(adx_values, columns=['time', 'positiveDI', 'negativeDI'])
# Set index to time
consolidated_adx = consolidated_adx.set_index('time')
Regards.
Edinson Leandro Medina Alfonzo
Hi Derek Melchin!
I have contrasted your code with mine. I could see that I defined the TradeBar object only once before start the for loop. While in your code, this object is defined in each iteration.
I have understood the issue in my code. In order to replace and use the new Time-OHLCV data, it is also necessary replace this definition in each iteration.
Thanks a lot for your help! I had stuck during a lot of time with this.
Regards
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.
Shile Wen
Hi Zach,
The algorithm has many technical and stylistic issues, and since it seemed to be a popular algorithm, we've rewrote it to use the SymbolData pattern, replaced the History calls with RollingWindows, and fixed many stylistic issues. Please view the updated algorithm in the attached backtest.
Best,
Shile Wen
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.
Zach Oakes
Thanks ! It's very cool. It's like an MR take on Trend -- brilliant interpretation, and MUCH nicer than my translation.
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.
Mohamed Ajmal
How can we implement stoploss / reduce drawdown in this algorithm?
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.
Varad Kabade
Hi Mohamed Ajmal,
In the last backtest attached by Shile he has implemented the stop-loss which is triggered every day after 10 minutes of market open:
Refer to the following code snippet.
Best,
Varad Kabade
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.
Andres Arizpe
This appears to be a very interesting algo.
Is there any documentation I might use to get a basic understanding of it?
Cheers,
Andres
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.
Varad Kabade
Hi Andres Arizpe,
The above algorithm consists of components like the scheduled events, rolling window, and standard python libraries like numpy and pandas. We recommend going through the following docs[1, 2], and regarding the libraries, please look for their homepage/documentation. Please feel free to ask any specific doubts about the above algorithm.
Best,
Varad Kabade
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!