M.A.C.H_X_alert_v2

Author: Copyright � 2007, MetaQuotes Software Corp.
M.A.C.H_X_alert_v2

This script is a custom technical analysis tool designed to identify specific trend-reversal moments on a trading chart. It functions by monitoring the relationship between two moving averages—specifically, a "fast" moving average and a "slow" moving average—to detect when they intersect each other.

Core Logic and Mechanics

The primary objective of this tool is to spot "crossovers." In technical analysis, when a fast-moving average (which reacts quickly to price changes) crosses over a slower-moving average (which represents the broader trend), it often signals a shift in market momentum.

To ensure accuracy, the script performs the following logic:

  • Moving Average Tracking: The tool constantly calculates two different Simple Moving Averages (SMA). It looks at three specific points in time: the current price point, the previous bar, and the subsequent bar.
  • Crossover Verification: Instead of just reacting to a single point of contact, the script validates a crossover by checking if the fast average was below the slow average in the past and has moved above it in the present (an "Up" cross), or vice versa (a "Down" cross).
  • Dynamic Range Calculation: The script calculates the average price range (the distance between the highest and lowest prices) over a 10-bar period. It uses this data to position visual markers on your chart at a consistent distance from the candles, ensuring the signals are clearly visible regardless of how volatile the market is.

Visual and Audio Alerts

When the script identifies these specific crossover conditions, it executes two actions:

  1. Visual Markers: It places distinct arrows on the chart. Yellow markers appear below the candle for upward crossovers, and Red markers appear above the candle for downward crossovers.
  2. Real-Time Notifications: If enabled in the settings, the script will trigger a proactive alert popup on your trading platform. To prevent "alert fatigue," the logic includes a filter to ensure you are only notified once per crossover event rather than being alerted on every single price tick.

Summary for the Trader

Essentially, this tool filters out market noise by focusing on the interaction between two trend lines. It automates the visual task of watching these lines intersect, providing you with clear, color-coded signals and immediate notifications whenever the momentum shifts from bullish to bearish (or vice versa).

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
M.A.C.H_X_alert_v2
//+------------------------------------------------------------------+
//|                                                   machXalert.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Red
//----
#property indicator_width1 2
#property indicator_width2 2
//----
double CrossUp[];
double CrossDown[];
//----
extern int FasterSMA       =12;
extern int FASTER_SMA_SHIFT=3;
extern int SlowerSMA       =25;
extern int SLOWER_SMA_SHIFT=5;
extern bool Alerts=true;
//----
int upalert=true,downalert=true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 74);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 74);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  int start() 
  {
   int limit, i, counter;
   double fasterSMAnow, slowerSMAnow, fasterSMAprevious, slowerSMAprevious, fasterSMAafter, slowerSMAafter;
   double Range, AvgRange;
   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(i=0; i<=limit; i++) 
     {
      counter=i;
      Range=0;
      AvgRange=0;
      for(counter=i ;counter<=i+9;counter++)
        {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
        }
      Range=AvgRange/10;
//----
      fasterSMAnow=iMA(NULL, 0, FasterSMA, FASTER_SMA_SHIFT, MODE_SMA, PRICE_CLOSE, i);
      fasterSMAprevious=iMA(NULL, 0, FasterSMA, FASTER_SMA_SHIFT, MODE_SMA, PRICE_CLOSE, i+1);
      fasterSMAafter=iMA(NULL, 0, FasterSMA, FASTER_SMA_SHIFT, MODE_SMA, PRICE_CLOSE, i-1);
      slowerSMAnow=iMA(NULL, 0, SlowerSMA, SLOWER_SMA_SHIFT, MODE_SMA, PRICE_CLOSE, i);
      slowerSMAprevious=iMA(NULL, 0, SlowerSMA, SLOWER_SMA_SHIFT, MODE_SMA, PRICE_CLOSE, i+1);
      slowerSMAafter=iMA(NULL, 0, SlowerSMA, SLOWER_SMA_SHIFT, MODE_SMA, PRICE_CLOSE, i-1);
//----
        if ((fasterSMAnow > slowerSMAnow) && (fasterSMAprevious < slowerSMAprevious) && (fasterSMAafter > slowerSMAafter)) 
        {
         CrossUp[i]=Low[i] - Range*0.5;
         if(i<=2 && Alerts && !upalert)
           {
            Alert (Symbol()," ",Period(),"M  SMACross UP ");
            //SendMail("SMA Cross Up on "+Symbol(),"");
            upalert=true;
            downalert=false;
           }
        }
        else if ((fasterSMAnow < slowerSMAnow) && (fasterSMAprevious > slowerSMAprevious) && (fasterSMAafter < slowerSMAafter)) 
        {
            CrossDown[i]=High[i] + Range*0.5;
            if(i<=2 && Alerts && !downalert)
              {
               Alert (Symbol()," ",Period(),"M  SMACross DOWN ");
               //SendMail("SMA Cross Down on "+Symbol(),"");
               downalert=true;
               upalert=false;
              }
           }
     }
   //----
   return(0);
  }
//+------------------------------------------------------------------+

Comments