Author: Copyright � 2005, Jason Robinson (jnrtrading)
em12

This tool is designed to simplify and clarify trend analysis by identifying specific moments when two moving averages intersect on a trading chart. In technical trading, "Moving Averages" are used to smooth out price fluctuations to reveal the underlying direction of the market. However, when these lines move very closely together or on fast timeframes, it can sometimes be difficult for a human trader to see exactly where they crossed.

How the Logic Works

The script functions by monitoring two distinct moving averages simultaneously: a Faster average and a Slower average. By comparing these two lines, the tool looks for "crossover" events, which are often interpreted as signals of a change in market momentum.

Here is the step-by-step logic the script follows:

  • Trend Detection: The tool constantly calculates the position of both moving averages across different points in time (the current bar, the previous bar, and the bar ahead).
  • Identifying an "Upward" Cross: The script looks for a specific sequence where the Faster average was previously below the Slower average but has now moved above it. When this specific transition occurs, the tool marks the spot to signal a potential upward shift in momentum.
  • Identifying a "Downward" Cross: Conversely, the tool looks for moments where the Faster average was previously above the Slower average but has dropped below it. It marks these spots to signal a potential downward shift in momentum.
  • Visual Precision: To ensure the signals are easy to see, the script calculates the average height (range) of the nearby price bars. Instead of placing a marker directly on the line—where it might get buried by the "candles" or price action—it places a visual arrow slightly above or below the price action based on that calculated range.

Key Benefits for the User

  • Clarity in Crowded Charts: Because it uses specific markers (arrows) rather than just drawing lines, it allows you to see exactly where a crossover happened even if you have zoomed out or are looking at very fast-moving price data.
  • Customizable Sensitivity: You can adjust the periods for both the "Faster" and "Slower" averages to suit your specific trading style, whether you prefer identifying quick, short-term shifts or broader, long-term trend changes.
  • Clean Workspace: This tool is designed to provide the "signal" without cluttering your view. It allows you to identify the necessary crossover points and then remove the moving average lines entirely if you prefer a cleaner chart layout.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
em12
//+------------------------------------------------------------------+
//|                                         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 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