Author: Copyright � 2006, Victor Chebotariov
MACD+MA

This tool is designed to help traders identify specific trend shifts and momentum changes on a price chart by combining two popular technical analysis methods: Moving Averages and the MACD (Moving Average Convergence Divergence) indicator.

Instead of cluttering the screen with complex lines, this script simplifies the data into clear visual signals—specifically, arrows that appear at key price points to indicate potential buying or selling opportunities.

How the Logic Works

The script constantly monitors two different types of market data simultaneously:

  1. Trend Direction (Moving Average): It looks at the "Moving Average," which smooths out price fluctuations to show the general direction of the market. The script specifically checks if this average is currently moving upward or downward compared to its previous position.
  2. Momentum (MACD): It also tracks the MACD, which measures the strength and speed of a price trend. It looks for "crossovers" or changes in the momentum's trajectory to see if the current move has enough power behind it.

Signal Generation

The script only triggers a visual signal when both of these independent conditions agree with each other at the same time. This "double confirmation" is intended to filter out market noise and provide more reliable entries:

  • Buy Signals (Red Arrows): A signal is generated when both the Moving Average is trending upward and the MACD momentum is also increasing. When these two conditions align, the script places an arrow at the high of the price candle, suggesting a positive trend is forming.
  • Sell Signals (Blue Arrows): Conversely, a signal is generated when both the Moving Average is trending downward and the MACD momentum is decreasing. When both indicators point toward a decline, the script places an arrow at the low of the price candle, suggesting a negative trend is forming.

Key Summary

By requiring two different types of mathematical confirmations before displaying a signal, this script aims to help traders identify high-probability moments where the overall trend and the immediate momentum are moving in the same direction.

Indicators Used
Moving average indicatorMACD Histogram
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
MACD+MA
//+------------------------------------------------------------------+
//|                                                      MACD+MA.mq4 |
//|                             Copyright © 2006, Victor Chebotariov |
//|                                      http://www.chebotariov.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Victor Chebotariov"
#property link      "http://www.chebotariov.com/"

extern int period = 14;
extern int ma_shift = 0;
extern int ma_method = 3;//0-3
extern int applied_price_ma = 0;//0-6

extern int fast_ema_period = 12;
extern int slow_ema_period = 26;
extern int applied_price_macd = 0;

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorShortName("MACD+MA");
//---- indicators
   SetIndexStyle(0,DRAW_ARROW,EMPTY,1,Blue);
   SetIndexArrow(0,159);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,1,Red);
   SetIndexArrow(1,159);
   SetIndexBuffer(1,ExtMapBuffer2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
//----
   i=Bars-counted_bars-1;
   while(i>=0)
     {
      double MA_0   = iMA(NULL,0,period,ma_shift,ma_method,applied_price_ma,i);
      double MA_1   = iMA(NULL,0,period,ma_shift,ma_method,applied_price_ma,i+1);
      double MACD_0 = iMACD(NULL,0,fast_ema_period,slow_ema_period,9,applied_price_macd,MODE_MAIN,i);
      double MACD_1 = iMACD(NULL,0,fast_ema_period,slow_ema_period,9,applied_price_macd,MODE_MAIN,i+1);

      if(MA_0>MA_1 && MACD_0>MACD_1)
        {
         ExtMapBuffer2[i]=High[i];
        }

      if(MA_0<MA_1 && MACD_0<MACD_1)
        {
         ExtMapBuffer1[i]=Low[i];
        }

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

Comments