This technical script is designed to act as a visual and audible notification system for traders who use the Average Directional Index (ADX) to identify market trends. Its primary purpose is to detect specific "crossover" moments where the momentum of the market shifts from one direction to another, providing clear signals for potential buying or selling opportunities.
How it Works
The logic operates by constantly monitoring two specific components of the ADX indicator: the Plus Directional Index (+DI), which tracks upward price movement, and the Minus Directional Index (-DI), which tracks downward price movement.
The script looks for two specific types of interactions:
- Buy Signals: The tool watches for the moment the Plus DI line crosses above the Minus DI line. This suggests that bullish momentum is overtaking bearish momentum. When this happens, the script places a visual arrow on the chart just below the current price candle.
- Sell Signals: Conversely, the tool monitors for the moment the Minus DI line crosses above the Plus DI line. This indicates that bearish momentum is taking over. In this case, it places a visual arrow just above the price candle.
Features and Notifications
Beyond just providing visual cues on your chart, the script is designed to actively alert you to these movements in real-time:
- Audio Alerts: If enabled, the script will play a specific sound file immediately when a crossover occurs, ensuring you don't miss a move while away from the screen.
- On-Screen Comments: The tool automatically prints a text comment on your trading platform. This comment displays the current currency pair, the timeframe being used, the type of signal (Buy or Sell), and the exact price at which the crossover was detected.
- Signal Filtering: The logic includes a "buffer" system to ensure that you only receive one notification per crossover event. This prevents the script from triggering multiple alerts for the same single move, keeping your workspace clean and your notifications organized.
Summary for the User
Essentially, this tool automates the tedious task of watching lines cross on an indicator. It "scans" the market for you and highlights the exact moment the trend changes direction, providing a visual arrow, an audio cue, and a written price confirmation to help you make faster, more informed trading decisions.
//+------------------------------------------------------------------+
//| ADX Crossing_Alert.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, 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
//---- input parameters
extern int ADXbars=14;
extern int CountBars=350;
extern bool UseSound = True;
extern string SoundFile = "expert.wav";
//---- buffers
double val1[];
double val2[];
double b4plusdi,nowplusdi,b4minusdi,nowminusdi;
bool SoundBuy = False;
bool SoundSell = False;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
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,limit,CountedBars = IndicatorCounted();
if (CountedBars < 1)
{
for (i=0; i<=CountBars; i++) {val1[i] = 0.0; val2[i] = 0.0;}
}
if(CountedBars > 0) CountedBars--;
limit = Bars - CountedBars;
for (shift = limit; 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;
}
}
if (val1[0] != EMPTY_VALUE && val1[0] != 0 && SoundBuy)
{
SoundBuy = False;
if (UseSound) PlaySound (SoundFile);
Comment (Symbol()," ",Period(),"ADX Crossing BUY @ ",Ask);
// Alert (Symbol()," ",Period(),"ADX Crossing BUY @ ",Ask);
}
if (!SoundBuy && (val1[0] == EMPTY_VALUE || val1[0] == 0)) SoundBuy = True;
if (val2[0] != EMPTY_VALUE && val2[0] != 0 && SoundSell)
{
SoundSell = False;
if (UseSound) PlaySound (SoundFile);
Comment (Symbol()," ",Period(), "ADX Crossing Sell @",Bid);
// Alert (Symbol()," ",Period(), "ADX Crossing Sell @",Bid);
}
if (!SoundSell && (val2[0] == EMPTY_VALUE || val2[0] == 0)) SoundSell = True;
return(0);
}
//+------------------------------------------------------------------+
Comments