ADXcrossesAlert

Author: Copyright � 2004, MetaQuotes Software Corp.
ADXcrossesAlert

This script is designed as a visual signaling tool for traders who use the Average Directional Index (ADX) to identify trends in the financial markets. Its primary purpose is to monitor the relationship between two specific components of the ADX—the Plus Directional Indicator (+DI) and the Minus Directional Indicator (-DI)—and provide real-time alerts when these two values cross over each other.

Core Logic and Functionality

The script works by continuously analyzing price movements to determine which direction the market is leaning. In technical terms, it tracks whether the "buying pressure" (+DI) is moving above the "selling pressure" (-DI), or vice versa.

1. Trend Identification (The Crossover) The tool looks for specific moments of transition:

  • Bullish Signal: When the +DI rises above the -DI, the script identifies a potential upward trend. It marks this on your chart with a visual icon located just below the current price candle.
  • Bearish Signal: When the -DI rises above the +DI, the script identifies a potential downward trend. It marks this on your chart with a visual icon located just above the current price candle.

2. Smart Visual Positioning To ensure that the signals do not clutter the actual price candles or overlap with other indicators, the script includes an automatic "buffer" logic. Depending on the timeframe you are viewing (e.g., 1-minute charts versus daily charts), the script calculates a specific distance to place the icons. This ensures that the signals stay neatly organized and readable regardless of how zoomed in or out your chart is.

3. Real-Time Alerts Beyond just visual cues, the script features an automated notification system. When a crossover occurs (a shift in momentum), the tool can trigger a pop-up alert on your trading platform. These alerts provide immediate information including:

  • The direction of the trend (Up or Down).
  • The specific currency pair being traded.
  • The timeframe of the chart.
  • The current Ask and Bid prices.

Key Features for the User

  • Customizable Sensitivity: The script allows you to define a "Period" (defaulted to 14), which determines how much historical data is used to calculate the trend. Adjusting this helps you choose between faster, more sensitive signals or slower, more stable trend confirmations.
  • Noise Reduction: By requiring a confirmed crossover of the two indicators rather than just tracking the raw price, the tool helps filter out minor market fluctuations, focusing instead on shifts in momentum.
  • Automated Monitoring: The logic scans through the historical data to populate the chart with past signals and then monitors live market ticks to catch new movements as they happen in real-time.
Indicators Used
Movement directional index
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
17 Views
0 Downloads
0 Favorites
ADXcrossesAlert
//+------------------------------------------------------------------+
//|                                                   ADXcrosses.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 Lime
#property indicator_color2 Red
//---- input parameters
extern int ADXcrossesPeriod=14;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
extern bool SoundON=true;
double alertBar;
//----
double b4plusdi, b4minusdi, nowplusdi, nowminusdi;
int    nShift;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, 0, 1);
   SetIndexArrow(0, 108);
   SetIndexBuffer(0, ExtMapBuffer1);
//----
   SetIndexStyle(1, DRAW_ARROW, 0, 1);
   SetIndexArrow(1, 108);
   SetIndexBuffer(1, ExtMapBuffer2);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("ADXcrosses("+ADXcrossesPeriod+")");
   SetIndexLabel(0, "ADXcrUp");
   SetIndexLabel(1, "ADXcrDn");
//----
   switch(Period())
     {
      case     1: nShift=1;   break;
      case     5: nShift=3;   break;
      case    15: nShift=5;   break;
      case    30: nShift=10;  break;
      case    60: nShift=15;  break;
      case   240: nShift=20;  break;
      case  1440: nShift=80;  break;
      case 10080: nShift=100; break;
      case 43200: nShift=200; break;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   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=1; i < limit; i++)
     {
      b4plusdi=iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_PLUSDI, i + 1);
      nowplusdi=iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_PLUSDI, i);
      b4minusdi=iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_MINUSDI, i + 1);
      nowminusdi=iADX(NULL, 0, ADXcrossesPeriod, PRICE_CLOSE, MODE_MINUSDI, i);
      //----
      if(b4plusdi < b4minusdi && nowplusdi > nowminusdi)
        {
         ExtMapBuffer1[i]=Low[i] - nShift*Point;
         if (SoundON==true && Bars>alertBar )
    Alert("ADX UP on ",Symbol()," M",Period()," at Ask=",Ask," Bid=",Bid);
        alertBar = Bars;}
         
      //----
      if(b4plusdi > b4minusdi && nowplusdi < nowminusdi)
         {
         ExtMapBuffer2[i]=High[i] + nShift*Point;
                  if (SoundON==true && Bars>alertBar )
        Alert("ADX Down on ",Symbol()," M",Period()," at Ask=",Ask," Bid=",Bid);
          alertBar = Bars;}
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments