MacD-2 line_v1
Download scriptThis tool is designed as a visual momentum indicator for trading platforms, specifically intended to help traders identify the strength of market trends and potential turning points by analyzing price fluctuations.
Core Logic Overview
The script operates by calculating the relationship between two different types of moving averages. In simple terms, it measures how fast a price is moving relative to its historical average. By comparing a "fast" moving average (which reacts quickly to recent price changes) against a "slow" moving average (which represents the longer-term trend), the script identifies whether the current market momentum is accelerating or slowing down.
How the Data is Processed
The logic follows a two-step calculation process:
1. The Main Momentum Line The primary output of this tool is calculated by subtracting the slow moving average from the fast moving average.
- When the result is positive, it indicates that short-term price action is pulling ahead of the long-term trend (often interpreted as upward momentum).
- When the result is negative, it suggests that short-term prices are falling behind the long-term trend (often interpreted as downward momentum).
2. The Signal Line To make the data easier to read and to filter out "noise," the script takes the results from the Main Momentum Line and applies a secondary smoothing calculation. This creates a "Signal Line." Rather than looking at every tiny fluctuation, this line provides a smoother path that helps traders identify when the momentum is reaching an extreme or beginning to shift direction.
Visual Representation
On your trading chart, these calculations are displayed in a separate window below the price action:
- The MACD Line: Represents the immediate difference between the two main averages.
- The Signal Line: Acts as a baseline for the MACD line.
Traders typically look for crossovers between these two lines or shifts in their relative positions to gauge whether the market is gaining strength or losing steam, providing a clearer picture of market dynamics than looking at price alone.
/*-----------------------------+
| |
| 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 Aqua
#property indicator_color2 Red
//---- indicator parameters
extern int FastEMA=8;
extern int SlowEMA=12;
extern int SignalSMA=9;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
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