ADX Smoothed
Download scriptThis script is a custom technical analysis tool designed for the MetaTrader platform. It enhances the standard ADX (Average Directional Index) indicator by applying two distinct layers of mathematical "smoothing" to make the data cleaner and easier to read for traders.
Core Functionality
The primary goal of this tool is to reduce market "noise"—those small, erratic price fluctuations that can often trigger false signals. By smoothing the data, the script helps identify more stable trends in the market. It tracks three specific components:
- DI Plus: Represents the strength of upward price movement.
- DI Minus: Represents the strength of downward price movement.
- ADX: Represents the overall strength of the trend (regardless of direction).
How the Logic Works
The script processes these three components through a two-stage refinement process:
1. The First Smoothing Layer (Lead Calculation) The tool first takes the raw ADX data and applies an initial calculation using a specific "alpha" coefficient. This step focuses on balancing the current market movement against the previous period's data. It creates a preliminary version of the trend lines, effectively filtering out immediate, sharp spikes while maintaining the core direction of the price action.
2. The Second Smoothing Layer (Final Refinement) Once the first layer is calculated, the script runs the data through a second refinement process using a different coefficient. This secondary pass acts like a "polishing" step. It blends the results from the first stage to produce a final, fluid line on your chart.
Visual Presentation
The result is displayed in a separate window below the main price chart, featuring three distinct lines:
- Lime Line: The smoothed DI Plus (Upward trend strength).
- Wheat Line: The smoothed DI Minus (Downward trend strength).
- Crimson Line: The final smoothed ADX (Overall trend intensity).
Summary for the User
Instead of showing you raw, jagged market data that can be distracting, this script performs a "double-filter" operation. It takes the standard trend indicators and rounds off the sharp edges, providing you with a smoother visual representation of market momentum. This allows for a clearer view of whether a trend is gaining strength, losing steam, or moving sideways without being misled by temporary volatility.
//+------------------------------------------------------------------+
//| ADX Smoothed.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Wheat
#property indicator_color3 Crimson
#property indicator_level1 25
//---- input parameters
extern int per=8;
extern double alpha1=0.25;
extern double alpha2=0.33;
extern int PriceType=0;
//---- buffers
double DiPlusFinal[];
double DiMinusFinal[];
double ADXFinal[];
double DIPlusLead[];
double DIMinusLead[];
double ADXLead[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(6);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,DiPlusFinal);
SetIndexLabel(0,"Di Plus");
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,DiMinusFinal);
SetIndexLabel(1,"Di Minus");
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ADXFinal);
SetIndexLabel(2,"ADX");
SetIndexBuffer(3,DIPlusLead);
SetIndexBuffer(4,DIMinusLead);
SetIndexBuffer(5,ADXLead);
IndicatorDigits(2);
IndicatorShortName("ADX("+per+")smothed");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int i,k,limit;
double DIPlus, DIMinus, ADX, DIPlus1, DIMinus1, ADX1;
//----
if (counted_bars==0) limit=Bars-per-1;
if (counted_bars>0) limit=Bars-counted_bars;
for (i=limit;i>=0;i--)
{
DIPlus=iADX(NULL,0,per,PriceType,MODE_PLUSDI,i);
DIMinus=iADX(NULL,0,per,PriceType,MODE_MINUSDI,i);
ADX=iADX(NULL,0,per,PriceType,MODE_MAIN,i);
DIPlus1=iADX(NULL,0,per,PriceType,MODE_PLUSDI,i+1);
DIMinus1=iADX(NULL,0,per,PriceType,MODE_MINUSDI,i+1);
ADX1=iADX(NULL,0,per,PriceType,MODE_MAIN,i+1);
DIPlusLead[i]=2*DIPlus + (alpha1 - 2) * DIPlus1 + (1 - alpha1) * DIPlusLead[i+1];
DIMinusLead[i] = 2*DIMinus + (alpha1 - 2) * DIMinus1 + (1 - alpha1) * DIMinusLead[i+1];
ADXLead[i] = 2*ADX + (alpha1 - 2) * ADX1 + (1 - alpha1) * ADXLead[i+1];
}
for (i=limit;i>=0;i--)
{
DiPlusFinal[i] = alpha2*DIPlusLead[i] + (1 - alpha2) * DiPlusFinal[i+1];
DiMinusFinal[i] = alpha2*DIMinusLead[i] + (1 - alpha2) * DiMinusFinal[i+1];
ADXFinal[i] = alpha2*ADXLead[i] + (1 - alpha2) * ADXFinal[i+1];
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments