MACD (DEMA) DiNapoli_v1 lines
Download scriptThis tool is designed to analyze market trends by calculating the momentum of price movements. It functions by comparing two different moving averages to determine if the market is speeding up, slowing down, or reversing direction.
Core Components
The logic operates through three primary layers of calculation:
1. Advanced Smoothing (DEMA) Instead of using standard moving averages—which can sometimes be too slow to react to sudden price changes—this script utilizes a specialized smoothing technique known as DEMA (Double Exponential Moving Average). This approach is designed to reduce the "lag" typically found in traditional indicators, allowing the tool to react more quickly to current market conditions while still filtering out unnecessary noise.
2. The MACD Calculation The script tracks two distinct data points: a "Fast" average and a "Slow" average.
- The Fast Average reacts quickly to recent price fluctuations.
- The Slow Average provides a broader view of the long-term trend.
By subtracting the Slow Average from the Fast Average, the script produces the main MACD line. When this value is positive and rising, it suggests upward momentum; when it is negative and falling, it suggests downward pressure.
3. The Signal Line To make the data even easier to interpret, the script performs one final calculation by applying a third moving average to the MACD line itself. This creates a "Signal Line." Traders typically look at the relationship between the main MACD line and this Signal Line; when they cross each other, it often serves as a visual cue for potential shifts in market direction.
How it Works Visually
The script processes every historical price point on your chart to build these lines. It ultimately provides two main lines in a separate window:
- The MACD Line: Represents the immediate momentum of the price.
- The Signal Line: Acts as a smoother guide to help identify significant turning points in that momentum.
//+------------------------------------------------------------------+
//| MACD(DEMA)DiNapoli.mq4 |
//| Copyright © 2006, TrendLaboratory Ltd. |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//| E-mail: igorad2004@list.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Silver
#property indicator_color2 Red
//---- indicator parameters
extern double FastEMA=8.3896;
extern double SlowEMA=17.5185;
extern double SignalEMA=9.0503;
//---- indicator buffers
double Macd_buffer[];
double Sign_buffer[];
double Fast_buffer[];
double Slow_buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
IndicatorBuffers(4);
SetIndexBuffer(0,Macd_buffer);
SetIndexBuffer(1,Sign_buffer);
SetIndexBuffer(2,Fast_buffer);
SetIndexBuffer(3,Slow_buffer);
SetIndexStyle(0,DRAW_LINE);
SetIndexDrawBegin(0,1);
SetIndexDrawBegin(1,1);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- indicator buffers mapping
if(!SetIndexBuffer(0,Macd_buffer) && !SetIndexBuffer(1,Sign_buffer))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD(DEMA)DiNapoli("+FastEMA+","+SlowEMA+","+SignalEMA+")");
SetIndexLabel(0,"MACD(DEMA)");
SetIndexLabel(1,"Signal");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| MACD (DEMA) DiNapoli |
//+------------------------------------------------------------------+
int start()
{
for(int i=Bars; i>=0; i--)
{
Fast_buffer[i]=0.0;
Slow_buffer[i]=0.0;
Macd_buffer[i]=0.0;
Sign_buffer[i]=0.0;
if (i==Bars) {Fast_buffer[i]=Close[i];Slow_buffer[i]=Close[i];}
}
//---- macd counted in the 1-st buffer
for( i=Bars-1; i>=0; i--)
{
Fast_buffer[i]=Fast_buffer[i+1]+2.0/(1.0+FastEMA)*(Close[i]-Fast_buffer[i+1]);
Slow_buffer[i]=Slow_buffer[i+1]+2.0/(1.0+SlowEMA)*(Close[i]-Slow_buffer[i+1]);
Macd_buffer[i]=Fast_buffer[i]-Slow_buffer[i];
}
//---- signal line counted in the 2-nd buffer
for(i=Bars-1; i>=0; i--)
Sign_buffer[i]=Sign_buffer[i+1]+2.0/(1.0+SignalEMA)*(Macd_buffer[i]-Sign_buffer[i+1]);
//---- done
return(0);
}
Comments