Alert_MA_v2
Download scriptThis tool is designed to provide traders with real-time notifications based on the behavior of a Moving Average (MA) relative to current market prices. It functions as an automated monitoring system that alerts you when specific price conditions are met, helping you stay informed without constantly staring at live charts.
The logic operates in two distinct modes depending on how you prefer to set your preferences:
Mode 1: Proximity Alerts
In this standard mode, the script monitors how close the current market price is to a Moving Average line. You can define the specific "window" or range of distance you are interested in. If the market price moves into this predefined zone around the Moving Average, the system will trigger an alert. This is useful for identifying when the price is "hugging" or interacting closely with a key trend line.
Mode 2: Price Target Crossing
This mode switches the logic from monitoring distance to monitoring specific milestones. Instead of looking at a range, you set a specific price target (for example, a certain resistance level). The script then tracks the Movement Average's position relative to that target.
It specifically looks for "crosses": it triggers an alert the moment the Moving Average moves from below your target price to above it, or vice versa. To ensure you aren't bombarded with constant notifications, the script includes a "one-time" memory feature; once a target has been crossed and the alert is fired, it will not trigger again for that specific movement.
Key Customization Options
- Moving Average Settings: You can adjust the period (how much historical data is averaged), the shift (the horizontal offset), and the calculation method (such as Exponential or Simple) to match your preferred technical analysis style.
- Alert Behavior: You can toggle between the "Proximity" and "Price Target" logic to suit different trading strategies, whether you are looking for price consolidation near an average or significant trend breakthroughs.
//+------------------------------------------------------------------+
//| Alert_MA.mq4 |
//| Kalenzo |
//| bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link "bartlomiej.gorski@gmail.com"
extern int range = 1;
extern int ma_period = 21;
extern int ma_shift = 0;
extern int ma_method = MODE_EMA;
extern int applied_price = PRICE_CLOSE;
extern bool usePriceTargetInsteadOfRange = true;
extern double priceTarget = 1.2001;
double pma = 0;
bool reached = false;
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----bb
double ma = iMA(Symbol(),0,ma_period,ma_shift,ma_method,applied_price,0);
if(!usePriceTargetInsteadOfRange)
{
if( (Bid <= ma+(range*Point)) && (Bid >= ma-(range*Point)))
Alert(Symbol()+" "+ma_period+" Moving Average range reached at ",Bid);
}
else
{
if(!reached && pma!=0 &&((pma < priceTarget && ma >= priceTarget) || (pma > priceTarget && ma <= priceTarget)))
{
Alert(Symbol()+" "+ma_period+" Moving Average price target ",priceTarget);
reached = true;
}
}
pma = ma;
//----
return(0);
}
//+------------------------------------------------------------------+
Comments