MACD-Silver
Download scriptThis custom indicator is designed to provide a visual representation of market momentum by calculating the relationship between two different types of moving averages. Rather than showing standard price data, it focuses on the "convergence" and "divergence" of these averages to help traders identify whether the market is accelerating in one direction or the other.
How the Logic Works
1. The Core Calculation (Moving Averages) The script looks at two specific timeframes (defined by the "Fast" and "Slow" settings). It calculates a smoothed average of the price for both of these periods. By subtracting the value of the slower average from the faster one, the tool produces a single numerical value.
2. Momentum Tracking
- When the fast average is significantly higher than the slow average, it suggests upward momentum.
- When the fast average falls below the slow average, it suggests downward momentum.
- The "gap" between these two averages is what the indicator actually plots on your chart.
3. Visual Representation (The Histogram) To make this data easy to read at a glance, the script uses a dual-color histogram system:
- Positive Momentum: When the calculated value moves upward or stays above its previous point, it is highlighted in Lime.
- Negative Momentum: When the calculated value moves downward or falls below its previous point, it is highlighted in Crimson.
Key Functionality
Instead of simply showing a line that fluctuates above and below zero, this logic focuses on the change in the MACD value relative to the previous bar. By comparing the current calculation to the one immediately preceding it, the script dynamically assigns colors to help you instantly distinguish between bullish (buying) pressure and bearish (selling) pressure.
By adjusting the "Fast" and "Slow" parameters, users can change how sensitive the indicator is to price fluctuations, allowing for a customized view of market trends tailored to different trading styles.
//+------------------------------------------------------------------+
//| Custom MACD.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Crimson
//---- indicator parameters
extern int FastEMA=5;
extern int SlowEMA=13;
//---- indicator buffers
double green_buffer[];
double red_buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexBuffer(0,green_buffer);
//----
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexBuffer(1,red_buffer);
//----
IndicatorDigits(Digits+1);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+")");
SetIndexLabel(0,"MACD");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
double MACD;
int counted_bars=IndicatorCounted();
int i;
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
for (i = Bars - Max (counted_bars-1, 1); i>=0; i--) {
MACD=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_MEDIAN,i)-
iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_MEDIAN,i);
if ( ( (green_buffer[i+1] != 0) && (MACD >= green_buffer[i+1]) ) ||
( (red_buffer[i+1] != 0) && (MACD > red_buffer[i+1]) ) ) {
green_buffer[i] = MACD;
red_buffer[i] = 0;
}
else {
green_buffer[i] = 0;
red_buffer[i] = MACD;
}
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
int Max (int val1, int val2) {
if (val1 > val2) return(val1);
return(val2);
}
Comments