mc_v2
Download scriptThis script is a specialized technical analysis tool designed to help traders visualize momentum and trend shifts in the financial markets. It functions by comparing two different types of moving averages—mathematical "smoothings" of price data—to identify whether an asset's price is accelerating or decelerating.
Core Logic and Functionality
The script operates by performing three primary mathematical steps to generate a visual representation on your chart:
1. Establishing the Base Trends The tool first tracks two different trend lines simultaneously:
- A Fast Trend: This reacts quickly to recent price changes.
- A Slow Trend: This follows the broader, long-term price movement.
2. Calculating the Difference (The MACD Line) By subtracting the Slow Trend from the Fast Trend, the script identifies the "gap" between short-term and long-term momentum.
- When this gap widens significantly, it indicates that the price is moving strongly in one direction.
- When the gap narrows or crosses zero, it suggests the current trend may be losing steam or reversing. This calculation produces the primary line (displayed in blue) on your indicator window.
3. Smoothing the Signal (The Signal Line) To filter out minor market "noise" and prevent traders from reacting to every tiny fluctuation, the script performs a secondary calculation. It takes the resulting data from the first step and applies another layer of smoothing to it. This creates a second, steadier line (displayed in red).
How to Interpret the Results
The primary purpose of this logic is to help you identify "crossover" moments:
- Trend Strength: The distance between the two lines indicates how powerful the current momentum is.
- Potential Reversals: When the Fast Trend line (blue) crosses over the Signal line (red), it serves as a visual cue that the market's momentum may be shifting from bearish to bullish, or vice versa.
- Visual Clarity: By placing this data in a separate window below your main price chart, it allows you to monitor the "health" of a trend independently of the actual price action.
//+------------------------------------------------------------------+
//| mc.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
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;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
ind_buffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA,i);
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments