SMA Cross Over ArrowAlert

Download script
SMA Cross Over ArrowAlert

This script is a specialized trading tool designed to identify specific momentum shifts in the market by tracking the interaction between two Simple Moving Averages (SMAs). In plain terms, it acts as an automated "scout" that watches for the exact moment one moving average crosses over another.

Core Functionality

The primary purpose of this tool is to provide clear visual and audible signals when a "Fast" moving average crosses a "Slow" moving average. This crossover technique is often used by traders to identify changes in trend direction—for example, when a fast-moving price average breaks above a slower one, it may indicate upward momentum (a buy signal), while breaking below may suggest downward momentum (a sell signal).

Key Features

  • Visual Markers: Rather than making you squint at overlapping lines on a crowded chart, the script places distinct arrows directly on the price candles. This makes it much easier to identify entry points, especially when the chart is zoomed out or cluttered with other data.
  • Dynamic Positioning: To ensure the markers are easy to see, the script calculates the average height of recent price candles (the "range"). It then places the "Buy" arrows slightly below the candle and the "Sell" arrows slightly above it, preventing them from overlapping with the actual price bars.
  • Customizable Periods: You can define exactly how many bars of data should be used to calculate your Fast and Slow averages, allowing you to tailor the sensitivity of the signals to different trading styles (e.g., day trading vs. long-term investing).

Automated Notifications

The script does more than just draw on the screen; it acts as an active monitoring system. When a crossover is detected in real-time, the tool can trigger multiple types of alerts simultaneously:

  1. Audio Alerts: It plays specific sound files to grab your attention immediately.
  2. Pop-up Alerts: It generates a visual notification window on your trading platform.
  3. Email Notifications: It can send an automated email directly to your inbox, providing the exact time and symbol where the crossover occurred.

Summary of Logic

The script constantly scans every new price tick, comparing the current, previous, and subsequent positions of two moving averages. By checking if the relationship between these averages has "flipped" from one bar to the next, it confirms a definitive crossover. Once confirmed, it executes the visual markers and triggers your preferred notification system, ensuring you never miss a potential trend shift.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It plays sound alertsIt sends emails
15 Views
0 Downloads
0 Favorites
SMA Cross Over ArrowAlert
//+------------------------------------------------------------------+
//|                                         SMA-Crossover_Signal.mq4 |
//|                         |
//+------------------------------------------------------------------+

/*
  +------------------------------------------------------------------+
  | Allows you to enter two sma 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 smas   |
  | from the chart.              
  +------------------------------------------------------------------+
*/   



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

double CrossUp[];
double CrossDown[];
extern int FasterSMA = 14;
extern int SlowerSMA = 34;
extern int SoundAlert  =    1; // 0 = disabled
extern int PopUpAlert = 1;
extern string BuySoundFile = "alert.wav";
extern string SellSoundFile = "alert2.wav";
extern int EmailAlert  =    1;
double prevtime;
//+------------------------------------------------------------------+
//| 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 fasterSMAnow, slowerSMAnow, fasterSMAprevious, slowerSMAprevious, fasterSMAafter, slowerSMAafter;
   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;
       
      fasterSMAnow = iMA(NULL, 0, FasterSMA, 0, MODE_SMA, PRICE_CLOSE, i);
      fasterSMAprevious = iMA(NULL, 0, FasterSMA, 0, MODE_SMA, PRICE_CLOSE, i+1);
      fasterSMAafter = iMA(NULL, 0, FasterSMA, 0, MODE_SMA, PRICE_CLOSE, i-1);

      slowerSMAnow = iMA(NULL, 0, SlowerSMA, 0, MODE_SMA, PRICE_OPEN, i);
      slowerSMAprevious = iMA(NULL, 0, SlowerSMA, 0, MODE_SMA, PRICE_OPEN, i+1);
      slowerSMAafter = iMA(NULL, 0, SlowerSMA, 0, MODE_SMA, PRICE_OPEN, i-1);
      if ((fasterSMAnow > slowerSMAnow) && (fasterSMAprevious < slowerSMAprevious) && (fasterSMAafter > slowerSMAafter)) {
         CrossUp[i] = Low[i] - Range*0.5;
      }
      else if ((fasterSMAnow < slowerSMAnow) && (fasterSMAprevious > slowerSMAprevious) && (fasterSMAafter < slowerSMAafter)) {
         CrossDown[i] = High[i] + Range*0.5;
      }
   }
      if ((CrossUp[0] > 2000) && (CrossDown[0] > 2000)) { prevtime = 0; }
      
      if ((CrossUp[0] == Low[0] - Range*0.5) && (prevtime != Time[0]))
       {
         prevtime = Time[0];
         if (SoundAlert != 0)PlaySound(BuySoundFile);
         if (EmailAlert != 0) SendMail("BUY Alert for " + Symbol(), " 3 MA Cross Up @  Hour " + Hour() + "  Minute " + Minute());
         if (PopUpAlert != 0)Alert(Symbol()," 3 MA Cross Up @  Hour ",Hour(),"  Minute ",Minute());
       }
      
      if ((CrossDown[0] == High[0] + Range*0.5) && (prevtime != Time[0]))
       {
         prevtime = Time[0];
         if (SoundAlert != 0)PlaySound(SellSoundFile);
         if (EmailAlert != 0) SendMail("SELL Alert for " + Symbol(), " 3 MA Cross Down @  Hour " + Hour() + "  Minute " + Minute());
         if (PopUpAlert != 0)Alert(Symbol()," 3 MA Cross Down @  Hour ",Hour(),"  Minute ",Minute());
       }
   return(0);
}

Comments