ADX-real
Download scriptThis technical tool is designed to measure the strength and direction of market trends by analyzing price movements over a specific timeframe. Unlike standard indicators that might only show you if a price is moving up or down, this script provides a comprehensive view of the "momentum" behind the price action.
Core Logic Breakdown
1. Movement Measurement (True Range) The script begins by calculating the "True Range." This identifies the actual volatility of the market during each period by comparing the current high and low prices against the previous closing price. By doing this, it accounts for gaps in pricing, giving a more accurate picture of how much the market is actually swinging.
2. Directional Analysis (Plus and Minus Indicators) The logic separates price movement into two distinct categories:
- Positive Movement: It tracks upward price shifts to determine the strength of "bullish" momentum.
- Negative Movement: It tracks downward price shifts to determine the strength of "bearish" momentum.
By comparing these two types of movements against the overall volatility (the True Range), the script can tell you which direction is currently dominating the market and how aggressively it is moving.
3. Trend Strength Calculation (ADX) The primary goal of this script is to produce the ADX value. This value represents the overall "health" or intensity of a trend, regardless of its direction.
- If the ADX is rising, it signifies that the current trend (whether up or down) is gaining strength.
- If the ADX is falling, it suggests that the market may be losing momentum or entering a period of consolidation (sideways movement).
4. Smoothing for Stability To prevent the data from being too "choppy" or reactive to tiny, insignificant price ticks, the script applies a smoothing process. It averages the current data with previous values over a set period (defaulting to 14). This results in smoother lines on your chart, making it easier for a trader to identify clear trends without being misled by temporary market "noise."
5. Optional Trend Correlation The script also contains an optional feature to display a secondary line (ADXR). This acts as a moving average of the trend strength, providing an additional layer of confirmation to help traders see if the current momentum is sustainable or beginning to fatigue.
Summary for the User
In simple terms, this tool tells you two things:
- Direction: Is the market currently pushing up more than it is pushing down?
- Intensity: How fast and strongly is that movement happening?
By observing these values together, traders can better decide whether to enter a trade based on a strong moving trend or stay out of the market when the trend is weak or non-existent.
//+------------------------------------------------------------------+
//| ADX.mq4 |
//| Bheurekso - MojoFX conversion |
//| fx.studiomojo.com |
//+------------------------------------------------------------------+
#property copyright "Bheurekso - MojoFX conversion"
#property link "fx.studiomojo.com"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color2 Red
#property indicator_color1 Blue
#property indicator_color3 White
#property indicator_color4 Yellow
extern int ADXperiod = 14;
extern bool displayADXR = false;
double Clo,Cloprev,Hi,Hiprev,Lo,Loprev,TRprev,TR,TRbaku,dHi,dLo;
double PDMI,MDMI,PDIprev,PDIbaku,MDIprev,MDIbaku,PDI,MDI,DX,ADXprev,ADX,ADXR;
//---- buffers
double L1[];
double L2[];
double L3[];
double L4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,0,1);
SetIndexBuffer(0,L1);
SetIndexStyle(1,DRAW_LINE,0,1);
SetIndexBuffer(1,L2);
SetIndexStyle(2,DRAW_LINE,0,2);
SetIndexBuffer(2,L3);
SetIndexStyle(3,DRAW_LINE,0,2);
SetIndexBuffer(3,L4);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
for (int k=Bars-ADXperiod-1; k > 0; k--) {
Clo = Close[k];
Cloprev = Close[k+1];
Hi = High[k];
Hiprev = High[k+1];
Lo = Low[k];
Loprev = Low[k+1];
TRprev = TR;
TRbaku = MathMax(MathAbs(Hi-Lo), MathMax(MathAbs(Hi-Cloprev),MathAbs(Cloprev-Lo)));
TR = TRbaku+TRprev*(ADXperiod-1)/ADXperiod;
dHi = Hi-Hiprev;
dLo = Loprev-Lo;
if ((dHi < 0 && dLo < 0) || (dHi==dLo)) { PDMI=0;MDMI=0;}
if (dHi > dLo) {PDMI=dHi; MDMI=0;}
if (dHi < dLo) {PDMI=0; MDMI = dLo;}
PDIprev=PDIbaku;
MDIprev=MDIbaku;
PDIbaku= PDMI+PDIprev*(ADXperiod-1)/ADXperiod;
MDIbaku= MDMI+MDIprev*(ADXperiod-1)/ADXperiod;
PDI=100*PDIbaku/TR;
MDI=100*MDIbaku/TR;
DX=100*MathAbs(PDI-MDI)/(PDI+MDI);
ADXprev=ADX;
ADX=(DX+(ADXperiod-1)*ADXprev)/ADXperiod;
ADXR=(ADX+L1[k+Period()])/2;
L1[k] = PDI;
L2[k] = MDI;
L3[k] = ADX;
if (displayADXR) { L4[k] = ADXR; }
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments