AIME_5820_Crossover_AlertNoMAs

Download script
Author: Copyright � 2006, Robert Hill
AIME_5820_Crossover_AlertNoMAs

This script is a specialized trading indicator designed for the MetaTrader platform to help traders identify specific momentum shifts in the market. It functions by monitoring the relationship between two different "Exponential Moving Averages" (EMAs)—which are mathematical tools that smooth out price data to reveal trends—and provides visual and auditory cues when those trends intersect.

Core Logic and Functionality

Trend Monitoring The script continuously calculates three different moving averages on your chart:

  • Fast EMA (5-period): A highly responsive average based on recent closing prices.
  • Slow EMA (8-period): A slightly slower average based on opening prices.
  • Long-term EMA (20-period): A broader average used to help visualize the general market direction.

The Crossover Strategy The primary logic of this tool is to detect "crossovers." Instead of just looking at where the prices are currently, the script compares the current position of the 5-period and 8-period averages against their positions on the previous candle.

  1. Buy Signals (Bullish): When the fast average (5) crosses from below to above the slow average (8), the script identifies a potential upward momentum shift.
  2. Sell Signals (Bearish): When the fast average (5) crosses from above to below the slow average (8), it identifies a potential downward momentum shift.

Visual and Notification Alerts To ensure the trader does not miss these moments, the script performs several actions simultaneously:

  • On-Chart Visuals: When a crossover occurs, the script automatically draws an arrow on the chart. A "Buy" arrow appears below the candle price, and a "Sell" arrow appears above it. The placement of these arrows is dynamically adjusted based on the recent volatility (range) of the market to ensure they remain clearly visible.
  • Real-Time Alerts: The script can be configured to trigger immediate notifications. If enabled, it will produce an audible sound alert and a pop-up window displaying the current price, time, symbol, and timeframe.
  • Email Notifications: For traders who are away from their screens, the script can send an automated email containing all relevant trade details (Buy/Sell status, exact prices, and timestamp) directly to a pre-configured email address.

Smart Filtering The logic includes "flags" to prevent the script from spamming multiple alerts for the same crossover event. It ensures that once a signal is detected on the most recent candle, it only triggers the notification once, providing a cleaner and more reliable trading experience.

Price Data Components
Series array that contains open time of each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt sends emails
13 Views
0 Downloads
0 Favorites
AIME_5820_Crossover_AlertNoMAs
//compile//
//+------------------------------------------------------------------+
//|                                       EMA_58_Crossover_Alert.mq4 |
//|                         Copyright © 2006, Robert Hill            |
//|                                                                  |
//| Written Robert Hill for use with AIME for the EMA 5/8 cross to   |
//| draw arrows and popup alert or send email                        |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2006, Robert Hill"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Red
#property indicator_width1  2
#property indicator_width2  2

extern bool SoundON=true;
extern bool EmailON=false;

double CrossUp[];
double CrossDown[];
double Ema5[];
double Ema8[];
double Ema20[];
int flagval1 = 0;
int flagval2 = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(5);
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
   SetIndexBuffer(2, Ema5);
   SetIndexBuffer(3, Ema8);
   SetIndexBuffer(4, Ema20);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

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


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double tmp=0;
   double fastMAnow, slowMAnow, fastMAprevious, slowMAprevious;
   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 = 1; 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;
       
      fastMAnow = iMA(NULL, 0, 5, -1, MODE_EMA, PRICE_CLOSE, i);
      fastMAprevious = iMA(NULL, 0, 5, -1, MODE_EMA, PRICE_CLOSE, i+1);

      slowMAnow = iMA(NULL, 0, 8, 0, MODE_EMA, PRICE_OPEN, i);
      slowMAprevious = iMA(NULL, 0, 8, 0, MODE_EMA, PRICE_OPEN, i+1);
      
      Ema20[i] = iMA(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, i);
      Ema5[i] = fastMAnow;
      Ema8[i] = slowMAnow;
      CrossUp[i] = 0;
      CrossDown[i] = 0;
      if ((fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious))
      {
         if (i == 1 && flagval1==0)
         {
           flagval1=1;
           flagval2=0;
           if (SoundON) Alert("BUY signal at Ask=",Ask,"\n Bid=",Bid,"\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
           if (EmailON) SendMail("BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
         CrossUp[i] = Low[i] - Range*0.75;
      }
      else if ((fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious))
      {
         if (i == 1 && flagval2==0)
         {
          flagval2=1;
          flagval1=0;
         if (SoundON) Alert("SELL signal at Ask=",Ask,"\n Bid=",Bid,"\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
         if (EmailON) SendMail("SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
         CrossDown[i] = High[i] + Range*0.75;
      }
   }

   return(0);
}

Comments