FractalVolOpt
Download scriptThis tool is designed to identify specific structural turning points in price action, commonly referred to as "fractals." It automatically scans historical price data to pinpoint areas where the market has reached a local peak (high) or a local valley (low) relative to the surrounding bars.
How the Logic Works
The script identifies these turning points by analyzing the relationship between a specific candle and its immediate neighbors on both the left and right sides. It looks for "extremes" based on three primary conditions:
1. Price Comparison (The Neighborhood Check) For a high point to be marked, the script ensures that the price at that moment is higher than a set number of candles preceding it and a set number of candles following it. Conversely, for a low point, it confirms the price is lower than the surrounding candles in both directions. This ensures that the marks only appear on significant peaks and valleys rather than minor fluctuations.
2. Equality Handling The logic includes a specific rule for when multiple candles share the exact same high or low price. It calculates the "equality" within those clusters to ensure that even if a flat peak or a wide floor is formed, the tool correctly identifies the structural boundary of that movement.
3. Volume and Candle Strength Verification To filter out noise and increase accuracy, the script adds two additional layers of validation:
- Volume Trend: It checks the trading volume to ensure that the momentum at the turning point aligns with certain stability requirements (comparing the volume of the current candle to the one preceding it).
- Price Action Geometry: It analyzes the relationship between the opening, closing, and high/low prices of the candle. For example, when identifying a high point, it verifies that the "upper wick" or price movement represents a significant portion of the total candle range, confirming that the price reached a definitive limit before retreating.
Visual Output
Once these conditions are met, the script places visual markers on your chart:
- Upward Fractals: Represented by markers at the top of high points to signify potential resistance or trend reversals.
- Downward Fractals: Represented by markers at the bottom of low points to signify potential support or trend shifts.
By combining price extremes, volume trends, and candle geometry, this tool filters out "fake" movements, highlighting only the most significant structural points in the market's history.
//+------------------------------------------------------------------+
//| 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
#property indicator_width1 3
#property indicator_width2 3
//---- input parameters
extern int Equals=5;
extern int nLeftUp=2;
extern int nRightUp=2;
extern int nLeftDown=2;
extern int nRightDown=2;
extern int AllBars = 2400;
//---- 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;
int limit = Bars-cnt-1;
if (limit > AllBars) limit = AllBars;
if (cbars > (limit)) pos=limit;
else pos=cbars+nRightUp;
while (pos>=nRightUp)
{
FractalsUp[pos] =0.0;
FractalsDown[pos]=0.0;
//ôÐRENRË ÂÂLÐO
r=nRightUp; //ddîâld?le ddrâót nnîdîíó ôdrenrër
for (i=1;i<=r;i++)
{
if (High[pos]<=High[pos-i]) break;
}
//lnëc nddrâr ânl ÎE nî i äîëcíî áunü drâíî r+1
if (i==r+1) //FractalsUp[pos]=High[pos];
{
l=nLeftUp; //ddîâld?le ëlâót nnîdîíó ôdrenrër
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)
{
if (iVolume(NULL,0,pos+1) <= iVolume(NULL,0,pos))
{
if (High[pos] - Close[pos] > (Close[pos] - Open[pos])/2) FractalsUp[pos]=High[pos];
}
break;
}
if (e<0) break;
}
}
//ÔÐRENRË ÂÍCÇ
r=nRightDown; //ddîâld?le ddrâót nnîdîíó ôdrenrër
for (i=1;i<=r;i++)
{
if (Low[pos]>=Low[pos-i]) break;
}
if (i==r+1) //FractalsUp[pos]=High[pos];
{
l=nLeftDown; //ddîâld?le ëlâót nnîdîíó ôdrenrër
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)
{
if (iVolume(NULL,0,pos+1) <= iVolume(NULL,0,pos))
{
if (Close[pos] - Low[pos] > (Open[pos] - Close[pos])/2) FractalsDown[pos]=Low[pos];
}
break;
}
if (e<0) break;
}
}
pos--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments