EMA-alert_001
Download scriptThis tool is designed to act as a real-time monitoring assistant for traders who want to be notified when market prices get dangerously close to a specific moving average. Instead of requiring you to watch the charts constantly, it automates the process of detecting "proximity" and alerts you the moment price enters your predefined zone of interest.
How the Logic Works
1. Customizing Your Baseline The script begins by calculating a Moving Average based on your preferences. You can choose between different types of averages (such as Simple, Exponential, Smoothed, or Linear Weighted) and define exactly how many past bars of data the calculation should look at. This baseline represents the "trend" of the market.
2. Measuring the Gap The script continuously monitors the distance between the current market price and that moving average. It creates a dynamic measurement to see how much "room" is left between where the price is currently trading and the moving average line.
3. The Proximity Trigger This is the core functionality of the tool. You can set a specific "pip distance"—a custom threshold that defines your personal "danger zone" or "interest zone." The script constantly checks: Is the current price within X pips of the moving average?
If the price crosses into that specific distance, the logic triggers an immediate action.
4. Multi-Channel Notifications To ensure you don't miss a move, the script is equipped with three different ways to notify you simultaneously:
- Visual Pop-ups: A standard alert window appears on your trading platform.
- Audio Alerts: A sound file plays to grab your attention immediately.
- Email Notifications: If enabled, it can send a direct message to your inbox detailing which currency pair has reached the proximity threshold.
Summary for the User
Essentially, this script acts like a "proximity sensor" for trading. You tell the tool what trend line matters to you and how close you want to be notified of it. When the price enters that small window, the script handles the heavy lifting by alerting you instantly, allowing you to react to potential price reversals or breakouts without having to stare at the screen every second.
//+------------------------------------------------------------------+
//| 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 PeriodMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int 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,period,0,PeriodMode,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 ",period," period MA");
if(Sound_Alert) PlaySound("alert.wav");
if(Email_Alert) SendMail("Price Alert on "+Symbol(),"Price is within "+pip_distance+" pips of "+period+" period MA");
lastimealert= Time[0];
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments