ADXcrosses&sound
Download scriptThis tool is designed to help traders identify specific momentum shifts in the market by monitoring the interaction between two primary trend indicators: the Plus Directional Indicator (+DI) and the Minus Directional Indicator (-DI). These components are derived from the Average Directional Index (ADX) system, which is commonly used to determine the strength and direction of a price trend.
How the Logic Works
The script scans historical and live price data to look for "crossovers"—moments where the leading lines representing upward pressure and downward pressure switch positions.
- Identifying Downward Shifts: The tool looks for instances where the upward trend line was previously higher than the downward trend line but has since dropped below it. When this happens, the script identifies a potential loss of bullish momentum.
- Identifying Upward Shifts: Conversely, it monitors for moments where the downward trend line was previously higher but has moved below the upward trend line, signaling a potential gain in bullish momentum.
Visual and Audible Alerts
To make these signals easy to act upon, the script provides two types of feedback:
- On-Chart Markers: Instead of just showing lines on a graph, the script places visual symbols (arrows) directly on your price chart at the exact moment a crossover is detected.
- The markers are intelligently positioned slightly above or below the candle to ensure they remain clear and do not clutter the actual price action.
- Audio Notifications: The script can be configured to play an audible alert sound whenever a new crossover occurs in real-time. It includes built-in logic to ensure that the sound only plays once per signal, preventing repetitive noise during a single trading candle.
Key Customization
The tool allows you to adjust the "Period" setting, which determines how much historical data the script analyzes to calculate the trend lines. A shorter period makes the tool more sensitive to quick fluctuations, while a longer period focuses on broader, more established trends.
//+------------------------------------------------------------------+
//| ADXcrosses_true_with_sound.mq4 |
//| 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 Blue
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//---- input parameters
extern bool Sound = true;
extern int ADXcrossesPeriod = 14;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//----
double b4plusdi, b4minusdi, nowplusdi, nowminusdi, nShift;
datetime uplast=0;
datetime dnlast=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 233);
SetIndexBuffer(0, ExtMapBuffer1);
//----
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 234);
SetIndexBuffer(1, ExtMapBuffer2);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("ADXcrosses(" + ADXcrossesPeriod + ")");
SetIndexLabel(0, "ADXcrUp");
SetIndexLabel(1, "ADXcrDn");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0)
return(-1);
//---- last counted bar will be recounted
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);
nowplusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE,
MODE_PLUSDI, i + 1);
b4minusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE,
MODE_MINUSDI, i);
nowminusdi = iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE,
MODE_MINUSDI, i + 1);
nShift = iATR(NULL,0,100,i)*0.5;
ExtMapBuffer1[i] = 0.0; ExtMapBuffer2[i] = 0.0;
//----
if(b4plusdi > b4minusdi && nowplusdi < nowminusdi)
ExtMapBuffer1[i] = Low[i] - nShift;
//----
if(b4plusdi < b4minusdi && nowplusdi > nowminusdi)
ExtMapBuffer2[i] = High[i] + nShift;
}
//---- Sound
if(ExtMapBuffer1[0]!=0.0 && Time[i]>uplast && Sound==true)
{
PlaySound("alert.wav");
uplast=Time[i];
}
if(ExtMapBuffer2[0]!=0.0 && Time[i]>dnlast && Sound==true)
{
PlaySound("alert.wav");
dnlast=Time[i];
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments