CrossedAlerts_002

Download script
Author: Coders Guru
CrossedAlerts_002

This script is designed to monitor the relationship between two specific moving averages on your trading chart and provide you with real-time notifications whenever they intersect. It acts as a watchful "eyes-on-screen" tool, identifying key shifts in market momentum without requiring you to constantly stare at the price action.

How it Works

The logic follows a straightforward three-step process:

1. Tracking the Moving Averages The script continuously calculates two different types of Exponential Moving Averages (EMAs). These are smooth lines that represent the average price of an asset over a specific period.

  • The first line tracks a 144-period average.
  • The second line tracks a 200-period average.

By looking at two different timeframes simultaneously, the script helps distinguish between short-term trends and long-term market direction.

2. Detecting the "Cross" The core functionality of the script is its ability to recognize exactly when these two lines move past one another. It compares the position of the 144-period line against the 200-period line at every heartbeat of the market:

  • It identifies when the faster line moves from below to above the slower line (often interpreted as a bullish signal).
  • It identifies when the faster line moves from above to below the slower line (often interpreted as a bearish signal).

3. Smart Alerting To ensure you aren't overwhelmed with constant notifications, the script includes "memory." It doesn't just alert you every time it sees one line higher than the other; it specifically looks for the moment of change.

Once a crossover occurs, the script triggers a pop-up alert on your screen and records that specific direction. It will remain silent until the lines cross each other again in the opposite direction. This ensures that you only receive a notification at the exact point of the trend shift, making it a streamlined tool for identifying potential entry or exit points in your trading strategy.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
13 Views
0 Downloads
0 Favorites
CrossedAlerts_002
//+------------------------------------------------------------------+
//|                                                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
//---- 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,144,0,MODE_EMA,PRICE_CLOSE,pos);

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

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


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

Comments