I've been trying to port over a Tradingview strategy for a few weeks now and struggled immensely. Something I realized is obvious to others - that the chart vs. data inputs make it difficult. So I figured out a way to get my preferred indicator to be aligned after a lot of debugging. At the core of one part is a 14 period ADX.
I had to build it with a manual warmup and update and rolling windows from consolidators.
So I started with a 29 period window (2*period + 1)… and the ADX values didn't match…
After a lot of frustration I just said “ok how about 100 member window”… and it got me values within 0.01 of what I had at the same moment in tradingview… but for the sake of the system I wanted to cut it back. 60 seemed good and well above any threshold I could see… but somehow it gives me different values.
So the question, how on a 14 period ADX does a 60 member rolling window give me different results than 100? Makes no sense to me. Both work OK in backtesting and while I know the default should be "run it on the 100 as it's safer' why????
Yuri Lopukhov
ADX is using Exponential Moving Average under the hood, this type of MA is not limited by the period, like Simple Moving Average, it has recurrent formula and basically takes all historical values into account, older values just has diminishing weights and eventually stop affecting current value. “Period” for EMA just set's how fast older values stop affecting current value, but there is no guarantee when exactly this happens, it depends on the actual values and precision limit.
So if EMA has just 14 values, it's value is not yet stable and can change if you take larger window into account, like 60, unlike SMA with period 14, which is always using only last 14 values. It is recommended to use at least 5*Period values to warm up EMA in order to reduce such instability. This is a very common source of discrepancies between platforms. Also, implementation of different indicators can be different on different platforms, like using different type of EMA. So it is quite hard to get matching values in general.
Jim Shorts
It varies based on the Period of your ADX such that 100/14 = ~7, 60/14=~4 and 29/14 =~1. 7 being a divisor of 14 gives you the closest approximation to the values on TV
Echoes McCarthur
Yuri, you are incredible.
Out of curiosity did I miss this in the documenation somewhere or is this just a trick of the trade? Would be great to see a link so others can benefit from it as well.
Yuri Lopukhov
Not sure about documentation, I've seen some topics on the forum, this is a recurring problem.
Echoes McCarthur
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!