ADXcrosses
Download scriptThis tool is designed to act as a visual signaling system on your trading charts, helping you identify specific momentum shifts by monitoring the relationship between two key trend components: the Positive Directional Index (plusDI) and the Negative Directional Index (minusDI).
How It Works
The script analyzes the "crossover" points of these two directional indicators. In technical terms, these indicators measure the strength and direction of price movements. When the positive indicator moves above the negative one, it suggests an upward trend; when the negative moves above the positive, it suggests a downward trend.
Key Functionalities
-
Dynamic Signal Detection: The script continuously scans past price data to find moments where these two lines cross each other.
- Bullish Signals: When the Positive DI crosses from below to above the Negative DI, the script places a visual arrow pointing upward.
- Bearish Signals: When the Negative DI crosses from below to above the Positive DI, the script places a visual arrow pointing downward.
-
Visual Clarity: Instead of cluttering your screen with messy lines, this tool uses distinct arrows (colored Dark Blue for upward signals and Maroon for downward signals) positioned clearly above or below the price candles.
-
Smart Spacing (Auto-Offset): To ensure that the arrows do not overlap directly onto the price candles—which could make the chart difficult to read—the script includes a smart "shifting" logic. It automatically calculates how far away from the candle the arrow should be placed based on the specific timeframe you are viewing (e.g., it uses a smaller gap for fast 1-minute charts and a much larger gap for long-term daily or weekly charts).
Summary for the Trader
Essentially, this script automates the tedious task of watching the DI lines closely. It "watches" the market for you and marks the exact moment the momentum shifts direction with an arrow, allowing you to quickly identify potential trend reversals at a glance.
//+------------------------------------------------------------------+
//| ADXcrosses.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DarkBlue
#property indicator_color2 Maroon
//---- input parameters
extern int ADXcrossesPeriod=14;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//----
double b4plusdi, b4minusdi, nowplusdi, nowminusdi;
int nShift;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, 0, 1);
SetIndexArrow(0, 233);
SetIndexBuffer(0, ExtMapBuffer1);
//----
SetIndexStyle(1, DRAW_ARROW, 0, 1);
SetIndexArrow(1, 234);
SetIndexBuffer(1, ExtMapBuffer2);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("ADXcrosses("+ADXcrossesPeriod+")");
SetIndexLabel(0, "ADXcrUp");
SetIndexLabel(1, "ADXcrDn");
//----
switch(Period())
{
case 1: nShift=1; break;
case 5: nShift=3; break;
case 15: nShift=5; break;
case 30: nShift=10; break;
case 60: nShift=15; break;
case 240: nShift=20; break;
case 1440: nShift=80; break;
case 10080: nShift=100; break;
case 43200: nShift=200; break;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0)
return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0)
counted_bars--;
limit=Bars - counted_bars;
//----
for(int i=1; i < limit; i++)
{
b4plusdi=iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_PLUSDI, i + 1);
nowplusdi=iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_PLUSDI, i);
b4minusdi=iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_MINUSDI, i + 1);
nowminusdi=iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_MINUSDI, i);
//----
if(b4plusdi < b4minusdi && nowplusdi > nowminusdi)
ExtMapBuffer1[i]=Low[i] - nShift*Point;
//----
if(b4plusdi > b4minusdi && nowplusdi < nowminusdi)
ExtMapBuffer2[i]=High[i] + nShift*Point;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments