MA_ALERT_v1
Download scriptThis script is designed as a specialized technical analysis tool for the MetaTrader 4 platform. Its primary purpose is to monitor price trends automatically and provide real-time notifications (alerts) when specific shifts in momentum occur.
Core Functionality
The tool operates by calculating a Moving Average (MA), which is a common mathematical way to smooth out price fluctuations to identify the underlying direction of a market trend. Users can customize various aspects of this average, including its sensitivity (period), the calculation method, and the specific price data it should follow.
How the Logic Works
The script continuously scans recent price history to determine the behavior of the Moving Average. It specifically looks at the relationship between the current value and the values from the previous two candles.
The logic triggers an alert based on two primary scenarios:
- Increasing Trend Detection: The script identifies a "V-shaped" upward movement. It checks if the moving average was lower than the previous point but has now swung higher than the point immediately following it. When this specific change in direction is detected, the system issues an alert stating that the Moving Average is increasing.
- Decreasing Trend Detection: Conversely, the script looks for a "V-shaped" downward movement. It monitors if the moving average was higher than the previous point but has dropped lower than the point immediately following it. When this occurs, the system alerts the user that the Moving Average is decreasing.
Smart Notification Management
To ensure the tool remains practical for the user, it includes a built-in "cooldown" mechanism. Rather than sending an overwhelming number of notifications for every tiny price tick, the script tracks the time of the last alert. It is programmed to only send one notification per candle timeframe, ensuring that you receive clear, actionable information without being disturbed by repetitive signals during a single period of market activity.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| MA_ALERT.mq4 |
//| Kalenzo |
//| simone@konto.pl |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link "simone@konto.pl"
extern bool makeItPlay = true;
extern int maMethod = 0;
extern int maPeriod = 14;
extern int maShift = 0;
extern int appiledPrice = 0;
int PrevAlertTime = 0;
#property indicator_chart_window
#property indicator_color1 Gold
#property indicator_buffers 1
double maBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,0,1);
SetIndexBuffer(0,maBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) counted_bars=0;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
for(int i = 0 ;i < limit ;i++)
{
maBuffer[i]=iMA(Symbol(),0,maPeriod,maShift,maMethod,appiledPrice,i);
}
double ppMA = NormalizeDouble(iMA(Symbol(),0,maPeriod,maShift,maMethod,appiledPrice,3),4);
double pMA = NormalizeDouble(iMA(Symbol(),0,maPeriod,maShift,maMethod,appiledPrice,2),4);
double cMA = NormalizeDouble(iMA(Symbol(),0,maPeriod,maShift,maMethod,appiledPrice,1),4);
if (CurTime() - PrevAlertTime > Period()*60)
{
if(ppMA < pMA && pMA > cMA)
{
Alert("MA incerasing");
PrevAlertTime = CurTime();
}
else if(ppMA > pMA && pMA < cMA)
{
Alert("MA decerasing");
PrevAlertTime = CurTime();
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments