EMA Crossover Signal+Email_001
Download scriptThis script is a specialized trading tool designed to help traders identify specific momentum shifts in the financial markets by monitoring two different moving averages (Exponential Moving Averages). It automates the detection of "crossovers," which occur when a fast-moving trend line intersects with a slower, broader trend line.
Core Functionality
The primary purpose of this tool is to eliminate visual clutter and provide precise alerts for trend changes. While traders often look at moving averages manually, these lines can sometimes be difficult to read clearly on a crowded chart. This script identifies the exact moment one average overtakes the other and places a visual marker (an arrow) on the chart to highlight the entry or exit point.
How the Logic Works
The script continuously analyzes the price action using the following logic:
- Trend Analysis: It tracks two distinct averages—a "Faster" EMA (which reacts quickly to recent price changes) and a "Slower" EMA (which reflects the long-term trend).
- Crossover Detection: The script looks for specific mathematical conditions where the Faster EMA moves from below the Slower EMA to above it (an upward trend), or vice versa (a downward trend).
- Visual Markers: When a crossover is confirmed, the script automatically places an arrow on the chart. It calculates the distance of these arrows based on recent price volatility to ensure they are positioned clearly above or below the candles, making them easy to see regardless of your zoom level.
Notification System
Beyond just providing visual cues, the script acts as an automated monitoring system. It is configured to provide real-time notifications through several channels:
- Audio Alerts: The tool can trigger a sound directly within your trading platform whenever a crossover occurs.
- Email Notifications: If enabled, the script can send an instant email alert to your registered address, notifying you of a trend change even if you are not actively looking at your screen.
- Smart Alerting: To prevent your workspace from being overwhelmed by constant noise, the script includes logic to manage how often alerts are triggered, ensuring you receive clear information about new trend movements.
Summary for the User
Essentially, this tool serves as a "sentinel." It watches the market 24/7, identifies the precise moment the momentum shifts based on your preferred moving average settings, and informs you immediately via sound, email, or visual markers so you can make faster, more informed trading decisions.
//+------------------------------------------------------------------+
//| 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;
extern bool ContinuousSound = 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])
{
if (ContinuousSound == true)
{
Alert("EMA Cross Trend going Down on ",Symbol()," ",Period());
}
else if (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])
{
if (ContinuousSound == true)
{
Alert("EMA Cross Trend going Up on ",Symbol()," ",Period());
}
else if (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