macdchannels

Download script
Author: Copyright 2015, MetaQuotes Software Corp.
macdchannels

This tool is designed as a custom technical indicator for the MetaTrader platform, specifically built to help traders visualize momentum and price trends through the calculation of multiple moving averages. By combining several distinct mathematical methods into a single view, it provides a multi-layered perspective on market behavior.

Core Components

The logic operates by calculating four distinct lines on your chart simultaneously:

  • Fast Exponential Moving Average (EMA): This tracks the recent price action closely. Because it is "fast," it reacts quickly to sudden changes in price, making it useful for identifying immediate momentum.
  • Slow Exponential Moving Average (EMA): This tracks the price over a longer period. It filters out minor market noise to provide a clearer picture of the broader trend direction.
  • MACD Simple Moving Average (SMA): This introduces a different smoothing method (Simple Moving Average) based on specific parameters, providing a steady baseline for comparison against the faster exponential lines.
  • The Combined Average (MACDAVG): This is a unique calculation where the script takes the values of the three previous lines—the Fast EMA, the Slow EMA, and the MACD SMA—and calculates their mean (average).

How the Logic Works

The script processes historical price data to plot these lines across your chart. It continuously updates as new price information becomes available, ensuring the visuals stay current with live market movements.

By placing all four values on the screen at once, the tool allows you to observe the relationship between short-term volatility and long-term trends. The final "Combined Average" line acts as a consolidated signal, blending the sensitivities of both exponential and simple moving averages into one representative visual. This helps in identifying where various market perspectives intersect, potentially making it easier to spot significant shifts in price dynamics.

Indicators Used
Moving average indicator
10 Views
0 Downloads
0 Favorites
macdchannels
//+------------------------------------------------------------------+
//|                                                 MACDChannels.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   4
//--- plot FastEMA
#property indicator_label1  "FastEMA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrMaroon
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot SlowEMA
#property indicator_label2  "SlowEMA"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrGray
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot MACDSMA
#property indicator_label3  "MACDSMA"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrBrown
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- plot MACDAVG
#property indicator_label4  "MACDAVG"
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrChartreuse
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1
//--- input parameters
input uint      FastEMA=12;
input uint      SlowEMA=26;
input uint      MACDSMA=9;
input ENUM_APPLIED_PRICE      ApplyPrice=PRICE_CLOSE;
//--- indicator buffers
double         FastEMABuffer[];
double         SlowEMABuffer[];
double         MACDSMABuffer[];
double         MACDAVGBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,FastEMABuffer);
   SetIndexBuffer(1,SlowEMABuffer);
   SetIndexBuffer(2,MACDSMABuffer);
   SetIndexBuffer(3,MACDAVGBuffer);

//---
   IndicatorShortName("MACDChannels("+IntegerToString(FastEMA)+","+IntegerToString(SlowEMA)+","+IntegerToString(MACDSMA)+")");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   ObjectsDeleteAll(0,DRAW_LINE);

  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   MACDChannels();
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---

  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---

  }
//+------------------------------------------------------------------+
//| MACDChannels function                                              |
//+------------------------------------------------------------------+
void MACDChannels()
  {
//---

   int limit;
   int counted_bars=IndicatorCounted();
//----last counted bar will be pecounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=limit -1; i>=0;i--)
     {
      FastEMABuffer[i]=iMA(NULL,NULL,FastEMA,0,MODE_EMA,ApplyPrice,i);
      SlowEMABuffer[i]=iMA(NULL,NULL,SlowEMA,0,MODE_EMA,ApplyPrice,i);
      MACDSMABuffer[i]=iMA(NULL,NULL,MACDSMA,0,MODE_SMA,ApplyPrice,i);
      MACDAVGBuffer[i]=(FastEMABuffer[i]+SlowEMABuffer[i]+MACDSMABuffer[i])/3;
     }
  }
//+------------------------------------------------------------------+

Comments