EMA Cross Arrow

EMA Cross Arrow

This script is designed to enhance your trading visual experience by identifying specific trend-reversal moments—known as "crossovers"—between two different Exponential Moving Averages (EMAs).

The Core Purpose

In many trading environments, it can be difficult to see exactly where one moving average line crosses another because the price candles or high zoom levels can obscure the precise point of intersection. This tool solves that problem by placing clear visual markers directly on your chart at the exact moment these two lines cross, allowing for cleaner analysis even when you choose to hide the actual moving average lines from your view.

How the Logic Works

The script works by continuously monitoring two distinct settings: a Faster EMA and a Slower EMA. By comparing the relationship between these two lines across recent price history, the logic identifies two specific scenarios:

  • Bullish Signals (Cross Up): The script looks for a moment where the Faster EMA moves from being below the Slower EMA to above it. When this "breakout" is detected, the script places a marker at the bottom of the price candle to signal an upward momentum shift.
  • Bearish Signals (Cross Down): Conversely, the script monitors for when the Faster EMA drops from above the Slower EMA to below it. When this occurs, it places a marker at the top of the price candle to signal a downward momentum shift.

Smart Positioning

To ensure these markers don't clutter your view or overlap with the price action, the script calculates a "Range" based on the recent volatility of the market (the difference between the highs and lows of the last 10 candles). It then uses this calculation to offset the signals:

  • Upward signals are placed slightly below the candle.
  • Downward signals are placed slightly above the candle.

By using this method, the tool provides a clear, organized history of trend shifts that remains visible and easy to read regardless of your chart's zoom level or the thickness of your price bars.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
18 Views
0 Downloads
0 Favorites
EMA Cross Arrow
//+------------------------------------------------------------------+
//|                                         EMA-Crossover_Signal.mq4 |
//|                         |
//+------------------------------------------------------------------+

/*
  +------------------------------------------------------------------+
  | 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.              
  +------------------------------------------------------------------+
*/   



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

double CrossUp[];
double CrossDown[];
extern int FasterEMA = 12;
extern int SlowerEMA = 89;
//+------------------------------------------------------------------+
//| 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 fasterEMAnow, slowerEMAnow, fasterEMAprevious, slowerEMAprevious, fasterEMAafter, slowerEMAafter;
   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;
       
      fasterEMAnow = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      fasterEMAprevious = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i+1);
      fasterEMAafter = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);

      slowerEMAnow = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      slowerEMAprevious = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i+1);
      slowerEMAafter = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);
      
      if ((fasterEMAnow > slowerEMAnow) && (fasterEMAprevious < slowerEMAprevious) && (fasterEMAafter > slowerEMAafter)) {
         CrossUp[i] = Low[i] - Range*0.5;
      }
      else if ((fasterEMAnow < slowerEMAnow) && (fasterEMAprevious > slowerEMAprevious) && (fasterEMAafter < slowerEMAafter)) {
         CrossDown[i] = High[i] + Range*0.5;
      }
   }
   return(0);
}

Comments