EMA-alert and email alert

Download script
Author: Copyright � 2007, MetaQuotes Software Corp.
EMA-alert and email alert

This script is designed as a specialized monitoring tool for traders who use the Exponential Moving Average (EMA) to gauge market trends. Its primary purpose is to act as an automated "early warning system," notifying you the moment the current market price enters a specific proximity to this moving average line.

How the Logic Works

1. Trend Monitoring The script continuously calculates the Exponential Moving Average based on a user-defined period (by default, 34). Unlike a standard moving average, the EMA gives more importance to recent price data, making it highly responsive to current market momentum.

2. Proximity Detection Instead of simply alerting you when the price touches or crosses the EMA line, the script looks for a "buffer zone." It monitors the gap between the current market price (specifically the Bid price) and the EMA value. If that gap narrows to a specific distance—defined by the user in "pips"—the system recognizes this as a significant event.

3. Smart Alerting System To ensure you stay informed without being overwhelmed, the script includes several notification layers that can be customized:

  • Visual Alerts: A pop-up box appears on your screen to grab your attention immediately.
  • Audio Notifications: A sound file plays to alert you if you are looking away from your workstation.
  • Email Notifications: The system can send a direct message to your inbox, providing the specific symbol and details of the price proximity.

4. Intelligent Filtering The script is programmed with a "time-stamp" memory. This prevents the system from spamming you with repeated alerts for the same price movement. It ensures that once an alert is triggered for a specific candle, it remains silent until a new price movement occurs on a subsequent bar.

Key Benefits for the User

By using this tool, you don't have to watch your charts constantly to see if the price is approaching a key level. It automates the "watchdog" role, allowing you to react quickly to potential trend changes or reversals whenever the price enters your predefined zone of interest.

Indicators Used
Moving average indicator
Miscellaneous
It issuies visual alerts to the screenIt plays sound alertsIt sends emails
11 Views
0 Downloads
0 Favorites
EMA-alert and email alert
//+------------------------------------------------------------------+
//|                                                   EMA-alert.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 1

//---- input parameters
extern int ema_period = 34;
//---- buffers
double ExtMapBuffer1[];
extern bool Box_Alert=true;
extern bool Sound_Alert=true;
extern bool Email_Alert=false;
extern int pip_distance = 10;
datetime lastimealert;
//----
double ema_value;
  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
  
    SetIndexBuffer(0, ExtMapBuffer1);

//---- name for DataWindow and indicator subwindow label
  
//----
   
    return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    int limit;
    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(int i = 0; i < limit; i++)
      {
       ema_value= iMA(NULL,0,ema_period,0,MODE_EMA,PRICE_CLOSE,i);
        //----
        ExtMapBuffer1[i] = ema_value-Ask ;
        if(MathAbs(ema_value-Bid)<=pip_distance*Point&& lastimealert!= Time[0] )
            {
            
            if(Box_Alert) Alert("Price is within ",pip_distance," pips of ",ema_period," period EMA");
            if(Sound_Alert) PlaySound("alert.wav");
            if(Email_Alert) SendMail("Price Alert on "+Symbol(),"Price is within "+pip_distance+" pips of "+ema_period+" period EMA");
            lastimealert= Time[0];
            }
            
        }




//----
    return(0);
  }
//+------------------------------------------------------------------+

Comments