maEMA_Trend_Indicator

Download script
Author: Copyright � 2005, Metaquotes
maEMA_Trend_Indicator

This tool is designed to help traders visualize and identify market trends by analyzing price movement patterns. It achieves this by calculating several moving averages simultaneously, focusing on two distinct layers of market data: the high and low price points.

Core Methodology

The indicator operates on the principle of "Exponential Moving Averages" (EMA). Unlike simple averages that weight all past prices equally, these averages give more importance to recent price action, allowing the tool to react more quickly to new market developments while still filtering out minor "noise."

How the Logic Works

To provide a comprehensive view of the trend, the script tracks four different data streams:

  • The Fast Layer: This represents shorter-term momentum. It monitors the highs and lows over a quick period (defaulting to 21 bars). Because it reacts faster, it highlights immediate shifts in price direction.
  • The Slow Layer: This represents the broader market sentiment. It monitors the highs and lows over a longer period (defaulting to 34 bars). This acts as a "baseline" to show the overall primary trend of the asset.

Visualizing the Trend

By calculating these averages specifically for the highest and lowest prices—rather than just the middle closing price—the indicator creates a visual "channel" or "envelope."

  1. Dynamic Range: The gap between the high and low averages shows the volatility of the market at any given moment.
  2. Trend Direction: By comparing the interaction between the Fast Layer (short-term) and the Slow Layer (long-term), traders can see if the immediate price action is aligning with the broader market direction or if a potential reversal is beginning to form.

In essence, this script translates complex raw price data into a structured visual map, helping users distinguish between temporary price fluctuations and sustained directional movements.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
maEMA_Trend_Indicator
//+------------------------------------------------------------------+
//|                                          EMA_Trend_Indicator.mq4 |
//|                                Copyright © 2006, Robert L Hill   |
//+------------------------------------------------------------------+
// Uses an idea from david to use EMAs to determine trend
#property copyright "Copyright © 2005, Metaquotes"
#property link      "mailto:metaquotes@metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 DodgerBlue
#property indicator_color4 Magenta
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
//---- input parameters
extern int FastMAPeriod=21;
extern int SlowMAPeriod=34;
//---- buffers
double fastEMA_HighBuffer[];
double fastEMA_LowBuffer[];
double slowEMA_HighBuffer[];
double slowEMA_LowBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 1);
   //---- indicators
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, slowEMA_HighBuffer);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, slowEMA_LowBuffer);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, fastEMA_HighBuffer);
   SetIndexStyle(3, DRAW_LINE);
   SetIndexBuffer(3, fastEMA_LowBuffer);
   SetIndexDrawBegin(0, SlowMAPeriod);
   //---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MA Trend ");
   //----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   //----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   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(int i = limit; i >= 0; i--)
     {
       fastEMA_HighBuffer[i] = iMA(NULL, 0, FastMAPeriod, 0, MODE_EMA, PRICE_HIGH, i);
       fastEMA_LowBuffer[i] = iMA(NULL, 0, FastMAPeriod, 0, MODE_EMA, PRICE_LOW, i);
       slowEMA_HighBuffer[i] = iMA(NULL, 0, SlowMAPeriod, 0, MODE_EMA, PRICE_HIGH, i);
       slowEMA_LowBuffer[i] = iMA(NULL, 0, SlowMAPeriod, 0, MODE_EMA, PRICE_LOW, i);
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments