This tool is designed to automatically identify and display key price levels on your trading chart by analyzing the movement of a trend line (Moving Average). Rather than relying on manual guesswork, it scans historical data to find specific moments where the market's momentum shifts, highlighting potential areas of resistance and support.
How the Logic Works
The script operates by examining the "curvature" of a Moving Average. It looks for three specific consecutive values in the trend line to determine if the price is hitting a peak or a trough:
-
Identifying Resistance (Peaks): The tool searches for a "downward hook." It looks for a point where the current value is lower than the previous one, but the previous one was higher than the one before that. When the script finds this specific shape—a peak in the trend line—it identifies the highest price reached at that exact moment and draws a Blue horizontal line. This signifies a "Resistance" level where the price previously struggled to move higher.
-
Identifying Support (Troughs): Simultaneously, the tool searches for an "upward hook." It looks for a point where the current value is higher than the previous one, but the previous one was lower than the one before that. When it detects this shape—a valley in the trend line—it identifies the lowest price reached at that moment and draws a Red horizontal line. This signifies a "Support" level where the price previously found a floor and bounced back up.
Visual Representation on Your Chart
Instead of cluttering your screen with complex data, the script simplifies everything into two clear visual markers:
- Blue Line (Resistance): Automatically placed at the highest point of a detected trend peak. This helps you visualize where sellers might step in to prevent the price from rising further.
- Red Line (Support): Automatically placed at the lowest point of a detected trend valley. This helps you visualize where buyers might enter to prevent the price from falling further.
By automating this process, the tool helps traders quickly see where significant structural "floors" and "ceilings" have formed based on recent price action trends.
//+------------------------------------------------------------------+
//| UpDown_Resistance.mq4 |
//| Z.R Lin |
//| onlycherishlove@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Z.R Lin"
#property link "onlycherishlove@gmail.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
extern string PERIOD="";
extern double period=6;//the period of MA
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
ObjectCreate("Resistance",OBJ_HLINE,0,0,0,0,0);
ObjectCreate("Support",OBJ_HLINE,0,0,0,0,0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("Resistance");
ObjectDelete("Support");
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double F1=0,F3=0,MA1,MA2,MA3;
int B1,B2,SR=1;
while(F3==0)
{
MA1=iMA(NULL,0,period,0,MODE_SMA,PRICE_CLOSE,SR);
MA2=iMA(NULL,0,period,0,MODE_SMA,PRICE_CLOSE,SR+1);
MA3=iMA(NULL,0,period,0,MODE_SMA,PRICE_CLOSE,SR+2);
if(MA1!=0)
{
if(MA1<MA2 && MA2>MA3)
{
B1=SR+1;F1=MA1;
}
else if(MA1>MA2 && MA2<MA3)
{
B2=SR+1;F3=MA1;
}
}
SR++;
}
ObjectSet("Resistance",OBJPROP_PRICE1,iHigh(NULL,0,B1));
ObjectSet("Resistance",OBJPROP_COLOR,Blue);
ObjectSet("Resistance",OBJPROP_WIDTH,3);
ObjectSet("Support",OBJPROP_PRICE1,iLow(NULL,0,B2));
ObjectSet("Support",OBJPROP_COLOR,Red);
ObjectSet("Support",OBJPROP_WIDTH,3);
return(0);
}
//+------------------------------------------------------------------+
Comments