wlxFractals_v2
Download scriptThis script is a technical analysis tool designed to identify specific structural patterns in price movement, known as "Fractals." It automatically scans historical price data to highlight significant turning points where the market reaches a local peak or valley relative to the surrounding candles.
Core Functionality
The tool identifies two distinct types of price structures:
- Upper Fractals: These represent local high points (resistance levels) where a candle's peak is higher than those surrounding it.
- Lower Fractals: These represent local low points (support levels) where a candle's bottom is lower than those surrounding it.
How the Logic Works
The script evaluates each price candle by looking at its neighbors to the left and right based on user-defined parameters. Instead of just looking for a single high or low point, it follows a rigorous verification process:
- Right-Side Verification: The script first checks the candles immediately to the right of a potential point. For an upper fractal, it ensures that the current candle's high is strictly greater than the highs of the specified number of candles following it. For a lower fractal, it ensures the low is strictly lower than the lows of those same candles.
- Left-Side Verification: Once the right side is confirmed, the script looks at the candles to the left. It verifies that the current candle maintains its status as a peak or valley relative to the preceding price action.
- Equality Handling: The logic includes a specific mechanism to handle "equal" prices (where two consecutive candles have the exact same high or low). It balances these instances to ensure that a cluster of equal highs or lows is treated as a single structural fractal rather than being ignored or counted multiple times.
Visual Output
When the script successfully confirms a pattern, it places an arrow on the chart:
- Blue Arrows: Mark the confirmed Upper Fractals (potential areas of price rejection from above).
- Red Arrows: Mark the confirmed Lower Fractals (potential areas of price rejection from below).
By identifying these points, the tool helps traders visualize the "skeleton" of the market trend, highlighting where the price has historically reversed or consolidated.
//+------------------------------------------------------------------+
//| wlxFractals.mq4 |
//| Copyright © 2004, by konKop, GOODMAN, Mstera, af + wellx |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, by wellx"
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Red
//---- input parameters
extern int Equals=5;
extern int nLeftUp=2;
extern int nRightUp=2;
extern int nLeftDown=2;
extern int nRightDown=2;
//---- buffers
double FractalsUp[];
double FractalsDown[];
int pos=0, cntup=0, cntdown=0, cnt=0;
int r=0,l=0,e=0;
int fup=0,fdown=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,217);
SetIndexBuffer(0,FractalsUp);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,218);
SetIndexBuffer(1,FractalsDown);
SetIndexEmptyValue(1,0.0);
cntup=nLeftUp+nRightUp+Equals+1;
cntdown=nLeftDown+Equals+1;
if (cntup>=cntdown) cnt=cntup;
if (cntup<cntdown) cnt=cntdown;
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i=0, j=0;
int cbars=IndicatorCounted();
if (cbars<0) return(-1);
if (cbars>0) cbars--;
pos=0;
if (cbars > (Bars-cnt-1)) pos=(Bars-cnt-1);
else pos=cbars+nRightUp;
while (pos>=nRightUp)
{
FractalsUp[pos] =NULL;
FractalsDown[pos]=NULL;
//ôÐÀÊÒÀË ÂÂÅÐÕ
r=nRightUp; //ïðîâåðÿåì ïðàâóþ ñòîðîíó ôðàêòàëà
for (i=1;i<=r;i++)
{
if (High[pos]<=High[pos-i]) break;
};
//åñëè ñïðàâà âñå ÎÊ òî i äîëæíî áûòü ðàâíî r+1
if (i==r+1) //FractalsUp[pos]=High[pos];
{
l=nLeftUp; //ïðîâåðÿåì ëåâóþ ñòîðîíó ôðàêòàëà
e=Equals;
for (j=1;j<=l+Equals;j++)
{
if (High[pos] < High[pos+j]) break;
if (High[pos] > High[pos+j]) l--;
if (High[pos] == High[pos+j])e--;
if (l==0)
{
FractalsUp[pos]=High[pos];
break;
};
if (e<0) break;
};
};
//ÔÐÀÊÒÀË ÂÍÈÇ
r=nRightDown; //ïðîâåðÿåì ïðàâóþ ñòîðîíó ôðàêòàëà
for (i=1;i<=r;i++)
{
if (Low[pos]>=Low[pos-i]) break;
};
if (i==r+1) //FractalsUp[pos]=High[pos];
{
l=nLeftDown; //ïðîâåðÿåì ëåâóþ ñòîðîíó ôðàêòàëà
e=Equals;
for (j=1;j<=l+Equals;j++)
{
if (Low[pos] > Low[pos+j]) break;
if (Low[pos] < Low[pos+j]) l--;
if (Low[pos] == Low[pos+j])e--;
if (l==0)
{
FractalsDown[pos]=Low[pos];
break;
};
if (e<0) break;
};
};
pos--;
};
//----
return(0);
}
//+------------------------------------------------------------------+
Comments