Alert SMA-EMA CrossOver
Download scriptThis tool is designed to help traders identify potential entry points in the financial markets by tracking the interaction between two different types of moving averages. By monitoring these trends, the script automatically detects "crossovers"—moments when the price momentum shifts significantly enough to suggest a new trend.
How the Logic Works
The script operates by calculating and plotting two distinct mathematical averages on your trading chart:
- Fast Moving Average: A quicker-reacting line that follows short-term price changes.
- Slow Moving Average: A smoother line that represents the broader, long-term trend.
Instead of requiring you to stare at the charts constantly, the script acts as an automated watchdog. It continuously compares the current position of these two lines against their previous positions to identify specific "cross-over" events.
Trade Signal Detection
The tool looks for two primary types of signals:
- Buy Signals (Upward Trend): When the faster average moves above the slower average, the script identifies this as a potential shift toward an upward trend. When this happens, the script places a visual arrow on the chart and triggers a notification.
- Sell Signals (Downward Trend): Conversely, when the faster average drops below the slower average, it signals a potential downward trend. The script marks this with a different arrow to notify you of the shift.
Automated Notifications
To ensure you never miss a critical market movement, the script is equipped with a multi-channel alert system. When a crossover occurs, the tool performs three actions simultaneously:
- Visual Alerts: It draws arrows directly on your trading candles for immediate on-screen confirmation.
- Audible Alerts: It plays a sound file to grab your attention if you are looking away from the screen.
- Pop-up Alerts: It generates an on-screen message displaying the specific price and trend details.
- Email Notifications: If enabled, the script will automatically send an email to your registered address, providing you with the exact price, symbol, and timeframe of the crossover, allowing you to stay informed even when you aren't at your computer.
Smart Adjustments
The tool also includes built-in intelligence to handle different timeframes. Depending on whether you are trading on a 1-minute chart or a daily chart, the script automatically adjusts the spacing of its visual markers, ensuring that the arrows remain clearly visible and don't clutter your screen regardless of the scale you choose.
//+------------------------------------------------------------------+
//| Alert SMA-EMA CrossOver.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 4
#property indicator_color1 Red
#property indicator_color2 Aqua
#property indicator_color3 DodgerBlue
#property indicator_color4 Magenta
//---- Variables Externes
extern int SMAPeriod = 13;
extern int EMAPeriod = 6;
extern int TimeFrame = 240;
extern bool Email = True;
//---- Indicateurs
double SMACurrent, SMAPrevious, EMACurrent, EMAPrevious;
int nShift, digit, digits;
int i,j,limit,counted_bars;
//---- Buffers
double ExtMapBuffer1[]; //SMA
double ExtMapBuffer2[]; //EMA
double ExtMapBuffer3[]; //Fleche Haut
double ExtMapBuffer4[]; //Fleche Bas
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//---- Styles et couleur des Lignes
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
//---- Styles et couleur des Fleches
SetIndexStyle(2, DRAW_ARROW, 0, 1); // Fleche vers le haut
SetIndexArrow(2, 233);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexStyle(3, DRAW_ARROW, 0, 1); // Fleche vers le bas
SetIndexArrow(3, 234);
SetIndexBuffer(3, ExtMapBuffer4);
//----
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;
}
//----
digits = MarketInfo(Symbol(),MODE_DIGITS);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
counted_bars=IndicatorCounted();
//----
if(counted_bars<0)
return(-1);
if(counted_bars>0)
counted_bars--;
limit=Bars-counted_bars;
for(i=0; i<limit; i++)
{
SMACurrent=iMA(NULL,0,18,0,MODE_EMA,PRICE_CLOSE,i);
SMAPrevious=iMA(NULL,0,18,0,MODE_EMA,PRICE_CLOSE,i+1);
ExtMapBuffer1[i]=SMACurrent;
EMACurrent=iMA(NULL,0,28,0,MODE_EMA,PRICE_CLOSE,i);
EMAPrevious=iMA(NULL,0,28,0,MODE_EMA,PRICE_CLOSE,i+1);
ExtMapBuffer2[i]=EMACurrent;
//---- Dessin des fleches, future entré en trade
//---- Buy
if((EMACurrent > SMACurrent+ digit*Point) && ( EMAPrevious <= SMACurrent)) // Croisement WMA8 up bord supérieur du tunnel
{
ExtMapBuffer3[i] = Low[i] - nShift*Point;
Alert("SMA-EMA CrossOver Going for a BUY Trend Sesion ",SMACurrent," Price ",Close[1]," for ", Symbol(),"-",Period());
PlaySound("alert.wav");
if (Email)
{
SendMail("SMA-EMA CrossOver", "SMA-EMA CrossOver Going for a BUY Trend Sesion "+DoubleToStr(SMACurrent, digits)+" Price "+DoubleToStr(Close[1], digits)+" for "+Symbol()+"-"+Period());
}
}
//---- Sell
if((SMACurrent > EMACurrent+ digit*Point) && ( EMAPrevious >= SMACurrent)) // Croisement WMA8 down bord inférieur du tunnel
{
ExtMapBuffer4[i] = High[i] + nShift*Point;
Alert("SMA-EMA CrossOver Going for a SELL Trend Sesion ",SMACurrent," Price ",Close[1]," for ", Symbol(),"-",Period());
PlaySound("alert.wav");
if (Email)
{
SendMail("SMA-EMA CrossOver", "SMA-EMA CrossOver Going for a SELL Trend Sesion "+DoubleToStr(SMACurrent, digits)+" Price "+DoubleToStr(Close[1], digits)+" for "+Symbol()+"-"+Period());
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments