ADX Crossing
Download scriptThis tool is designed to identify specific shifts in market momentum by monitoring the relationship between two opposing trend indicators. Rather than tracking the overall strength of a movement, it focuses on the "tug-of-war" between bullish (upward) and bearish (downward) forces to pinpoint moments where the lead changes.
Core Logic Overview
The script operates by analyzing two specific components: the Plus Directional Index (+DI), which represents upward pressure, and the Minus Directional Index (-DI), which represents downward pressure. The logic follows a simple "cross-over" principle:
- Bearish Signal (Red): The tool looks for a moment where the bullish force was previously stronger than the bearish force but has now dropped below it. When this transition occurs, the script identifies a potential shift toward downward momentum.
- Bullish Signal (Lime): Conversely, the tool watches for instances where the bearish force was previously dominant but has been overtaken by the bullish force. This identifies a potential shift toward upward momentum.
How It Works on Your Chart
Instead of creating a continuous line that might clutter your view, the script acts as an alert system using visual markers:
- Momentum Tracking: The tool constantly scans back through a specific number of historical bars (user-defined) to ensure it captures every relevant transition.
- Signal Detection: It compares the values from the current candle against the previous candle to see if a "cross" has occurred.
- Visual Marking:
- When a downward cross is detected, an arrow appears slightly below the candle's low price.
- When an upward cross is detected, an arrow appears slightly above the candle's high price.
Key Customizations
The behavior of the script can be adjusted through two primary settings:
- ADXbars: Determines the sensitivity of the trend calculation. A higher number will smooth out the data (fewer signals, but potentially more reliable), while a lower number will make the tool more responsive to quick price flickers.
- CountBars: Controls how much historical data the script reviews on your screen at one time.
In summary, this script serves as a visual "crossing" notifier, highlighting the exact moments when market sentiment flips from one direction to another based on directional momentum.
//+------------------------------------------------------------------+
//| 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=14;
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,108);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,108);
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