ADX Crossing w_Alerts_v1
Download scriptThis tool is designed to assist traders by identifying specific momentum shifts in the market using a technical analysis indicator known as the ADX (Average Directional Index). Instead of just showing general price movement, this script focuses on the relationship between two specific components: the Positive Directional Index (which tracks upward momentum) and the Negative Directional Index (which tracks downward momentum).
Core Logic and Functionality
The script continuously monitors the interaction between these two momentum indicators to detect "crosses." Here is how the logic flows:
- Momentum Monitoring: The tool looks at the recent history of the market to determine which direction has more strength—upward or downward. It compares the values of the PlusDI and MinusDI components across consecutive bars (time intervals).
- Buy Signal Detection: A "Buy" signal is triggered when the momentum shifts from being predominantly downward to predominantly upward. Specifically, if the previous data point showed stronger negative momentum, but the current data point shows that positive momentum has overtaken it, the script identifies a potential bullish shift.
- Sell Signal Detection: Conversely, a "Sell" signal is triggered when the momentum shifts from being predominantly upward to predominantly downward. If the previous data point showed stronger positive momentum and the current data point shows that negative momentum has taken over, the script identifies a potential bearish shift.
- Visual and Audio Alerts: When these specific crossovers occur, the script performs three actions simultaneously:
- It places a visual arrow on the chart (Lime for Buy, Red for Sell) to highlight the entry point.
- It triggers a pop-up alert on the trading platform.
- It generates a notification message including the current time and the specific currency pair or asset being traded.
User Experience Settings
The tool is customizable to allow traders to adjust how much historical data is processed and how sensitive the momentum calculation is. By defining the number of "bars" used for the ADX calculation, traders can choose between a faster, more reactive signal or a slower, more smoothed signal depending on their specific trading style.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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 && i!=1)
{
val1[shift]=Low[shift]-5*Point;
Alert("Buy Arrow","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());
i++;
}
if (b4plusdi<b4minusdi && nowplusdi>nowminusdi && i!=1)
{
val2[shift]=High[shift]+5*Point;
Alert("Sell Arrow","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());
i++;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments