ADX_Cross
Download scriptThis tool is designed to assist traders by visually identifying specific trend reversals on a price chart. It works by monitoring two distinct momentum components—often referred to as the Plus Directional Index and the Minus Directional Index—which measure the strength and direction of market movement.
How it Works
The script continuously analyzes the relationship between these two momentum indicators over a user-defined period. Instead of just showing a continuous line, the logic focuses specifically on "crosses." It looks for moments where the leading strength shifts from one side to the other:
- Bearish Signals: The tool identifies a potential downward shift when the "Plus" momentum was previously stronger than the "Minus" momentum but has now dropped below it. When this crossover occurs, the script places a visual marker (a red arrow) below the price candles.
- Bullish Signals: Conversely, it detects an upward shift when the "Minus" momentum was previously dominant but has been overtaken by the "Plus" momentum. In these instances, the script places a visual marker (a green arrow) above the price candles.
Dynamic Adjustment
One of the key features of this logic is its ability to adapt to different timeframes automatically. The script includes a built-in calculation that adjusts the distance of the arrows from the price based on the chart you are viewing (e.g., 1-minute charts vs. daily charts). This ensures that the visual markers remain clearly visible and do not overlap with the price bars, regardless of whether you are performing high-frequency scalping or long-term swing trading.
Summary for the User
Essentially, this script acts as an automated "scout." It filters through the complex fluctuations of market momentum to highlight only those specific moments where the trend appears to be flipping direction, providing a clear visual cue for potential entry or exit points.
//+------------------------------------------------------------------+
//| 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 Lime
#property indicator_color2 Red
extern int ADXcrossesPeriod = 14;
extern int CountBars=350;
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double b4plusdi, b4minusdi, nowplusdi, nowminusdi;
int nShift;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_ARROW, 0, 1);
SetIndexArrow(0, 225);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexStyle(1, DRAW_ARROW, 0, 1);
SetIndexArrow(1, 226);
SetIndexBuffer(1, ExtMapBuffer2);
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();
if(counted_bars < 0)
return(-1);
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
for(int i = 0; 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