MACDsignals

Download script
Author: Gideon Smolders,2005
MACDsignals

This script is a custom technical analysis tool designed to identify potential market trend reversals by analyzing the momentum and velocity of price movements. Rather than relying on a simple moving average, it uses a sophisticated logic that looks at the "acceleration" behind the current price action to filter out noise and highlight significant shifts in direction.

Core Logic Overview

The script functions by calculating three primary components:

  1. The Momentum Gap: It first determines the distance between two different types of moving averages (Fast and Slow). This identifies the current strength of the trend.
  2. The Signal Line: It then smooths that momentum data to create a "signal" line, which helps differentiate between a steady move and a sudden, volatile spike.
  3. Relative Velocity: The core "intelligence" of this script lies in how it compares the current gap against several previous points in time. It doesn't just look at where the price is going; it calculates the rate of change (the speed) at which that momentum is moving.

How the Signals are Generated

The tool identifies specific "shapes" or patterns in these momentum calculations to trigger visual alerts on your chart:

  • Upward Signals: The script looks for specific conditions where the momentum is increasing significantly faster than it has in recent history. It evaluates a series of mathematical hurdles (defined by the "DivCalc" parameters) to ensure that the upward move has enough "weight" or velocity to be considered a valid trend shift rather than a minor fluctuation.
  • Downward Signals: Conversely, it looks for instances where momentum is dropping sharply. It scans for patterns where the downward pressure accelerates past specific thresholds, indicating a potential breakdown in price support.

Visual Output

When the script detects these specific momentum "breakouts" based on its internal logic:

  • It places a visual marker (an arrow) below the candle to suggest an upward movement.
  • It places a visual marker (an arrow) above the candle to suggest a downward movement.

In essence, this tool acts as a filter for high-velocity momentum shifts, helping traders spot where the "push" of the market is changing direction with enough force to potentially impact the price significantly.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
MACDsignals
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
// you are free to use and improve, however I would appreciate you send me your versions at gideonsmolders(@)gmail.com
//ATTENTION: error messages: zero divide
#property copyright "Gideon Smolders,2005"
#property link      "gideonsmolders(@)gmail.com"
//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 2
#property  indicator_color1  Olive  
#property  indicator_color2  FireBrick

//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern double DivCalc1=0.3;
extern double DivCalc2=0.35;
extern double DivCalc3=0.45;
extern double DivCalc4=0.60;
//---- indicator buffers
double     ind_buffer1a[];
double     ind_buffer1b[];
double     ind_buffer2[];
double     ind_buffer3[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(4);
//---- drawing settings
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,108);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,108);
   
//---- 3 indicator buffers mapping
   if(!SetIndexBuffer(0,ind_buffer1a) &&
      !SetIndexBuffer(1,ind_buffer1b) &&
      !SetIndexBuffer(2,ind_buffer2) &&      
      !SetIndexBuffer(3,ind_buffer3))
      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACDsignals("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Average                                      |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer
   for(int i=0; i<limit; i++)
      ind_buffer2[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)
                        -iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd additional buffer
   for(i=0; i<limit; i++)
      ind_buffer3[i]=iMAOnArray(ind_buffer2,Bars,SignalSMA,0,MODE_SMA,i);
//---- main loop
   double value=0;
   double prev_value=0;
   double prev2_value=0;
   double prev3_value=0;
   double prev4_value=0;   
   double div_value1=0;
   double div_value2=0;
   double div_value3=0;
   double div=0;
   double div2=0;
   double div3=0;
   for(i=0; i<limit; i++)
      {
         ind_buffer1a[i]=0.0;
         ind_buffer1b[i]=0.0;      
         value=ind_buffer2[i]-ind_buffer3[i];
         prev_value=ind_buffer2[i+1]-ind_buffer3[i+1];
         prev2_value=ind_buffer2[i+2]-ind_buffer3[i+2];
         prev3_value=ind_buffer2[i+3]-ind_buffer3[i+3];
         prev4_value=ind_buffer2[i+4]-ind_buffer3[i+4];
         div_value1=MathAbs(div/prev_value);
         div_value2=MathAbs(div2/prev2_value);
         div_value3=MathAbs(div3/prev3_value);
         div=value-prev_value;
         div2=value-prev2_value;
         div3=value-prev3_value;
         if ((value>prev_value && prev_value<prev2_value && prev2_value<prev3_value && div_value1>DivCalc1) || 
             (value>prev_value && prev_value>prev2_value && prev2_value<prev3_value && div_value2>DivCalc2) ||
             (value>prev_value && (prev_value<prev2_value || prev_value>prev2_value) && prev2_value>prev3_value && prev3_value<prev4_value && div_value3>DivCalc3) || 
             (value>prev_value && prev_value>prev2_value && prev2_value>prev3_value && div_value1>DivCalc4) ) ind_buffer1a[i]=Low[i]-2*Point;
         if ((value<prev_value && prev_value>prev2_value && prev2_value>prev3_value && div_value1>DivCalc1) ||
             (value<prev_value && prev_value<prev2_value && prev2_value>prev3_value && div_value2>DivCalc2) ||
             (value<prev_value && (prev_value>prev2_value || prev_value<prev2_value)  && prev2_value<prev3_value && prev3_value>prev4_value && div_value3>DivCalc3) ||
             (value<prev_value && prev_value<prev2_value && prev2_value<prev3_value && div_value2>DivCalc4)) ind_buffer1b[i]=High[i]+2*Point;
      }   
//---- done
   return(0);
  }
//+------------------------------------------------------------------+


Comments