ADX Crossing_v4
Download scriptThis tool is designed as a visual trading assistant for the MetaTrader platform, specifically created to identify momentum shifts in the market. It functions by monitoring two specific components of the ADX (Average Directional Index) technical indicator: the Plus DI and the Minus DI.
Core Functionality
The primary purpose of this script is to detect "crosses" between these two trend lines. In technical analysis, the Plus DI generally represents upward price pressure, while the Minus DI represents downward price pressure. When these two lines cross each other on a chart, it often signals a potential change in the direction of the market trend—shifting from bullish to bearish or vice versa.
How It Works
The script continuously scans historical price data over a specific range of bars (customizable by the user) and performs the following logic:
- Trend Reversal Detection: The tool looks for moments where the Plus DI line was previously above the Minus DI line but has just dropped below it, or vice versa.
- Visual Signaling: Instead of cluttering your chart with lines, the script places specific visual markers (arrows) at the exact moment these crossings occur:
- Bearish Signals: When the indicator detects that upward momentum is losing out to downward momentum, it places a marker below the candle's low price.
- Bullish Signals: When it detects that downward momentum is losing out to upward momentum, it places a marker above the candle's high price.
User Experience
For a trader, this means you don't have to manually watch two overlapping lines on an ADX indicator to see where they intersect. The script does the heavy lifting by automatically identifying these "crossover" points and highlighting them directly on your main price chart, providing a clear visual cue for potential entry or exit points based on momentum shifts.
//+------------------------------------------------------------------+
//| ADX Crossing.mq4
//| Amir
//+------------------------------------------------------------------+
#property copyright "Author - Amir"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//---- input parameters
extern int ADXbars=50;
extern int CountBars=350;
//---- buffers
double val1[];
double val2[];
double b4plusdi,nowplusdi,b4minusdi,nowminusdi;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexBuffer(0,val1);
SetIndexBuffer(1,val2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| AltrTrend_Signal_v2_2 |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>=Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars);
SetIndexDrawBegin(1,Bars-CountBars);
int i,shift,counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=CountBars;i++) val1[CountBars-i]=0.0;
for(i=1;i<=CountBars;i++) val2[CountBars-i]=0.0;
}
for (shift = CountBars; shift>=0; shift--)
{
b4plusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,shift-1);
nowplusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,shift);
b4minusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_MINUSDI,shift-1);
nowminusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_MINUSDI,shift);
if (b4plusdi>b4minusdi && nowplusdi<nowminusdi)
{
val1[shift]=Low[shift]-5*Point;
}
if (b4plusdi<b4minusdi && nowplusdi>nowminusdi)
{
val2[shift]=High[shift]+5*Point;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments