CrossedAlerts1

Download script
Author: Coders Guru
CrossedAlerts1

This tool is designed to monitor price movements on your trading charts by identifying specific moments when two different moving averages intersect. Its primary purpose is to provide a clear, audible signal whenever the momentum of the market shifts from one direction to another.

How the Logic Works

1. Data Tracking The script constantly calculates two distinct "Moving Averages" based on current market prices. These serve as smoothed indicators of price trends:

  • A Fast Average (calculated over a shorter period) reacts quickly to recent price changes.
  • A Slow Average (calculated over a longer period) represents the broader, long-term trend.

2. Identifying "Crosses" The core logic revolves around the relationship between these two lines. The script looks for a "crossover" event:

  • If the Fast Average moves from below the Slow Average to above it, it suggests an upward shift in momentum.
  • If the Fast Average moves from above the Slow Average to below it, it suggests a downward shift in momentum.

3. Smart Alerting System To ensure the tool is useful for active trading, it features a "memory" system. Instead of notifying you every single time the price fluctuates slightly while the lines are already crossed, the script only triggers an alert at the exact moment the crossover occurs. It remembers the previous state of the market; once a cross is detected and the sound is played, it will not trigger again until the opposite cross happens.

4. User Notifications When a crossover is confirmed by the logic, the tool performs two actions:

  • Audio Alert: It plays a specific sound file (by default, an alert sound) to grab your attention immediately.
  • Log Entry: It records the event in the platform's internal log, providing a history of when these crossovers occurred.

In essence, this tool acts as a secondary set of "eyes," filtering out minor market noise and notifying you only when the underlying trend shows a significant enough change to warrant your attention.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It plays sound alerts
12 Views
0 Downloads
0 Favorites
CrossedAlerts1
//+------------------------------------------------------------------+
//|                                                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 Red
#property indicator_color2 Blue
extern bool UseSound = True;
extern string NameFileSound = "alert.wav";

//---- 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) 
{
      
     if (UseSound==1) PlaySound(NameFileSound);
      
      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,5,0,MODE_EMA,PRICE_CLOSE,pos);

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

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


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

Comments