BPS Support and Resistance 2
Download scriptThis script is designed to identify key price levels on a trading chart by detecting "fractals." In the world of trading, these represent Support and Resistance zones—specific areas where the price has historically struggled to move past or has consistently bounced back from.
How the Logic Works
The tool works by scanning historical price data to find specific peaks and valleys. It doesn't just look at a single candle in isolation; instead, it looks for a "neighborhood" of price movement to confirm a significant turning point.
1. Identifying Resistance (High Points) To mark a point as Resistance, the script looks for a peak where the high price of a specific candle is higher than all the candles surrounding it within a predefined range (the "period"). If the center candle is taller than its neighbors to both the left and the right, the script flags this as a potential ceiling. These points are displayed on your chart in Red.
2. Identifying Support (Low Points) Similarly, to mark a point as Support, the script looks for a valley where the low price of a specific candle is lower than all the candles surrounding it within that same range. If the center candle is deeper than its neighbors to both the left and the right, the script flags this as a potential floor. These points are displayed on your chart in Blue.
3. Visual Continuity The logic ensures that these levels are clearly visible by "carrying" the values across the chart. Once a significant peak or valley is identified, the script maintains that level visually, allowing you to see exactly where historical price action hit a wall and reversed direction.
Key Parameters
- Period: This determines the "neighborhood" size. A larger period means the script will only identify very prominent, major peaks and valleys, while a smaller period will highlight more frequent, minor fluctuations.
- Max Bars: This controls how far back into the past the script will scan to calculate these levels, ensuring the chart remains clean and focused on relevant historical data.
Summary for the Trader
Essentially, this tool filters out the "noise" of daily price movements to highlight the significant structural turning points of the market. By identifying where price has historically peaked (Red) or bottomed out (Blue), it provides a visual map of the supply and demand zones on your trading screen.
//+------------------------------------------------------------------+
//| Support and Resistance 2 |
//| Copyright © 2004/5/6/7 Barry Stander |
//| http://www.4Africa.net/4meta/ |
//+------------------------------------------------------------------+
#property copyright "Support and Resistance Copyright © 2006 Barry Stander fx1@4africa.net"
#property link "http://www.4Africa.net/4meta/"
string version = "";
string likeit = " ";
extern int srPeriod = 7;
extern int MaxBars = 500;
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- buffers
double v1[];
double v2[];
double val1;
double val2;
int i;
double upper_fr[300];
double lower_fr[300];
int init()
{
Comment( version + "\n" + likeit );
IndicatorBuffers(2);
SetIndexArrow(0, 119);
SetIndexStyle(0,DRAW_ARROW,STYLE_DOT,1,Red);
SetIndexDrawBegin(0,i-1);
SetIndexBuffer(0, v1);
SetIndexLabel(0,"Resistance");
SetIndexArrow(1, 119);
SetIndexStyle(1,DRAW_ARROW,STYLE_DOT,1,Blue);
SetIndexDrawBegin(1,i-1);
SetIndexBuffer(1, v2);
SetIndexLabel(1,"Support");
return(0);
}
int start()
{
Comment( version + "\n" + likeit );
int counted = IndicatorCounted();
if (counted < 0) return (-1);
if (counted > 0) counted--;
int limit = MathMin(Bars-counted, MaxBars);
double dy = 0;
// for (int i=1; i <= 20; i++)
// {
// dy += 0.3*(High[i]-Low[i])/20;
// }
for (int i=0+srPeriod; i <= limit+srPeriod; i++)
{
upper_fr[i] = 0;
lower_fr[i] = 0;
if (is_upper_fr(i, srPeriod)) upper_fr[i] = High[i];//+dy;
if (is_lower_fr(i, srPeriod)) lower_fr[i] = Low[i];//-dy;
}
i=Bars;
while(i>=0)
{
val1 = upper_fr[i];
if (val1 > 0)
v1[i]=High[i];
else
v1[i] = v1[i+1];
val2 = lower_fr[i];
if (val2 > 0)
v2[i]=Low[i];
else
v2[i] = v2[i+1];
i--;
}
return(0);
}
//+------------------------------------------------------------------+
//
// i-FractalsEx from: http://codebase.mql4.com/1302
// #property copyright "© 2007 RickD"
// #property link "www.e2e-fx.net"
//
bool is_upper_fr(int bar, int period)
{
for (int i=1; i<=period; i++)
{
if (bar+i >= Bars || bar-i < 0) return (false);
if (High[bar] < High[bar+i]) return (false);
if (High[bar] < High[bar-i]) return (false);
}
return (true);
}
bool is_lower_fr(int bar, int period)
{
for (int i=1; i<=period; i++)
{
if (bar+i >= Bars || bar-i < 0) return (false);
if (Low[bar] > Low[bar+i]) return (false);
if (Low[bar] > Low[bar-i]) return (false);
}
return (true);
}
Comments