wlxFractals
Download scriptThis script is a technical analysis tool designed for the MetaTrader platform that identifies specific price turning points on a chart, commonly known as "Fractals." These are visual markers used by traders to recognize significant peaks (highs) and valleys (lows) in market momentum.
Core Logic Overview
The logic functions by scanning historical price data and comparing each candle against its neighbors to determine if it represents a local extreme point. It does not simply look for the highest or lowest price in a broad range; instead, it verifies a specific "structural" relationship between a central candle and the candles surrounding it on both the left and right sides.
How the Analysis Works
The script evaluates two distinct types of market structures:
1. Identifying Upper Fractals (Resistance/Peaks) To identify a peak, the script looks for a candle where the high price is greater than the highs of the candles immediately preceding it (to the right) and follows specific height requirements relative to the candles following it (to the left).
- The Right Side: It ensures that the central candle is higher than a set number of bars on its right side.
- The Left Side: It checks the left side to ensure the high price remains dominant, specifically looking for a sequence where the central high is either greater than or equal to the surrounding prices. If these conditions are met, it places a blue arrow marking an "Upper Fractal."
2. Identifying Lower Fractals (Support/Valleys) Conversely, to identify a valley, the script looks for a candle where the low price is lower than the lows of the candles on its right and maintains a similar dominance over the prices on its left.
- The Right Side: It confirms the central candle's low is lower than the designated number of bars to the right.
- The Left Side: It verifies that the low price remains at or below the neighboring heights. If this condition is satisfied, it places a red arrow marking a "Lower Fractal."
Customization and Precision
The script allows users to define the sensitivity of these markers through several adjustable parameters:
- Left and Right Proximities: You can define exactly how many candles to the left and right the script should "look at" to confirm a peak or valley. Increasing these numbers makes the tool more conservative (identifying only major swings), while decreasing them makes it more sensitive (identifying smaller, more frequent fluctuations).
- Equality Tolerance: The logic includes an "Equals" parameter, which allows the script to account for scenarios where multiple consecutive candles share the exact same high or low price, ensuring that the marker is placed correctly even in choppy or sideways markets.
Visual Output
The final result is a clean visual overlay on the trading chart. Blue arrows appear at the top of significant price peaks, and red arrows appear at the bottom of significant price valleys, helping traders quickly identify potential areas of support and resistance without having to manually scan every price movement.
//+------------------------------------------------------------------+
//| 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 Blue
#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
SetIndexBuffer(0, FractalsUp);
SetIndexBuffer(1, FractalsDown);
//----
SetIndexStyle(0, DRAW_ARROW, 0, 0);
SetIndexArrow(0, 217);
//----
SetIndexStyle(1, DRAW_ARROW, 0, 0);
SetIndexArrow(1, 218);
//----
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()
{
//----
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 = Bars - (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