MTF_MACD_Bars

Author: Kirk Sloan
MTF_MACD_Bars

This tool is designed to provide traders with a multi-timeframe visual representation of the MACD (Moving Average Convergence Divergence) indicator. Instead of just showing the raw data, it translates complex momentum movements into distinct color-coded signals that help identify trend shifts across different time horizons.

Core Functionality

The script works by analyzing price data from a specific timeframe that you choose (ranging from 1-minute intervals up to monthly charts). It calculates the relationship between two primary components of the MACD: the Main Line (which tracks the strength of the momentum) and the Signal Line (which acts as a smoothed average of that momentum).

How the Visual Logic Works

The tool interprets the interaction between these two lines to generate four specific visual outputs on your chart:

  • Bullish Momentum (Green): When the Signal Line is positioned below the Main Line, the script identifies this as a positive trend movement and highlights it accordingly.
  • Bearish Momentum (Red): Conversely, when the Signal Line sits above the Main Line, the script recognizes a downward trend and signals it with a distinct visual marker.
  • Upper Zone Signals: The tool looks for specific "oversold" or "overbought" contexts by checking where the Main Line sits in relation to the zero axis. If the momentum is positive but the Signal Line drops below the Main Line while the price is still above the zero line, it flags this specific state.
  • Lower Zone Signals: Similarly, if the momentum is negative and the Signal Line rises above the Main Line while the price remains below the zero line, the script identifies this specific reversal context.

User Experience

For a trader, this means you don't have to manually calculate whether the momentum is shifting or which direction it is pointing. By selecting your desired timeframe (e.g., H1 for Hourly or D1 for Daily), the script automatically processes the math and paints the chart with clear visual cues, allowing for quicker identification of market turns and trend confirmations.

Indicators Used
MACD Histogram
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
MTF_MACD_Bars
//+------------------------------------------------------------------+
//|                                                MTF_MACD_Bars.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//|                                                    FlatTrend.mq4 |
//|                                                       Kirk Sloan |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Kirk Sloan"
#property link      "http://www.metaquotes.net"
#property link      "Modified by cja"

#property indicator_separate_window
#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_buffers 4
#property indicator_color1 Tomato
#property indicator_color2 YellowGreen
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_width1 4
#property indicator_width2 4
#property indicator_width3 4
#property indicator_width4 4


//---- input parameters
extern int Minutes=0;
extern int MACD_Fast = 8;
extern int MACD_Slow = 17;
extern int MACD_MA = 9;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
/*double Ma;
double hhigh, llow;
double Psar;
double MA1,MA2,MA3;
double PADX,NADX;*/
string TimeFrameStr;

double MACD_Signal,MACD_Main;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
  SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
  SetIndexBuffer(0,ExtMapBuffer1);
  SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
  SetIndexBuffer(1,ExtMapBuffer2);
  SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
  SetIndexBuffer(2,ExtMapBuffer3);
  SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
  SetIndexBuffer(3,ExtMapBuffer4);

switch(Minutes)
   {
      case 1 : TimeFrameStr="Period_M1"; break;
      case 5 : TimeFrameStr="Period_M5"; break;
      case 15 : TimeFrameStr="Period_M15"; break;
      case 30 : TimeFrameStr="Period_M30"; break;
      case 60 : TimeFrameStr="Period_H1"; break;
      case 240 : TimeFrameStr="Period_H4"; break;
      case 1440 : TimeFrameStr="Period_D1"; break;
      case 10080 : TimeFrameStr="Period_W1"; break;
      case 43200 : TimeFrameStr="Period_MN1"; break;
      default : TimeFrameStr="Current Timeframe"; Minutes=0;
   }
   IndicatorShortName("MTF_MACD ("+TimeFrameStr+")");  

 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----

for (int i = 0; i < 300; i++){
   ExtMapBuffer1[i]=0;
   ExtMapBuffer2[i]=0;
   ExtMapBuffer3[i]=0;
   ExtMapBuffer4[i]=0;
   

   MACD_Signal=iMACD(NULL,Minutes,MACD_Fast,MACD_Slow,MACD_MA,PRICE_CLOSE,MODE_SIGNAL,i);
   MACD_Main  =iMACD(NULL,Minutes,MACD_Fast,MACD_Slow,MACD_MA,PRICE_CLOSE,MODE_MAIN,i);
   
   if(MACD_Signal < MACD_Main )ExtMapBuffer2[i] = -1;//Sig Below MACD 
   if(MACD_Signal > MACD_Main )ExtMapBuffer1[i] = 1;//Sig above MACD
  /* if(ExtMapBuffer1[i] == 0 && ExtMapBuffer2[i] == 0)
   {ExtMapBuffer3[i] = 1;}*/
   if(MACD_Signal < MACD_Main && MACD_Main > 0)ExtMapBuffer3[i] = 1;//Sig below MACD & Above 0
   if(MACD_Signal > MACD_Main && MACD_Main < 0)ExtMapBuffer4[i] = -1;//Sig above MACD & Below 0
  
}
 

 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments