SilverMACD+
Download scriptThis script is a specialized technical analysis tool designed to help traders visualize market momentum and identify potential entry or exit points by analyzing the relationship between different price trends. It functions as a modified version of the Moving Average Convergence Divergence (MACD) indicator, specifically tailored to provide clear, visual cues through color-coded histograms.
How the Logic Works
The tool operates by performing three distinct mathematical steps:
1. Calculating Trend Momentum First, the script looks at the historical price of an asset and calculates two different types of moving averages simultaneously: a "Fast" average and a "Slow" average. By subtracting the slower trend from the faster one, the script determines the gap between current price momentum and its long-term direction. This difference tells the trader how quickly the price is moving in a specific direction.
2. Creating a Signal Baseline Once the momentum (the gap) is established, the script takes that data and performs a second calculation to create a "Signal" line. Think of this as an average of the momentum itself. This provides a smoothed-out baseline that helps filter out temporary "noise" or minor price fluctuations, allowing the user to see the broader trend more clearly.
3. Visual Color Coding The final step is where the script provides its most useful information to the user. Instead of just showing simple lines, it translates the relationship between the Momentum and the Signal into a visual histogram:
- Green Highlights: When the current momentum is higher than or equal to the signal line, the script identifies this as a bullish (positive) state and displays it in green.
- Red Highlights: When the momentum falls below the signal line, the script identifies this as a bearish (negative) state and displays it in red.
Summary for the Trader
Essentially, this tool simplifies complex data into a "traffic light" style visual. It automatically compares two different layers of market movement and paints a histogram that shows you at a glance whether the current momentum is strengthening or weakening relative to its recent history. By observing where the colors switch, traders can better identify shifts in market sentiment.
//+------------------------------------------------------------------+
//| Silver MACD.mq4 |
//| Copyright © 2004, Viac |
//| http://www.viac.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, Viac.ru"
#property link "http://www.viac.ru/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 ForestGreen
#property indicator_color2 Red
//---- indicator parameters
extern int FastEMA=9;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern int Price=PRICE_CLOSE;
extern int Mode=MODE_EMA;
//---- 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+","+SignalSMA+")");
SetIndexLabel(0,"MACD");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
double MACD[];
double Signal[];
int limit;
int counted_bars=IndicatorCounted();
int i;
//---- check for possible errors
if(counted_bars<0) return(-1);
//
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- Âû÷èñëÿåì ìàññèâ MACD
for(i=0; i<limit; i++)
MACD[i]=iMA(NULL,0,FastEMA,0,Mode,Price,i)-iMA(NULL,0,SlowEMA,0,Mode,Price,i);
//---- Âû÷èñëÿåì ñèãíàëüíóþ ëèíèþ äëÿ MACD
for(i=0; i<limit; i++)
Signal[i]=iMAOnArray(MACD,Bars,SignalSMA,0,MODE_SMA,i);
//---- Åñëè MACD áîëüøå èëè ðàâíî ñèãíàëüíîé, òî çåëåíûé èíà÷å êðàñíûé
for (i=0; i<limit; i++)
{
if (MACD[i] >= Signal[i])
{
green_buffer[i] = MACD[i];
red_buffer[i] = 0;
}
else
{
green_buffer[i] = 0;
red_buffer[i] = MACD[i];
}
}
return(0);
}
Comments