Macd Support and Resistance
Download scriptThis indicator is designed to identify key price boundaries—specifically Support and Resistance levels—by analyzing the momentum of the market using the MACD (Moving Average Convergence Divergence) methodology. Instead of simply looking at where prices have bounced in the past, this tool uses a mathematical filter to determine when the market is showing signs of exhaustion or reversal.
How the Logic Works
The script operates by scanning historical price data and applying four distinct calculations simultaneously to identify different types of "floors" (Support) and "ceilings" (Resistance). It processes these in two primary categories:
1. Primary Support and Resistance (Solid Lines) The indicator looks at the interaction between the market's momentum signals and the actual highs and lows of the price candles.
- Resistance: When the momentum signal indicates a specific downward pressure, the script marks the recent low points as a potential support level.
- Support: When the signal suggests upward pressure, it identifies the high points to map out resistance.
- The logic ensures that these lines remain consistent across periods, creating a continuous visual path of significant price zones.
2. Secondary Support and Resistance (Dotted Lines) In addition to the primary levels, the script calculates secondary boundaries using a different component of the MACD calculation (the "Main" value).
- These provide an extra layer of depth, identifying deeper or more subtle turning points in the market.
- By using a slight "offset" or variance in its memory, it allows you to see not just where the price is reacting now, but how those reactions have shifted over the preceding bars.
Key Features for the User
- Dynamic Identification: The tool automatically distinguishes between "Support" (where the price might find a floor and bounce up) and "Resistance" (where the price might hit a ceiling and drop).
- Visual Distinction: The script separates these levels using different line styles (solid vs. dotted) and colors, allowing you to quickly differentiate between immediate price reactions and broader structural boundaries.
- Customizable Timeframes: You can adjust the look-back periods and the sensitivity of the MACD settings (Fast, Slow, and Signal periods), which changes how aggressively the indicator reacts to market volatility.
- Historical Backfilling: The script calculates these levels across the entire visible chart history, providing you with a clear visual map of where historical "walls" were built in the market.
//+------------------------------------------------------------------+
//| Macd Support and Resistance.mq4 |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Alksnis Gatis"
#property link "2xpoint@gmail.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Violet
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 Blue
extern string x="macd option";
extern int FEMA =8;
extern int SEMA =24;
extern int SMA =10;
extern string x2="timeframe- 0=current";
extern int PERIOD =0;
extern string x3="variant -100 100";
extern int variant =-2;
//---- buffers
double g1[];
double g2[];
double g3[];
double g4[];
double val1;
double val2;
double val3;
double val4;
int i;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexArrow(0, 158);
SetIndexArrow(1, 158);
//----
SetIndexStyle(0, DRAW_SECTION, STYLE_SOLID, 2);
SetIndexDrawBegin(0, i-1);
SetIndexBuffer(0, g1);
SetIndexLabel(0,"Resistance");
//----
SetIndexStyle(1,DRAW_SECTION,STYLE_SOLID,2);
SetIndexDrawBegin(1,i-1);
SetIndexBuffer(1, g2);
SetIndexLabel(1,"Support");
//---- drawing settings
SetIndexArrow(2, 158);
SetIndexArrow(3, 158);
//----
SetIndexStyle(2, DRAW_SECTION, STYLE_DOT, 2);
SetIndexDrawBegin(2, i-1);
SetIndexBuffer(2, g3);
SetIndexLabel(2,"Resistance1");
//----
SetIndexStyle(3,DRAW_SECTION,STYLE_DOT,2);
SetIndexDrawBegin(3,i-1);
SetIndexBuffer(3, g4);
SetIndexLabel(3,"Support1");
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
i = Bars;
while(i >= 0)
{
//1
val1 =iMACD(NULL,PERIOD,FEMA,SEMA,SMA,PRICE_LOW,MODE_SIGNAL,i);
if(val1 > 0)
g1[i] = Low[i];
else
g1[i] = g1[i+variant];
//2
val2 =iMACD(NULL,PERIOD,FEMA,SEMA,SMA,PRICE_HIGH,MODE_SIGNAL,i);
if(val2 < 0)
g2[i] = High[i];
else
g2[i] = g2[i+variant];
//3
val3 =iMACD(NULL,PERIOD,FEMA,SEMA,SMA,PRICE_LOW,MODE_MAIN,i);
if(val3 > 0)
g3[i] = Low[i];
else
g3[i] = g3[i+variant+1];
//2
val4 =iMACD(NULL,PERIOD,FEMA,SEMA,SMA,PRICE_HIGH,MODE_MAIN,i);
if(val4 < 0)
g4[i] = High[i];
else
g4[i] = g4[i+variant+1];
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments