Good_Macd dark screen
Download scriptThis tool is designed to provide traders with a visual representation of market momentum, helping to identify the strength and direction of price movements over time. Rather than looking at raw price action alone, this script processes data to reveal "hidden" trends through three distinct visual components:
Core Logic and Components
The script operates by calculating moving averages—which are essentially smoothed versions of a currency or asset's price—to filter out short-term "noise." It focuses on the relationship between two different speeds of these averages.
1. The MACD Line (The Momentum) The tool first calculates a "Fast" moving average and a "Slow" moving average. By subtracting the Slow average from the Fast average, the script produces the MACD Line.
- When this line is above zero, it indicates that recent price momentum is stronger than the long-term trend.
- When it falls below zero, it suggests that short-term momentum is weakening relative to the broader trend.
2. The Signal Line (The Smoothing) To make the momentum data even easier to read, the script applies a secondary smoothing process to the MACD Line itself. This creates the Signal Line. Think of this as a "trend of the trend." It reacts more slowly than the main MACD line, providing a stable point of reference to determine if a change in momentum is significant enough to be considered a potential reversal.
3. The Histogram (The Gap) The most visible element for many users is the Histogram. This is calculated by measuring the distance between the MACD Line and the Signal Line.
- As the gap between these two lines widens, the bars on the histogram grow taller, indicating increasing momentum.
- When the bars shrink or flip sides, it signals that the momentum is slowing down or potentially shifting direction.
Summary of Functionality
In simple terms, this script takes complex price data and simplifies it into a visual "heartbeat" of the market. By comparing the current momentum (MACD Line) against its smoothed average (Signal Line), it allows you to see not just where the price is going, but how fast it is moving there and when that energy might be starting to fade.
//+------------------------------------------------------------------+
//| MACD.mq4 |
//| Copyright © 2005, David W. Thomas |
//| mailto:davidwt@usa.net |
//+------------------------------------------------------------------+
// This is the correct computation and display of MACD.
#property copyright "Copyright © 2005, David W. Thomas"
#property link "mailto:davidwt@usa.net"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Aqua
#property indicator_color2 DeepPink
#property indicator_color3 MintCream
//---- input parameters
extern int FastMAPeriod=12;
extern int SlowMAPeriod=26;
extern int SignalMAPeriod=9;
//---- buffers
double MACDLineBuffer[];
double SignalLineBuffer[];
double HistogramBuffer[];
//---- variables
double alpha = 0;
double alpha_1 = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MACDLineBuffer);
SetIndexDrawBegin(0,SlowMAPeriod);
SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(1,SignalLineBuffer);
SetIndexDrawBegin(1,SlowMAPeriod+SignalMAPeriod);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2,HistogramBuffer);
SetIndexDrawBegin(2,SlowMAPeriod+SignalMAPeriod);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastMAPeriod+","+SlowMAPeriod+","+SignalMAPeriod+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
//----
alpha = 2.0 / (SignalMAPeriod + 1.0);
alpha_1 = 1.0 - alpha;
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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;
for(int i=limit; i>=0; i--)
{
MACDLineBuffer[i] = iMA(NULL,0,FastMAPeriod,0,MODE_EMA,PRICE_CLOSE,i) - iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
SignalLineBuffer[i] = alpha*MACDLineBuffer[i] + alpha_1*SignalLineBuffer[i+1];
HistogramBuffer[i] = MACDLineBuffer[i] - SignalLineBuffer[i];
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments