Author: Kalenzo
MA_ALERT

This tool is designed to monitor price trends on a trading chart by tracking the movement of a Moving Average (MA)—a common technical indicator used to smooth out price action and identify the general direction of the market.

Core Functionality

The script works by calculating a Moving Average based on specific parameters that you can customize, such as the length of the period, the shift, and the method of calculation. It visualizes this trend as a line on your chart, allowing you to see the current momentum at a glance.

Automated Alert Logic

Beyond simply drawing the line, the script is programmed to "watch" the direction of the Moving Average in real-time. It specifically looks for changes in the curve's direction by comparing three consecutive data points:

  • Trend Reversals: The system detects when the Moving Average changes its trajectory from moving downward to moving upward (or vice versa).
  • Instant Notifications: When the script identifies these specific "peaks" or "valleys" in the Moving Average's path, it triggers an automated alert notification. This is intended to inform you of a potential shift in market momentum immediately.

Smart Notification Management

To ensure that you are not overwhelmed with constant notifications, the logic includes a built-in cooling period. The script is designed to only send one alert per candle (time period). This means that even if the Moving Average continues to fluctuate rapidly within a single timeframe, you will only receive one notification until the next candle begins, providing a cleaner and more manageable flow of information.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
11 Views
0 Downloads
0 Favorites
MA_ALERT
//+------------------------------------------------------------------+
//|                                                     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