MACD_color

This custom indicator is designed to enhance the standard Moving Averages Convergence Divergence (MACD) tool by improving its visual clarity and making market trends easier to identify at a glance. It primarily focuses on changing how the data is displayed on your trading chart rather than altering the core mathematical calculations of the MACD itself.

Visual Enhancements

The primary logic of this script revolves around two specific visual improvements:

  • Dynamic Color Coding: Unlike the standard MACD, which often presents a single uniform color, this tool uses a "coloring style" similar to an Awesome Oscillator (AO). It automatically distinguishes between upward and downward momentum by changing the color of the histogram bars. When the momentum shifts in a positive direction compared to the previous period, it is highlighted in one color; when it moves negatively, it switches to another. This allows traders to instantly spot changes in trend direction without having to analyze the raw values.
  • Clean Interface (Hidden Null Bars): A common visual clutter in standard indicators is the appearance of "null bars" or flat lines at the zero level where there is no significant movement. This script includes logic specifically designed to hide these unnecessary bars, resulting in a cleaner, more professional-looking chart that focuses only on active price data.

Underlying Mechanics

While the visual style is customized, the tool still relies on three core parameters that you can adjust:

  1. Fast EMA: A quick-moving average to capture recent price changes.
  2. Slow EMA: A longer-term moving average to establish the broader trend.
  3. Signal SMA: A secondary line used to smooth out the MACD data, providing a clear reference point for potential crossover signals.

In summary, this script takes the standard MACD logic and applies a "smart" visual layer. It simplifies the user experience by using color to signal momentum shifts and removing visual noise, making it an ideal tool for traders who prefer a more intuitive and organized way to view market dynamics.

Indicators Used
Moving average indicatorMoving average indicator
8 Views
0 Downloads
0 Favorites
MACD_color
//+------------------------------------------------------------------+
//|                                                  Custom MACD.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

//
//    Îòëè÷àåòñÿ îò ñòàíäàðòíîãî ÌÀÑD 
//    1. ðàñêðàñêîé â ñòèëå ÀÑ/ÀÎ
//    2. çàïðåòîì íà èçîáðàæåíèå íóëåâîãî áàðà
//
//    Difference from ÌÀÑD of standart
//    1. color of style of AC/AO
//    2. unvisible null bar
#property  copyright "Aleksandr Pak,Almaty, 2006"
#property  link  "ekr-ap@mail.ru" 
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Green
#property  indicator_color2  Red
#property  indicator_color3  Silver

#property  indicator_width1  2
#property  indicator_width2  2
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double     MacdBuffer[],   MacdBufferUp[],   MacdBufferDown[];
double     SignalBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
  IndicatorBuffers(4);
   
   SetIndexBuffer (0,MacdBufferUp);
   SetIndexStyle  (0,DRAW_HISTOGRAM);
   SetIndexBuffer (1,MacdBufferDown); 
   SetIndexStyle  (1,DRAW_HISTOGRAM);
   SetIndexBuffer (2,SignalBuffer);
   SetIndexStyle  (2,DRAW_LINE);
   SetIndexDrawBegin(2,SignalSMA);
   SetIndexBuffer (3,MacdBuffer);
   SetIndexStyle  (3,DRAW_NONE);   
   
   SetIndexLabel  (0,"Buffer 0");
   SetIndexLabel  (1,"Buffer 1");
   SetIndexLabel  (2,"Signal");
   IndicatorDigits(Digits+3);
   IndicatorShortName("MACD_color("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit,i;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
   for(i=0; i<limit; i++)
         {
         MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
         }
   for(i=0; i<limit; i++)
   {
      MacdBufferDown[i]=0.0; MacdBufferUp[i]=0.0;
     
         if(i>=1) //ýòî çàðåò íà èçîáðàæåíèå íóëåâîãî áàðà //break the null bar  
            {
               if(MacdBuffer[i+1]-MacdBuffer[i]>=0)MacdBufferDown[i]=MacdBuffer[i]; //óñëîâèÿ ðàñêðàñè //condition of color
                  else MacdBufferUp[i]=MacdBuffer[i];}
            }
   for(i=0; i<limit; i++) SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
   return(0);
  }
//+------------------------------------------------------------------+

Comments