MACD MA Price-2
Download scriptThis tool is a specialized technical analysis indicator designed to help traders visualize market momentum by identifying the relationship between two different price averages. It provides a clearer look at whether an asset's price is accelerating, slowing down, or reversing direction based on its historical movement.
Core Functionality
The script operates by calculating two distinct types of data points and displaying them in a separate window below your main trading chart:
- The Momentum Histogram: This represents the "gap" between two different moving averages (a fast one and a slow one). By comparing these two averages, the tool shows the current strength of the price trend. If the fast average is significantly higher than the slow average, it suggests bullish momentum; if it is lower, it suggests bearish momentum.
- The Signal Line: This acts as a secondary smoothing layer. It takes the data from the Momentum Histogram and applies another moving average to it. This helps filter out "market noise" and provides a smoother line that traders often use to identify potential turning points or trend changes.
Customization Options
The logic allows for significant flexibility so users can tailor the tool to different trading styles:
- Time Periods: You can adjust the speeds of the calculations (Fast, Slow, and Signal periods). Shorter periods make the indicator more reactive to sudden price changes, while longer periods provide a smoother, more generalized view of the trend.
- Calculation Methods: The script offers four different mathematical models for calculating moving averages (Simple, Exponential, Smoothed, and Linear Weighted). This allows you to choose how much weight to give to recent price action versus older history.
- Price Source: You can choose which specific price data the indicator looks at—such as the standard closing price, the high/low of a candle, or even the median price.
Summary of Operation
In simple terms, this script takes raw market prices, performs a series of mathematical "smoothings" to identify the prevailing trend, and then creates a visual representation of the speed and direction of that trend. By watching how the histogram moves relative to the signal line, traders can better understand the underlying "pulse" of the market.
//+------------------------------------------------------------------+
//| MACD MA Price-2.mq4 |
//| Paladin80 |
//| forevex@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Paladin80"
#property link "forevex@mail.ru"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Silver
#property indicator_color2 Red
#property indicator_width1 2
//---- indicator parameters
extern int Fast_period=12;
extern int Slow_period=26;
extern int Signal_period=9;
//----
extern int MACD_MA_method_1=1;
extern int MACD_MA_method_2=1;
extern int Signal_MA_method=0;
extern int Applied_price=0;
bool error=false;
/* MACD_MA_method_1, MACD_MA_method_2 and Signal_MA_method:
0 - Simple moving average,
1 - Exponential moving average,
2 - Smoothed moving average,
3 - Linear weighted moving average.
Applied_price: 0 - Close price,
1 - Open price,
2 - High price,
3 - Low price,
4 - Median price,
5 - Typical price,
6 - Weighted close price, */
//---- indicator buffers
double MacdBuffer[];
double SignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,Signal_period);
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
SetIndexBuffer(0,MacdBuffer);
SetIndexBuffer(1,SignalBuffer);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+Fast_period+","+Slow_period+","+Signal_period+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
//---- initialization done
if (MACD_MA_method_1<0 || MACD_MA_method_1>3)
{ error=true;
Alert("Please select correct MACD_MA_method_1 (0-3) for indicator MACD MA Price-2");
}
if (MACD_MA_method_2<0 || MACD_MA_method_2>3)
{ error=true;
Alert("Please select correct MACD_MA_method_2 (0-3) for indicator MACD MA Price-2");
}
if (Signal_MA_method<0 || Signal_MA_method>3)
{ error=true;
Alert("Please select correct Signal_MA_method (0-3) for indicator MACD MA Price-2");
}
if (Applied_price<0 || Applied_price>6)
{ error=true;
Alert("Please select correct Applied_price (0-6) for indicator MACD MA Price-2");
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
//----
if (error==true) return(0);
//----
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
MacdBuffer[i]=iMA(NULL,0,Fast_period,0,MACD_MA_method_1,Applied_price,i)-iMA(NULL,0,Slow_period,0,MACD_MA_method_2,Applied_price,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,Signal_period,0,Signal_MA_method,i);
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments