mc_v1
Download scriptThis tool is a technical analysis indicator designed to help traders visualize the momentum and trend direction of a financial asset. It operates by calculating the relationship between two different types of moving averages to identify whether the price is accelerating or slowing down.
How the Logic Works
1. Establishing the Baseline (The MACD Line) The core of the script works by comparing two distinct "moving averages" based on the closing prices of the market:
- Fast Average: This tracks recent price movements quickly.
- Slow Average: This tracks the longer-term price trends more broadly.
By subtracting the Slow Average from the Fast Average, the script produces a primary line (the MACD). When this line is above zero, it suggests that the short-term momentum is stronger than the long-term trend; when it drops below zero, it indicates that the short-term price action is weakening compared to the broader trend.
2. Creating a Smoothing Filter (The Signal Line) To make the data easier to read and to reduce "market noise," the script takes the primary MACD line mentioned above and applies a second calculation to it. It calculates a simple average of the MACD values over a set period. This creates a secondary, smoother line known as the "Signal" line.
3. Interpreting the Results The visual output provides two lines on your chart:
- The Main Line: Shows the raw difference in momentum between short-term and long-term price trends.
- The Signal Line: Acts as a stabilizer, helping traders see the overall direction of that momentum.
Traders typically look for the interaction between these two lines—such as when the main line crosses above or below the signal line—to identify potential entry or exit points in the market.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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