EMA-Crossover_Signal_alert

Download script
Author: Copyright � 2005, Jason Robinson (jnrtrading)
EMA-Crossover_Signal_alert

This tool is designed to help traders identify specific momentum shifts in the market by tracking the interaction between two different Exponential Moving Averages (EMAs). Essentially, it acts as a visual "crosshair" that highlights exactly when a faster-moving trend line passes through a slower-moving one.

Core Functionality

The primary purpose of this script is to provide clear visual cues for trend reversals. While many traders use moving averages to see the general direction of the market, these lines can sometimes become cluttered or difficult to read on certain chart zoom levels. This tool solves that problem by placing distinct markers (arrows) directly on the chart at the precise moment a "crossover" occurs.

How the Logic Works

The script continuously monitors two different timeframes of price averages:

  • Faster EMA: A shorter period average that reacts quickly to recent price changes.
  • Slower EMA: A longer period average that represents the broader, more established trend.

To determine if a signal should be shown, the logic performs a three-point check on every historical candle:

  1. The Current State: It checks if the Faster EMA is currently above or below the Slower EMA.
  2. The Previous State: It looks back at the previous candle to see where the lines were positioned.
  3. Confirmation: It ensures that the "crossing" happened specifically at the current point, rather than just moving in the same direction.

Visual and Audible Alerts

When the script detects these specific crossovers, it performs two main actions:

  • Visual Markers: It places an arrow on the chart. An upward cross (where the faster trend moves above the slower trend) typically indicates bullish momentum, while a downward cross (where the faster trend moves below) indicates bearish momentum. The script intelligently calculates the spacing for these arrows based on recent price volatility so they remain clearly visible and don't overlap with the candles.
  • Real-Time Notifications: If enabled in the settings, the tool will trigger an audible alert sound and a pop-up message on your screen the moment a crossover is confirmed on the most recent completed candle. This prevents you from having to watch the chart constantly to catch a trend change.

Key Benefits for Traders

  • Clutter Reduction: Because it marks the specific crossing point, you can choose to remove the actual moving average lines from your chart entirely, leading to a cleaner workspace.
  • Precision: It eliminates the guesswork of deciding "Has the line crossed yet?" by providing a definitive visual confirmation.
  • Customization: Users can adjust the periods for both the fast and slow averages to suit different trading styles, whether they prefer scalping (fast reactions) or swing trading (slower, more stable trends).
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
13 Views
0 Downloads
0 Favorites
EMA-Crossover_Signal_alert
//+------------------------------------------------------------------+
//|                                         EMA-Crossover_Signal.mq4 |
//|         Copyright © 2005, Jason Robinson (jnrtrading)            |
//|                   http://www.jnrtading.co.uk                     |
//+------------------------------------------------------------------+

/*
  +------------------------------------------------------------------+
  | Allows you to enter two ema periods and it will then show you at |
  | Which point they crossed over. It is more usful on the shorter   |
  | periods that get obscured by the bars / candlesticks and when    |
  | the zoom level is out. Also allows you then to remove the emas   |
  | from the chart. (emas are initially set at 5 and 6)              |
  +------------------------------------------------------------------+
*/   
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)"
#property link      "http://www.jnrtrading.co.uk"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Red

double CrossUp[];
double CrossDown[];
extern int FasterEMA = 5;
extern int SlowerEMA = 6;
extern bool SoundON=true;
double alertTag;
 double control=2147483647;
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY,2);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY,2);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double fasterEMAnow, slowerEMAnow, fasterEMAprevious, slowerEMAprevious, fasterEMAafter, slowerEMAafter;
   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;
       
      fasterEMAnow = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      fasterEMAprevious = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i+1);
      fasterEMAafter = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);

      slowerEMAnow = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      slowerEMAprevious = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i+1);
      slowerEMAafter = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);
      
      if ((fasterEMAnow > slowerEMAnow) && (fasterEMAprevious < slowerEMAprevious) && (fasterEMAafter > slowerEMAafter)) {
         CrossUp[i] = Low[i] - Range*0.5;
      }
      else if ((fasterEMAnow < slowerEMAnow) && (fasterEMAprevious > slowerEMAprevious) && (fasterEMAafter < slowerEMAafter)) {
          CrossDown[i] = High[i] + Range*0.5;
      }
        if (SoundON==true && i==1 && CrossUp[i] > CrossDown[i] && alertTag!=Time[0]){
         Alert("EMA Cross Trend going Down on ",Symbol()," ",Period());
        alertTag = Time[0];
      }
        if (SoundON==true && i==1 && CrossUp[i] < CrossDown[i] && alertTag!=Time[0]){
       Alert("EMA Cross Trend going Up on ",Symbol()," ",Period());
        alertTag = Time[0];
        } 
  }
   return(0);
}

Comments