Backtesting is the process of seeing how well our trading strategy has performed on the given stock data. In our case, we are going to implement a backtesting process for our Average Directional Index trading strategy over the Apple stock data. Now, let’s code this indicator from scratch and build the discussed trading strategy out of it in python and backtest it with the Apple stock to see some exciting results. We will also compare our ADX crossover strategy returns with the returns of the SPY ETF to see how well our trading strategy has performed against a benchmark. Since the value is 100, we will say that the ADX indicator is exhibiting a very strong trend. This can be also visually confirmed by the candlestick plot of the data shown above.
We are going to backtest our strategy by investing a hundred thousand USD into our trading strategy. So first, we are storing the amount of investment into the ‘investment_value’ variable. After that, we are calculating the number of Apple stocks we can buy using the investment amount. The number of stocks should be an integer but not a decimal number. Remember that the ‘floor’ function is way more complex than the ‘round’ function. Then, we are passing a for-loop to find the investment returns followed by some data manipulation tasks.
Wilder’s initial stops were not incorporated in order to focus on the indicator signals. As the chart clearly shows, there are plenty of +DI and -DI crosses. As with most such systems, there will be whipsaws, great signals, and bad signals. The key, as always, is to incorporate other aspects of technical analysis. For example, the first group of whipsaws in September 2009 occurred during a consolidation.
The indicator can also be used as a trend or trade confirmation tool. If the +DI is well above -DI, the trend has strength on the upside, and this would help confirm current long trades or new long trade signals based on other entry methods. Conversely, if -DI is well above +DI, this confirms the strong downtrend or short positions. This is same as the previous step, but instead of summarizing the true ranges, we’re going to summarize the past 14 day’s directional movements.
DMI Trend Lines
This has a smoothing effect on the indicator that protects it from erratic movements. If there’s no positive directional movement for today, nothing is added back. Now that you know how to calculate the directional movement – both positive and negative – it’s time to move forward.
When both DMI lines are below 25 and moving sideways, there is no dominant force, and trend trades are not appropriate. However, the best trends begin after long periods where the DMI lines cross back and forth under the 25 level. A low-risk trade setup will occur after DMI expands above the 25 level and price penetrates https://forexhero.info/lexatrade-forex-broker-company-background-and-security/ support/resistance. The great feature of DMI is the ability to see buying and selling pressure at the same time, allowing the dominant force to be determined before entering a trade. The strength of a swing high (bulls) is reflected in the +DMI peak, and the strength of a swing low (bears) is seen in the -DMI peak.
Trading with Wilder’s DMI
This is where the ADX is useful; it helps to isolate ranging markets and capture strong trends instead. It’s probably not going to be exact same values, because different brokers can have slightly different prices. Also, it’s possible that other calculations may do the smoothing a bit differently. We can construct a simple Excel formula that calculates the true range using the built-in MAX() and ABS() functions.
Stocks with low volatility may not generate signals based on Wilder’s parameters. Chartists will likely need to adjust the indicator settings or the signal parameters according to the characteristics of the security. Even though DI crossovers may appear as an easy way to identify trading signals, traders should confirm these signals with other trading indicators because false signals might occur.
Here we can see a number of times the Positive Directional Indicator crossed over from under the Negative Directional Indicator. But, as we mentioned above, we check the ADX indicator level as well to ascertain the strength of the trend. Considering that we took a simple example before, we have added another table below which gives the stock price of Apple and its corresponding ADX indicator. Now since each can have different magnitudes, we normalise them by dividing with the true range and expressing them as a percentage. As the name suggests, the Positive Directional Indicator is used to help us gauge the uptrend of the market.
This makes it easy to identify directional indicator crosses. While ADX can be plotted above, below or behind the main price plot, it is recommended to plot above or below because there are three lines involved. The chart example below also shows the 50-day SMA and Parabolic SAR plotted behind the price plot.