MA_ALERT_v3
Download scriptThis script is a specialized trading tool designed to monitor price trends by tracking the movement of a Moving Average (MA) on your trading chart. Its primary goal is to provide real-time notifications whenever the momentum of the market shows a significant change in direction.
Core Functionality
The script calculates a Moving Average line based on parameters you can customize, such as the period (how much historical data to look at), the smoothing method, and the specific price type to track. This line serves as a visual representation of the market's "average" trend over time.
How the Logic Works
The tool works by constantly analyzing the relationship between three consecutive data points on the Moving Average line:
- Trend Upward (Increasing): The script looks for a specific pattern where the average value rises and then begins to curve back, or vice versa. Specifically, if it detects that the market momentum is shifting upward in a way that suggests an increasing trend, it triggers a "MA increasing" alert.
- Trend Downward (Decreasing): Conversely, if the script identifies a sequence where the average values are dipping, indicating a downward shift in momentum, it triggers a "MA decreasing" alert.
Smart Notification Management
To ensure the tool is helpful rather than intrusive, it includes built-in logic to manage how often you receive notifications:
- Time Filtering: The script is designed to prevent "alert spam." It tracks the time of the last notification and will only send a new one if a full new candle (time period) has passed. This means you won't receive multiple alerts for the same price movement within a single timeframe.
- Real-Time Monitoring: The script runs automatically in the background, constantly comparing the current market data against the historical averages to ensure you are notified as soon as the mathematical conditions for a trend change are met.
Summary for the User
In simple terms, this tool acts like an automated scout. It watches the "flow" of the market prices and sends you an immediate notification whenever the Moving Average shows a distinct peak or valley in its movement, helping you identify potential shifts in market direction without having to stare at the screen constantly.
//+------------------------------------------------------------------+
//| 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 Red
#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