Silver-MACD

Download script
Silver-MACD

This custom technical indicator is designed to provide traders with a visual representation of momentum by measuring the relationship between two different moving averages. Instead of showing standard price movements, it focuses on the "gap" or convergence between these averages to help identify trends more clearly.

How the Logic Works

1. The Core Calculation The tool identifies two specific types of Exponential Moving Averages (EMAs): a "Fast" average and a "Slow" average.

  • The Fast EMA reacts quickly to recent price changes.
  • The Slow EMA tracks the broader, long-term trend.

The indicator calculates the difference between these two values at every point on the chart. When the Fast average is significantly above or below the Slow average, it indicates that price momentum is accelerating in a specific direction.

2. Visual Representation (Color Coding) To make this data easy to read at a glance, the script translates these calculations into a two-color histogram:

  • Green Momentum: If the current calculated value is higher than (or equal to) the previous value, the indicator displays as green. This typically suggests an upward trend or strengthening bullish momentum.
  • Red Momentum: If the calculated value drops below the previous value, the indicator switches to red. This suggests a downward trend or a shift toward bearish momentum.

3. Key Features for Traders

  • Dynamic Comparison: By comparing each new data point against the one immediately preceding it, the script creates a continuous visual flow of market sentiment.
  • Customizable Sensitivity: The underlying logic allows for the adjustment of the "Fast" and "Slow" periods, enabling users to tailor the indicator's sensitivity to different trading styles (e.g., making it faster for day trading or slower for long-term investing).
  • Separate Visual Window: The results are plotted in their own dedicated window below the main price chart, ensuring that the primary price action remains uncluttered while still providing clear directional cues.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
Silver-MACD
//+------------------------------------------------------------------+
//|                                                  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  ForestGreen
#property  indicator_color2  Red
//---- indicator parameters
extern int FastEMA=5;
extern int SlowEMA=34;
//---- 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