MA_Crossover_Signal_With_wav

Download script
Author: Copyright � 2005, Jason Robinson (jnrtrading)
MA_Crossover_Signal_With_wav

This tool is designed to simplify and clarify visual trading data by identifying specific "crossover" moments between two Moving Averages (MAs) on a price chart. While many traders use Moving Averages to gauge trends, these lines can sometimes become visually cluttered or difficult to read when zoomed out or when looking at very short timeframes where candles overlap significantly. This script solves that problem by highlighting the exact point of intersection with clear visual signals.

How the Logic Works

The script monitors two different moving averages simultaneously: a "Faster" average and a "Slower" average. It calculates these based on user-defined settings (such as Simple, Exponential, or Smoothed Moving Averages) and specific time periods.

The core logic follows a three-step verification process to identify a crossover:

  1. Current State: The script checks the current position of both averages.
  2. Previous State: It looks back at the previous price bar to see where the averages were located before the current movement.
  3. Confirmation: It verifies that a "flip" has occurred—where the faster line was previously below the slower line and has now moved above it (a Bullish/Buy signal), or vice versa (a Bearish/Sell signal).

Visual and Audio Notifications

To ensure these signals are easy to spot, the script performs three specific actions when a crossover is detected:

  • On-Chart Markers: It places distinct visual arrows on the chart. A "Buy" signal is marked below the candle's low, while a "Sell" signal is marked above the candle's high. The distance of these markers is dynamically calculated based on the average volatility (the range between highs and lows) to ensure they remain clearly visible regardless of the asset being traded.
  • Audible Alerts: The script triggers a sound notification immediately upon detecting a crossover.
  • Pop-up Alerts: A text alert will appear on your trading platform, specifying the current currency pair and timeframe where the move occurred.

Key Benefits for the User

  • Clarity: By providing distinct arrows, you no longer have to squint at overlapping lines to determine if a crossover has actually happened.
  • Efficiency: The script filters out "noise" by ensuring that only confirmed crossovers trigger an alert, preventing unnecessary signals from minor price fluctuations.
  • Customization: You can adjust the speeds and types of both moving averages to suit your specific trading strategy, whether you prefer fast-paced scalping signals or slower, more stable trend indicators.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It plays sound alertsIt issuies visual alerts to the screen
12 Views
0 Downloads
0 Favorites
MA_Crossover_Signal_With_wav
//+------------------------------------------------------------------+
//|                                         EMA-Crossover_Signal.mq4 |
//|         Copyright © 2005, Jason Robinson (jnrtrading)            |
//|                   http://www.jnrtading.co.uk                     |
//+------------------------------------------------------------------+

/*
  +------------------------------------------------------------------+
  | Allows you to enter two ema periods and it will then show you at |
  | Which point they crossed over. It is more usful on the shorter   |
  | periods that get obscured by the bars / candlesticks and when    |
  | the zoom level is out. Also allows you then to remove the emas   |
  | from the chart. (emas are initially set at 5 and 6)              |
  +------------------------------------------------------------------+
*/   
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)"
#property link      "http://www.jnrtrading.co.uk"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red

double CrossUp[];
double CrossDown[];
extern int FasterMode = 1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int FasterMA =   5;
extern int SlowerMode = 0; //0=sma, 1=ema, 2=smma, 3=lwma
extern int SlowerMA =   9;
 double alertTag;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, 
fasterMAafter, slowerMAafter;
   double Range, AvgRange;
   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--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
       
      fasterMAnow = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, 
i);
      fasterMAprevious = iMA(NULL, 0, FasterMA, 0, FasterMode, 
PRICE_CLOSE, i+1);
      fasterMAafter = iMA(NULL, 0, FasterMA, 0, FasterMode, 
PRICE_CLOSE, i-1);

      slowerMAnow = iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, 
i);
      slowerMAprevious = iMA(NULL, 0, SlowerMA, 0, SlowerMode, 
PRICE_CLOSE, i+1);
      slowerMAafter = iMA(NULL, 0, SlowerMA, 0, SlowerMode, 
PRICE_CLOSE, i-1);
      
      if ( (fasterMAnow > slowerMAnow) && (fasterMAprevious < 
slowerMAprevious) && (fasterMAafter > slowerMAafter)) {
         CrossUp[i] = Low[i] - Range*0.5;
         if ( alertTag!=Time[0])
         {
          PlaySound("news.wav");// buy wav
          Alert(Symbol(),"  M",Period()," MA cross BUY");
         }
          alertTag = Time[0];
      }
      else if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > 
slowerMAprevious) && (fasterMAafter < slowerMAafter)) {
         CrossDown[i] = High[i] + Range*0.5;
         if ( alertTag!=Time[0])
         {
          PlaySound("news.wav"); //sell wav
           Alert(Symbol(),"  M",Period()," MA cross SELL");
         }
          alertTag = Time[0];
      }
   }
   return(0);
}


       

Comments