EMA Crossover Signal+Email_002

Download script
Author: Copyright � 2005, Jason Robinson (jnrtrading)
EMA Crossover Signal+Email_002

This script is designed as a visual and notification tool for traders who use Exponential Moving Averages (EMA) to determine market trends. Its primary purpose is to identify the exact moment two different moving averages cross paths, which often signals a change in momentum or a potential entry point for a trade.

How the Logic Works

The script monitors two distinct timeframes of price movement: a "Faster" EMA and a "Slower" EMA. By comparing these two lines, the tool looks for specific crossover events:

  • Bullish Signal (Trend Up): When the Faster EMA moves from below the Slower EMA to above it, the script identifies this as an upward trend shift.
  • Bearish Signal (Trend Down): When the Faster EMA moves from above the Slower EMA to below it, the script identifies this as a downward trend shift.

Key Features and Visual Aids

To make these signals easy to interpret, the script performs several automated actions:

  • Visual Markers: Instead of forcing you to squint at tiny lines on a crowded chart, the script places distinct arrows directly on the price candles. These markers appear precisely where the crossover occurs, helping you identify historical trends even when you are zoomed out or looking at different timeframes.
  • Dynamic Positioning: The tool automatically calculates the "Range" of the price action around the crossover point. It then places the arrows slightly above or below the candle (depending on the direction) so that they remain clearly visible without overlapping the price bars.
  • Real-Time Alerts: The script doesn't just show you what happened in the past; it can notify you of what is happening right now. If a crossover occurs on the most recent completed bar, the tool can trigger:
    • Audio Alerts: A sound notification within your trading platform.
    • Email Notifications: An automated email sent to your registered address providing the symbol name and the timeframe of the move.
  • Smart Filtering: The system includes a "tag" logic that prevents it from sending multiple alerts for the same signal. It ensures you only receive one notification per trend shift, keeping your inbox and workspace organized.

Customization

Users have the flexibility to adjust the settings to match their specific trading style. You can define the length of both the Faster and Slower EMAs, as well as toggle the sound and email notifications on or off depending on your preference.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt sends emails
17 Views
0 Downloads
0 Favorites
EMA Crossover Signal+Email_002
//+------------------------------------------------------------------+
//|                                   EMA-Crossover_Signal+Email.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 SeaGreen
#property indicator_color2 Red

double CrossUp[];
double CrossDown[];
extern int FasterEMA = 5;
extern int SlowerEMA = 50;
extern bool SoundON=true;
extern bool EmailON=true;
double alertTag;
 double control=2147483647;
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY,3);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY,3);
   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 (EmailON==true && i==1 && CrossUp[i] > CrossDown[i] && alertTag!=Time[0]){
         SendMail("EMA Cross Trend going Down on "+Symbol()+" ",Period());
        
      }
      
        if (SoundON==true && i==1 && CrossUp[i] < CrossDown[i] && alertTag!=Time[0]){
       Alert("EMA Cross Trend going Up on ",Symbol()," ",Period());
        alertTag = Time[0];
        } 
        
        if (EmailON==true && i==1 && CrossUp[i] < CrossDown[i] && alertTag!=Time[0]){
         SendMail("EMA Cross Trend going Up on "+Symbol()+" ",Period());
        
        }    
  }
   return(0);
}

Comments