CrossedAlerts

Author: Coders Guru
CrossedAlerts

This tool is designed to act as an automated visual and audio assistant for traders who use moving averages to identify trends in the financial markets. Its primary purpose is to detect specific moments when two different trend lines intersect, providing real-time notifications of potential shifts in market momentum.

Core Methodology

The script works by tracking two distinct types of Exponential Moving Averages (EMA) simultaneously:

  • The Fast Moving Average: This line reacts quickly to recent price changes.
  • The Slow Moving Average: This line provides a broader view of the overall trend, smoothing out minor market "noise."

By comparing these two lines, the tool helps traders see whether the short-term price movement is pulling ahead of or falling behind the long-term average.

How the Logic Works

The system continuously monitors the relationship between these two lines on your chart. It specifically looks for a "crossover" event:

  1. Trend Identification: The logic constantly checks if the Fast line is currently above or below the Slow line.
  2. Change Detection: Rather than alerting you every time the prices move, the script is programmed to recognize a change in state. It remembers the previous position of the lines; it only triggers an action when the lines switch from one side to the other (e.g., the Fast line moves from being below the Slow line to above it).
  3. Alert Trigger: The moment this crossover occurs, the script sends a pop-up alert on your screen. This notification informs you that a crossover has happened on the specific currency pair and timeframe you are currently viewing.

User Experience

For the trader, this means you do not have to watch the charts constantly to catch the exact second a trend shifts. The tool automates the "watching" process, filtering out the constant fluctuations of the market and only notifying you when the technical relationship between the two moving averages indicates a significant shift in direction.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
12 Views
0 Downloads
0 Favorites
CrossedAlerts
//+------------------------------------------------------------------+
//|                                                CrossedAlerts.mq4 |
//|                                                      Coders Guru |
//|                                         http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Coders Guru"
#property link      "http://www.forex-tsd.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
extern int FasterMA = 2;
extern int SlowerMA = 50;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }

bool Crossed (double line1 , double line2 )
{

static string last_direction = "";
string current_dirction = "";

if(line1>line2)current_dirction = "up";
if(line1<=line2)current_dirction = "down";



if(current_dirction != last_direction) 
{
      Alert("EMA Cross for "+Symbol()+" on the "+Period()+" minute chart.");
      last_direction = current_dirction;
      return (true);
}
else
{
      return (false);

}
 
} 
int start()
  {
   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--;
   
   int pos=Bars-counted_bars;
   
     
 
   while(pos>=0)
     {
         ExtMapBuffer1[pos]= iMA(NULL,0,FasterMA,0,MODE_EMA,PRICE_CLOSE,pos);

         ExtMapBuffer2[pos]= iMA(NULL,0,SlowerMA,0,MODE_EMA,PRICE_CLOSE,pos);

         
         pos--;
     }
     
     
     
     Print(Crossed (ExtMapBuffer1[0],ExtMapBuffer2[0]));


//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments