macd_and_volumes

Download script
Author: IvanMorozov
macd_and_volumes

This custom trading indicator is designed to provide a comprehensive visual analysis of market momentum and activity by combining traditional Moving Average Convergence Divergence (MACD) components with live volume data. Unlike standard indicators that only show one set of information, this tool consolidates four distinct data points into a single view to help traders understand the "strength" behind price movements.

Core Functionality

The indicator operates based on three primary layers of mathematical logic:

1. Momentum Tracking (Fast and Slow Lines) The tool first calculates two different types of moving averages based on the closing prices of the asset.

  • The Fast Line tracks short-term price trends.
  • The Slow Line tracks long-term price trends. By calculating the difference between these two, the indicator identifies whether the current market momentum is accelerating or decelerating.

2. The MACD Histogram The third layer of logic takes the results of the Fast and Slow lines and subtracts one from the other to create a Histogram. This visual bar chart represents the "gap" between short-term and long-term momentum. When the histogram is large, it signals a strong trend; when it shrinks or crosses the center line, it suggests a potential shift in market direction.

3. Integrated Volume Analysis What sets this specific version apart is the inclusion of a Volume Line. The script retrieves the trading volume for the current asset and applies a dynamic scaling calculation. This ensures that the volume data is adjusted to fit visually within the same window as the MACD lines, allowing you to see at a glance whether a price move is happening with high participation (high volume) or if it is a "weak" move driven by low trading activity.

User Experience and Customization

The script allows for several personalized adjustments to suit different trading styles:

  • Toggleable Volume: Users can choose whether to display the volume data or hide it to keep the chart clean.
  • Adjustable Periods: The settings allow for customization of the "Fast" and "Slow" timeframes (the periods), enabling traders to switch between aggressive day-trading views and smoother, long-term trend tracking.
  • Visual Clarity: By using distinct colors (Gray for the Histogram, Red for Fast, Blue for Slow, and Green for Volume), the tool ensures that all four data streams are easily distinguishable at a glance.

Summary of Benefits

By merging momentum (MACD) with liquidity (Volume), this indicator helps eliminate "false signals." It allows a trader to verify if a trend is actually supported by market participants or if it is merely a temporary fluctuation in price.

Price Data Components
Series array that contains tick volumes of each bar
Indicators Used
Moving average indicatorMoving average indicator
7 Views
0 Downloads
0 Favorites
macd_and_volumes
//+------------------------------------------------------------------+
//|                                                       MACD+v.mq4 |
//|                                                      IvanMorozov |
//|                            https://www.mql5.com/ru/users/frostow |
//+------------------------------------------------------------------+
#property copyright "IvanMorozov"
#property link      "https://www.mql5.com/ru/users/frostow"
#property version   "1.2"
#property description "MACD with volumes"
#property strict
#property indicator_separate_window
#property indicator_levelwidth 1
#property indicator_levelstyle STYLE_DOT
#property indicator_buffers 4    
#property indicator_plots   4    
//--- Ãèñòîãðàììà MACD
#property indicator_label1  "Hist"    //Name, that we can see on chart
#property indicator_type1   DRAW_HISTOGRAM   //Type
#property indicator_color1  clrGray          //Color
#property indicator_style1  STYLE_SOLID      //Style
#property indicator_width1  2                //Width... and the same about following:
//--- Áûñòðàÿ ëèíèÿ MACD
#property indicator_label2  "Fast" 
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- Ìåäëåííàÿ ëèíèÿ MACD
#property indicator_label3  "Slow"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrBlue
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- Ëèíèÿ îáúåìà
#property indicator_label4  "Volume" 
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrGreen
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1

//--- indicator buffers
double         HistogramBuffer[];
double         LBuffer[];
double         SBuffer[];
double         VBuffer[];

//input data
extern bool v = true;//Will volumes be shown?
extern int p1 = 12;  //Period of MACD
extern int p2 = 26;
extern int p3 = 9;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,HistogramBuffer);
   SetIndexBuffer(1,LBuffer);     //Fast         
   SetIndexBuffer(2,SBuffer);     //Slow
   if(v) SetIndexBuffer(3,VBuffer);

   IndicatorSetInteger(INDICATOR_LEVELS,1);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,0);
   IndicatorSetString(INDICATOR_SHORTNAME,"MACD + Volumes");

   return 0;
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+


int start()
  {
   int i,
   counted_bars,
   limit;
   string sym=Symbol();

   counted_bars=IndicatorCounted();
   limit=Bars-counted_bars;

// Fast
   for(i=0; i<limit; i++) LBuffer[i]=iMA(sym,0,p1,0,MODE_EMA,PRICE_CLOSE,i) -
      iMA(sym,0,p2,0,MODE_EMA,PRICE_CLOSE,i);

// Slow
   for(i=0; i<limit; i++) SBuffer[i]=iMAOnArray(LBuffer,Bars,p3,0,MODE_EMA,i);

// Hist
   for(i=0; i<limit; i++) HistogramBuffer[i]=LBuffer[i]-SBuffer[i];

// Volume
   for(i=0; i<limit; i++)
     {
      VBuffer[i]=iVolume(sym,0,i) *(MathPow(10,-2-MarketInfo(sym,MODE_DIGITS)));
      //Volumes will be reduced to show it correctly
     }
   return 0;
  }
//+------------------------------------------------------------------+

Comments