- adx calculation
- Adaptive lookback indicators
- ADX-System
Does anyone know the calculation mt4 uses for its iAdx function ?
maybe this doc helps https://www.metatrader5.com/en/terminal/help/indicators/trend_indicators/admi
- www.metatrader5.com
Yes, the calculation it is provided in the official documentation ... ADX = SUM[(+DI-(-DI))/(+DI+(-DI)), N]/N
Average Directional Movement Index, ADX
MetaQuotes, 2005.12.06 15:10
Average Directional Movement Index Indicator (ADX) helps to determine if there is a price trend.
I recently removed a post from this thread. I see now that I misread the original post and that the question is indeed about Python (the reason for the removal).
My apologies to the poster for removing it. It is not possible for me to restore the post, so here is a copy of it.
However, please be aware that it contains some misinformation about the calculation and implementation not being provide by MetaQuotes. It is indeed provide as I indicated in my previous post.
Forum on trading, automated trading systems and testing trading strategies
Deleted comment from "Indicator discrepancy"
Nardus Van Staden, 2024.09.28 23:37
The source code for built-in functions like iADX() in MQL4 is not publicly available. These built-in functions are proprietary to MetaQuotes and are part of the MetaTrader platform's closed-source system. You can attempt to recreate the behavior of the iADX() function by observing how its output differs from the conventional ADX implementation.
Here is an example (long story)
To replicate the behaviour in Python, you could try:
Since you like the sensitivity of iADX() , you can experiment with smoothing methods and parameters in Python to approximate its output. You could manually adjust parameters in the Python ADX implementation until the output matches iADX() as closely as possible. Some third-party libraries or indicators might offer an alternative smoothing method or may have reverse-engineered variations of ADX that resemble iADX() more closely. By running both the iADX() function in MQL4 and your ADX implementation in Python, you can examine where they diverge and adjust the Python code to match the behavior.
- +DI (Positive Directional Index): Measures upward movement.
- -DI (Negative Directional Index): Measures downward movement.
- ADX (Average Directional Index): Measures the strength of the trend.
For example:
At row 9, the ADX value is 71.95, indicating a strong trend.
To adjust the sensitivity to match the MQL4's iADX() behavior, you can experiment with the smoothing method. One possibility is to adjust the exponential moving average (EMA) by changing the alpha or trying other smoothing techniques.
here is an example where i modify the smoothing method by adjusting the alpha value in the ewm function. The default smoothing uses alpha = 1/period for Wilder's smoothing, but we can tweak this to see if it matches the behavior of the iADX() function in MQL4. This is just an example, hope it clears up your query.
import numpy as np import pandas as pd # Sample data (high, low, close prices) data = { 'High': [45.09, 46.78, 47.03, 46.30, 46.09, 47.34, 46.50, 45.89, 47.11, 48.23], 'Low': [44.11, 45.23, 45.89, 45.23, 45.01, 45.87, 45.19, 44.23, 45.98, 47.00], 'Close': [44.98, 46.00, 46.99, 45.89, 46.00, 47.10, 45.89, 45.50, 47.01, 48.12] } df = pd.DataFrame(data) # Parameters period = 14 # True Range (TR) df['High-Low'] = df['High'] - df['Low'] df['High-Close'] = abs(df['High'] - df['Close'].shift(1)) df['Low-Close'] = abs(df['Low'] - df['Close'].shift(1)) df['TR'] = df[['High-Low', 'High-Close', 'Low-Close']].max(axis=1) # Directional Movement (DM) df['+DM'] = np.where((df['High'] - df['High'].shift(1)) > (df['Low'].shift(1) - df['Low']), np.maximum(df['High'] - df['High'].shift(1), 0), 0) df['-DM'] = np.where((df['Low'].shift(1) - df['Low']) > (df['High'] - df['High'].shift(1)), np.maximum(df['Low'].shift(1) - df['Low'], 0), 0) # Modified Smoothing (you can tweak the alpha value here) def custom_smoothing(series, period, alpha=None): # Default alpha (Wilder's method) is 1/period, but we allow custom alpha for sensitivity tuning if alpha is None: alpha = 1 / period return series.ewm(alpha=alpha, adjust=False).mean() # Applying the smoothing with custom alpha (try different values like 0.2, 0.3, etc.) alpha_value = 0.3 # Modify this to experiment with different smoothing sensitivity df['TR_smooth'] = custom_smoothing(df['TR'], period, alpha=alpha_value) df['+DM_smooth'] = custom_smoothing(df['+DM'], period, alpha=alpha_value) df['-DM_smooth'] = custom_smoothing(df['-DM'], period, alpha=alpha_value) # Calculate +DI and -DI df['+DI'] = 100 * (df['+DM_smooth'] / df['TR_smooth']) df['-DI'] = 100 * (df['-DM_smooth'] / df['TR_smooth']) # Calculate DX and ADX df['DX'] = 100 * abs(df['+DI'] - df['-DI']) / (df['+DI'] + df['-DI']) df['ADX'] = custom_smoothing(df['DX'], period, alpha=alpha_value) # Final output with adjusted smoothing print(df[['High', 'Low', 'Close', '+DI', '-DI', 'ADX']].tail())
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use