ADXmodified_v1
Download scriptThe ADX Modified tool is a technical analysis indicator designed to help traders identify the strength and direction of market trends. Rather than just showing whether a price is going up or down, it focuses on measuring the "velocity" and "momentum" of those movements to help users determine if a trend is active or if the market is moving sideways.
Core Logic Overview
The script functions by analyzing the relationship between price highs and lows over a specific period (defaulting to 14 bars). It breaks this down into three primary components:
1. Directional Movement Tracking
The tool first separates price action into two distinct categories:
- Positive Movement (+DI): Measures how much the market is pushing upward compared to previous highs.
- Negative Movement (-DI): Measures how much the market is pushing downward compared to previous lows.
It filters out "noise" by ensuring that only significant price movements are counted. If the upward push and downward push are equal, or if the movement is insignificant, the tool ignores them to prevent false signals.
2. Relative Strength Calculation
To put these movements into perspective, the script calculates a "True Range." This helps normalize the data by comparing the current move against the total volatility of the candle. By dividing the positive and negative movements by this range, the indicator produces two percentage-based values. These show the relative strength of buyers versus sellers at any given moment.
3. Smoothing and Trend Identification
Because raw market data can be erratic, the script applies a series of mathematical "smoothings" (Exponential Moving Averages) to the data:
- Smoothing the Direction: It first smooths the raw positive and negative strength values to create stable (+DI and -DI) lines.
- Calculating the Difference (DX): It then calculates the gap between the positive and negative strengths. A large gap suggests a strong trend; a narrow gap suggests a choppy or sideways market.
- The Final ADX Value: Finally, it applies one last smoothing layer to that difference. The resulting ADX line represents the overall trend strength.
How to Interpret the Results
- Trend Strength: A rising ADX line generally indicates that a trend (either up or down) is gaining strength and momentum. A falling ADX line suggests the trend is losing steam or the market is entering a consolidation phase.
- Directional Bias: By observing the relationship between the +DI (typically showing buying pressure) and the -DI (showing selling pressure), traders can identify which side of the market currently has the upper hand. When one line明显 stays above the other, it indicates the prevailing direction of the current trend.
//+------------------------------------------------------------------+
//| ADX modified_v1.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//| |
//| Modified from default ADX by Toshi |
//| http://toshi52583.blogspot.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 C'175,175,175'
#property indicator_color2 C'175,0,0'
#property indicator_style2 2
#property indicator_color3 C'100,100,100'
#property indicator_style3 2
#property indicator_level1 0
#property indicator_levelcolor C'75,75,75'
//---- input parameters
extern int ADXPeriod=14;
//---- buffers
double ADXBuffer[];
double PlusDiBuffer[];
double MinusDiBuffer[];
double PlusSdiBuffer[];
double MinusSdiBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 3 additional buffers are used for counting.
IndicatorBuffers(6);
//---- indicator buffers
SetIndexBuffer(0,ADXBuffer);
SetIndexBuffer(1,PlusDiBuffer);
SetIndexBuffer(2,MinusDiBuffer);
SetIndexBuffer(3,PlusSdiBuffer);
SetIndexBuffer(4,MinusSdiBuffer);
SetIndexBuffer(5,TempBuffer);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("ADX modified("+ADXPeriod+")");
SetIndexLabel(0,"ADX modified");
SetIndexLabel(1,"+DI");
SetIndexLabel(2,"-DI");
//----
SetIndexDrawBegin(0,ADXPeriod);
SetIndexDrawBegin(1,ADXPeriod);
SetIndexDrawBegin(2,ADXPeriod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Average Directional Movement Index |
//+------------------------------------------------------------------+
int start()
{
double pdm,mdm,tr;
double price_high,price_low;
int starti,i,counted_bars=IndicatorCounted();
//----
i=Bars-2;
PlusSdiBuffer[i+1]=0;
MinusSdiBuffer[i+1]=0;
if(counted_bars>=i) i=Bars-counted_bars-1;
starti=i;
//----
while(i>=0)
{
price_low=Low[i];
price_high=High[i];
//----
pdm=price_high-High[i+1];
mdm=Low[i+1]-price_low;
if(pdm<0) pdm=0; // +DM
if(mdm<0) mdm=0; // -DM
if(pdm==mdm) { pdm=0; mdm=0; }
else if(pdm<mdm) pdm=0;
else if(mdm<pdm) mdm=0;
//---- âû÷èñëÿåì èñòèííûé èíòåðâàë
double num1=MathAbs(price_high-price_low);
double num2=MathAbs(price_high-Close[i+1]);
double num3=MathAbs(price_low-Close[i+1]);
tr=MathMax(num1,num2);
tr=MathMax(tr,num3);
//---- counting plus/minus direction
if(tr==0) { PlusSdiBuffer[i]=0; MinusSdiBuffer[i]=0; }
else { PlusSdiBuffer[i]=100.0*pdm/tr; MinusSdiBuffer[i]=100.0*mdm/tr; }
//----
i--;
}
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
//---- apply EMA to +DI
for(i=0; i<=limit; i++)
PlusDiBuffer[i]=iMAOnArray(PlusSdiBuffer,Bars,ADXPeriod,0,MODE_EMA,i);
//---- apply EMA to -DI
for(i=0; i<=limit; i++)
MinusDiBuffer[i]=iMAOnArray(MinusSdiBuffer,Bars,ADXPeriod,0,MODE_EMA,i);
//---- Directional Movement (DX)
for(i=0; i<=limit; i++)
TempBuffer[i]=PlusDiBuffer[i]-MinusDiBuffer[i];
//---- ADX is exponential moving average on DX
for(i=0; i<limit; i++)
ADXBuffer[i]=iMAOnArray(TempBuffer,Bars,ADXPeriod,0,MODE_EMA,i);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments