MA_of_MA
Download scriptThis script is designed as a specialized technical analysis tool for MetaTrader 4, specifically created to visualize multi-layered moving averages. Rather than simply showing you the price action of an asset, this indicator provides a "smoothed" perspective by calculating averages of averages, which helps in identifying underlying trends with less market noise.
Core Functional Logic
The script operates through a three-step hierarchical calculation process:
1. The Primary Base (The Foundation) The tool begins by calculating a standard moving average based on your preferred settings (such as timeframe, period, and price type). This serves as the raw data source for the rest of the indicator. It captures the immediate momentum of the market.
2. The First Layer of Smoothing (Intermediate Trend) Instead of calculating a second average from the raw price, the script takes the results of the Primary Base and calculates a moving average on top of it. By doing this, the script begins to filter out minor fluctuations, providing a clearer picture of the medium-term trend.
3. The Second Layer of Smoothing (The Macro Trend) The final step applies a third moving average calculation to the results of the first smoothing layer. This "MA of an MA" approach creates a highly refined data stream. It is designed to highlight significant structural shifts in the market, allowing users to see the broader direction while ignoring temporary volatility.
Visual Output and Customization
The script generates three distinct visual lines on a separate window:
- Primary Line: Represents the base moving average.
- Secondary Line: Represents the first smoothed layer.
- Tertiary Line: Represents the final, most smoothed trend.
Users have full control over the "DNA" of these calculations, including the ability to choose different smoothing methods (such as Simple, Exponential, Smooth, or Linear Weighted) and specific price points (like Open, High, Low, or Close prices). This allows for a highly customizable experience tailored to specific trading styles.
//+------------------------------------------------------------------+
//| MA_of_MA.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright "Wolfe"
#property link ""
#property indicator_separate_window
//#property indicator_minimum 0
//#property indicator_maximum 100
//#property indicator_level1 20
//#property indicator_level2 80
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Blue
#property indicator_color3 Red
extern int MA_Timeframe=0;//0=current chart,1=m1,5=m5,15=m15,30=m30,60=h1,240=h4,etc...
extern int MA_Period =3;
extern int MA_Method=1;// 0=SMA, 1=EMA, 2=SMMA, 3=LWMA
extern int MA_Applied_Price=0;//0=close, 1=open, 2=high, 3=low, 4=(high+low)/2, 5=(high+low+close)/3, 6=(high+low+close+close)/4
extern int MA1_of_MA_Period = 7;
extern int MA1_of_MA_Method = 1;// 0=SMA, 1=EMA, 2=SMMA, 3=LWMA
extern int MA2_of_MA_Period = 14;
extern int MA2_of_MA_Method = 1;// 0=SMA, 1=EMA, 2=SMMA, 3=LWMA
double MA1_Array[],MA2_Array[],MA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators setting
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_LINE,STYLE_DASH,1);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
IndicatorShortName("MA_of_MA "+MA_Timeframe);
SetIndexBuffer(0,MA1_Array);
SetIndexLabel(0,"MA1-MA "+MA1_of_MA_Period);
SetIndexBuffer(1,MA2_Array);
SetIndexLabel(1,"MA2-MA "+MA2_of_MA_Period);
SetIndexBuffer(2,MA);
SetIndexLabel(2,"MA "+MA_Period);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit = Bars - IndicatorCounted() - 1;
//---- indicator calculation
for(int i=limit; i>=0; i--)
{
MA[i] = iMA(NULL,MA_Timeframe,MA_Period,0,MA_Method,MA_Applied_Price,i);
}
for(i=limit; i>=0; i--)
{
MA1_Array[i] = iMAOnArray(MA,0,MA1_of_MA_Period,0,MA1_of_MA_Method,i);
MA2_Array[i] = iMAOnArray(MA,0,MA2_of_MA_Period,0,MA2_of_MA_Method,i);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments