MultiEMA
Download scriptThis tool is designed to help traders visualize price trends by layering three different Exponential Moving Averages (EMAs) on a single chart. Unlike standard indicators that calculate averages independently, this script uses a "nested" or "sequential" logic, where each subsequent line is derived from the previous one, creating a smoothed, multi-layered trend analysis.
How the Logic Works
The script processes data in three distinct stages to build its visual output:
1. The Primary Foundation (Short-Term) The first layer captures immediate price action. It looks at the most recent market prices (based on a user-defined setting, such as the midpoint between the high and low of each candle) and calculates a fast moving average. This represents the "momentum" of the current market.
2. The Secondary Smoothing (Medium-Term) Instead of calculating a second average based on the raw price, the script takes the results of the first moving average and applies a second moving average calculation to it. By doing this, the tool filters out some of the "noise" or minor fluctuations found in the first line, providing a clearer view of the intermediate trend.
3. The Tertiary Smoothing (Long-Term) The final layer follows the same logic: it takes the results of the second moving average and applies a third calculation to them. This creates a significantly smoothed, long-term trend line. Because each step is based on the previous calculation rather than the raw price, the resulting lines are much more stable and less reactive to sudden, temporary market spikes.
Key Benefits for Traders
- Noise Reduction: By nesting the averages (Average of an Average), the script creates a "smoother" visual experience than three independent moving averages would provide.
- Trend Identification: The distance and direction between these three lines help traders identify whether the market is trending strongly, weakening, or entering a period of consolidation.
- Customizable Sensitivity: Users can adjust the specific lengths of these three stages to suit different trading styles, whether they are looking for rapid scalping signals or long-term investment directions.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| Multi EMAs.mq4 |
//| Copyright © 2006, Ronald Verwer/ROVERCOM |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Ronald Verwer/ROVERCOM"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Blue
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
//---- indicator parameters
extern int FirstEMA=5;
extern int SecondEMA=13;
extern int ThirdEMA=62;
extern int Price_Type=4;
//---- indicator buffers
double x1[];
double x2[];
double x3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexDrawBegin(0,ThirdEMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
if(!SetIndexBuffer(0,x1) &&
!SetIndexBuffer(1,x2) &&
!SetIndexBuffer(2,x3))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MultiEMA("+FirstEMA+","+SecondEMA+","+ThirdEMA+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Multi Exponential Moving Averages |
//+------------------------------------------------------------------+
int start()
{
int i,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;
//---- macd counted in the 1-st additional buffer
for(i=limit; i>=0; i--)
x1[i]=iMA(NULL,0,FirstEMA,0,MODE_EMA,Price_Type,i);//(High[i]+Low[i])/2,i);
for(i=limit; i>=0; i--)
x2[i] = iMAOnArray(x1,Bars,SecondEMA,0,MODE_EMA,i);
for(i=limit; i>=0; i--)
x3[i] = iMAOnArray(x2,Bars,ThirdEMA,0,MODE_EMA,i);
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments