ADX Crossing_alerts_v1
Download scriptThis script is a specialized trading tool designed for the MetaTrader platform to identify potential trend reversals and momentum shifts by monitoring the ADX (Average Directional Index). It simplifies complex technical analysis into clear visual signals on your chart, helping traders spot "Buy" and "Sell" opportunities more efficiently.
How the Logic Works
The core of this tool relies on the relationship between two components of the ADX indicator: the Plus Directional Indicator (+DI) and the Minus Directional Indicator (-DI). These indicators represent the strength of upward and downward price movement, respectively.
1. Identifying "Buy" Signals (Bullish Momentum) The script constantly monitors these two lines as they move in real-time. A "Buy" signal is triggered when the Plus DI line (representing upward momentum) crosses over the Minus DI line (representing downward momentum). This suggests that bullish pressure is overtaking bearish pressure. When this happens, the tool places a visual marker on the chart below the current price.
2. Identifying "Sell" Signals (Bearish Momentum) Conversely, a "Sell" signal is triggered when the Minus DI line crosses over the Plus DI line. This indicates that downward pressure is becoming dominant over upward movement. When this occurs, the tool places a visual marker on the chart above the current price.
Key Features and User Customization
To ensure the tool fits your specific trading style, it includes several customizable behaviors:
- Visual Markers: You can choose from various different arrow styles (such as round, thick, hollow, or diagonal) to make the signals stand out clearly on your candles.
- Dynamic Positioning: Instead of placing markers exactly on the price line, the script uses an "Average True Range" calculation. This places the arrows at a professional distance away from the price, ensuring they remain visible and do not clutter the actual price action.
- Real-Time Notifications: You don't have to watch the screen constantly. The script is equipped with a multi-layered alert system:
- Pop-up Alerts: Instant text notifications on your computer screen.
- Audio Alerts: Plays a specific sound file (e.g., "alert.wav") to grab your attention.
- Email Notifications: Sends an automated message to your inbox containing the specific price, time, and symbol details of the signal.
Summary for the Trader
This tool automates the "line crossing" analysis that traders usually perform manually. It scans the market history and live data, identifies the exact moment momentum shifts from one direction to another, and broadcasts that information to you via visual markers and your preferred notification method.
//+------------------------------------------------------------------+
//| 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;
extern string note13 = "turn on soundAlert = true; turn off = false";
extern bool SoundON = true;
extern string note15 = "send Email Alert = true; turn off = false";
extern bool EmailON = false;
extern string note17 = "turn on Alert = true; turn off = false";
extern bool AlertON = true;
extern string SoundFileName = "alert.wav";
extern string note7 = "Arrow Type";
extern string note8 = "0=defaultRound,1=Thick, 2=Thin, 3=Hollow, 4=Round";
extern string note9 = "5=Fractal, 6=Diagonal Thin,7=Diagonal Thick";
extern string note10 = "8=Diagonal Hollow, 8=Thumb";
extern string note11 = " 10 = Finger";
extern int ArrowType = 0;
//---- buffers
double CrossUp[];
double CrossDown[];
double b4plusdi,nowplusdi,b4minusdi,nowminusdi;
int flagval1 = 0;
int flagval2 = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
IndicatorBuffers(2);
if (ArrowType == 0) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 108);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 108);
}
else if (ArrowType == 1) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 233);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 234);
}
else if (ArrowType == 2) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 225);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 226);
}
else if (ArrowType == 3) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 241);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 242);
}
else if (ArrowType == 4) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 221);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 222);
}
else if (ArrowType == 5) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 217);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 218);
}
else if (ArrowType == 6) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 228);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 230);
}
else if (ArrowType == 7) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 236);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 238);
}
else if (ArrowType == 8) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 246);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 248);
}
else if (ArrowType == 9) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 67);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 68);
}
else if (ArrowType == 10) {
SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 71);
SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 72);
}
//----
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| AltrTrend_Signal_v2_2 |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit,i;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i=limit; i>=0; i--)
{
b4plusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,i+1);
nowplusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,i);
b4minusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_MINUSDI,i+1);
nowminusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_MINUSDI,i);
if (b4plusdi<=b4minusdi && nowplusdi>nowminusdi)
{
if (i == 1 && flagval1==0)
{
flagval1=1;
flagval2=0;
if (AlertON) Alert(" ADX BUY signal at Ask=",Ask,"\n Bid=",Bid,"\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
if (EmailON) SendMail("ADX BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
if (SoundON) PlaySound(SoundFileName);
}
CrossUp[i] = Low[i] - iATR(NULL,0,20,i)/2.0;
}
else if (b4plusdi>=b4minusdi && nowplusdi<nowminusdi)
{
if (i == 1 && flagval2==0)
{
flagval2=1;
flagval1=0;
if (AlertON) Alert("ADX SELL signal at Ask=",Ask,"\n Bid=",Bid,"\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
if (EmailON) SendMail("ADX SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
if (SoundON) PlaySound(SoundFileName);
}
CrossDown[i] = High[i] + iATR(NULL,0,20,i)/2.0;
}
}
return(0);
}
Comments