olyakish_fractals_02
Download scriptThis script is designed for the MetaTrader platform to analyze market structure by identifying specific types of "fractals"—which are essentially visual markers for significant highs and lows in price action. Rather than simply displaying every fractal, this tool uses a logic-based filtering system to categorize these points based on two primary factors: Trading Volume and Relative Price Movement (MFI).
Core Logic Overview
The script scans the historical price chart to find specific price "peaks" and "valleys." When it finds one of these points, it doesn't label it immediately. Instead, it looks backward through history to find a previous opposite point (a high looking for a low, or a low looking for a high). It then compares these two points against each other using a percentage-based threshold to determine the "strength" or "type" of the current price movement.
How the Categorization Works
The tool categorizes the detected points into four distinct types based on how much volume was traded and the relative distance of the price move:
- Lime (Strong Fractal): This appears when the current price point is accompanied by a significant increase in trading volume compared to the previous point, while also showing a high relative movement in price. It signifies a strong momentum shift.
- Red (Descending/Weakening Fractal): This is identified when there is a significant increase in trading volume, but the relative price movement is lower than the previous point. This suggests that despite high activity, the price is struggling to maintain its upward strength.
- Blue (Fading Fractal): This occurs when the current price point has much lower trading volume than the previous point, but the relative price move remains high. This indicates a move happening on "thin" liquidity.
- SaddleBrown (Waning Fractal): This is identified when both the trading volume and the relative price movement are lower than the previous point. It marks a significant decrease in both market interest and price action intensity.
Technical Behavior
- Scanning: The script automatically looks through a specific number of past bars (defined by the user) to find these patterns.
- Comparison Engine: For every high or low it finds, it calculates a custom "Money Flow" style value by comparing the price range (High minus Low) against the total volume of the surrounding candles.
- Visual Output: Once the logic determines which category a fractal belongs to, it places a specific arrow on the chart at that exact price level. This allows traders to visually distinguish between high-volume momentum shifts and low-volume exhaustion points at a glance.
//+------------------------------------------------------------------+
//| olyakish_fractals_02 |
//| Copyright © -2007, olyakish |
//| plutonia-dmb#yandex.ru |
//| Äîáàâëåí ïðîöåíò äëÿ îòñåèâàíèÿ ôðàêòàëîâ |
//+------------------------------------------------------------------+
#property copyright "olyakish"
#property link "plutonia-dmb#yandex.ru"
//----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime // Çåëåíûé ôðàêòàë
#property indicator_color2 Red // Ïðèñåäàþùèé
#property indicator_color3 SaddleBrown // Óâÿäàþùèé
#property indicator_color4 Blue // Ôàëüøèâûé
//----
extern int Pips = 15;
extern int ShiftBars = 150;
extern string rem1 = "Ïðîöåíò äëÿ îòñåèâàíèÿ ïî îáúåìó";
extern int Percent = 110;
double ExtLimeBuffer[];
double ExtRedBuffer[];
double ExtSaddleBrownBuffer[];
double ExtBlueBuffer[];
int i, j;
double a_Fractal[2]; // 0- ïîñëåäíèé 1-ïðåäûäóùèé
double a_MFI[2]; // 0- ïîñëåäíèé 1-ïðåäûäóùèé
double a_Volume[2]; // 0- ïîñëåäíèé 1-ïðåäûäóùèé
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0, ExtLimeBuffer);
SetIndexBuffer(1, ExtRedBuffer);
SetIndexBuffer(2, ExtSaddleBrownBuffer);
SetIndexBuffer(3, ExtBlueBuffer);
//----
SetIndexStyle(0, DRAW_ARROW, 0, 1);
SetIndexStyle(1, DRAW_ARROW, 0, 1);
SetIndexStyle(2, DRAW_ARROW, 0, 1);
SetIndexStyle(3, DRAW_ARROW, 0, 1);
//----
SetIndexArrow(0, 177);
SetIndexArrow(1, 177);
SetIndexArrow(2, 177);
SetIndexArrow(3, 177);
//----
SetIndexLabel(0, "Çåëåíûé ôðàêòàë");
SetIndexLabel(1, "Ïðèñåäàþùèé ôðàêòàë");
SetIndexLabel(2, "Óâÿäàþùèé ôðàêòàë");
SetIndexLabel(3, "Ôàëüøèâûé ôðàêòàë");
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int n = 3;
while(ExtLimeBuffer[n] != NULL || ExtRedBuffer[n] != NULL ||
ExtSaddleBrownBuffer[n] != NULL || ExtBlueBuffer[n] != NULL)
{
if(n > ShiftBars)
{
n = ShiftBars;
break;
}
n++;
}
for(int i = n + 20; i >= 3; i--)
{
//-- âåðõíèå ôðàêòàëû
ArrayInitialize(a_Fractal, 0);
ArrayInitialize(a_MFI, 0);
ArrayInitialize(a_Volume, 0);
// íà i áàðå åñòü ôðàêòàë ââåðõ
if(iFractals(NULL, 0, MODE_UPPER, i) != 0)
{
Comment("olyakish_fractals_02\n",i, ", ", j);
Sleep(1000);
// öåíà íà ôðàêòàëå
a_Fractal[0] = iFractals(NULL, 0, MODE_UPPER, i);
// îáúåì
a_Volume[0] = Volume[i] + Volume[i+1] + Volume[i+2] +
Volume[i-1] + Volume[i-2];
// MFI
a_MFI[0] = (High[i] - Low[i] + High[i-1] - Low[i-1] +
High[i-2] - Low[i-2] + High[i+1] - Low[i+1] +
High[i+2] - Low[i+2]) / a_Volume[0];
// ïîøëè èñêàòü ôðàêòàë íà âíèç ïî èñòîðèè
j = i + 1;
while(a_Fractal[1] == 0)
{
if(iFractals(NULL, 0, MODE_UPPER, j) != 0)
break;
// Íàøëè ôðàêòàë âíèç
if(iFractals(NULL, 0, MODE_LOWER, j) != 0)
{
a_Fractal[1] = iFractals(NULL, 0, MODE_LOWER, j);
a_Volume[1] = Volume[j+2] + Volume[j+1] + Volume[j] +
Volume[j-1] + Volume[j-2];
a_MFI[1] = (High[j+1] - Low[j+1] + High[j+2] -
Low[j+2] + High[j] - Low[j] + High[j-1] -
Low[j-1] + High[j-2] - Low[j-2]) / a_Volume[1];
// èìååì ïðèñåäàþùèé ôðàêòàë (MFI - îáúåì +)
if(a_Volume[0] > a_Volume[1]*Percent / 100 &&
a_MFI[0] < a_MFI[1])
{
ExtRedBuffer[i] = High[i]; // + Pips*Point;
break;
}
// èìååì çåëåíûé ôðàêòàë (MFI + îáúåì +)
if(a_Volume[0] > a_Volume[1]*Percent / 100 &&
a_MFI[0] > a_MFI[1])
{
ExtLimeBuffer[i] = High[i]; // + Pips*Point;
break;
}
// èìååì ôàëüøèâûé ôðàêòàë (MFI + îáúåì -)
if(a_Volume[0]*Percent / 100 < a_Volume[1] &&
a_MFI[0] > a_MFI[1])
{
ExtBlueBuffer[i] = High[i]; // + Pips*Point;
break;
}
// èìååì óâÿäàþùèé ôðàêòàë (MFI - îáúåì -)
if(a_Volume[0]*Percent / 100 < a_Volume[1] &&
a_MFI[0] < a_MFI[1])
{
ExtSaddleBrownBuffer[i] = High[i]; // + Pips*Point;
break;
}
}
j++;
}
}
//--- íèæíèå ôðàêòàëû
ArrayInitialize(a_Fractal, 0);
ArrayInitialize(a_MFI, 0);
ArrayInitialize(a_Volume, 0);
// íà i áàðå åñòü ôðàêòàë âíèç
if(iFractals(NULL, 0, MODE_LOWER, i) != 0)
{
// öåíà íà ôðàêòàëå
a_Fractal[0] = iFractals(NULL, 0, MODE_LOWER, i);
// îáúåì
a_Volume[0] = Volume[i] + Volume[i+1] + Volume[i+2] +
Volume[i-1] + Volume[i-2];
// MFI
a_MFI[0] = (High[i] - Low[i] + High[i-1] - Low[i-1] +
High[i-2] - Low[i-2] + High[i+1] - Low[i+1] +
High[i+2] - Low[i+2]) / a_Volume[0];
// ïîøëè èñêàòü ôðàêòàë íà ââåðõ ïî èñòîðèè
j = i + 1;
while(a_Fractal[1] == 0)
{
if(iFractals(NULL, 0, MODE_LOWER, j) != 0)
{
break;
}
// Íàøëè ôðàêòàë ââåðõ
if(iFractals(NULL, 0, MODE_UPPER, j) != 0)
{
a_Fractal[1] = iFractals(NULL, 0, MODE_UPPER, j);
a_Volume[1] = Volume[j+2] + Volume[j+1] + Volume[j] +
Volume[j-1] + Volume[j-2];
a_MFI[1] = (High[j+1] - Low[j+1] + High[j+2] -
Low[j+2] + High[j] - Low[j] + High[j-1] -
Low[j-1] + High[j-2] - Low[j-2]) / a_Volume[1];
// èìååì ïðèñåäàþùèé ôðàêòàë (MFI - îáúåì +)
if(a_Volume[0] > a_Volume[1]*Percent / 100 &&
a_MFI[0] < a_MFI[1])
{
ExtRedBuffer[i] = Low[i]; // - Pips*Point;
break;
}
// èìååì çåëåíûé ôðàêòàë (MFI + îáúåì +)
if(a_Volume[0] > a_Volume[1]*Percent / 100 &&
a_MFI[0] > a_MFI[1])
{
ExtLimeBuffer[i] = Low[i]; // - Pips*Point;
break;
}
// èìååì ôàëüøèâûé ôðàêòàë (MFI + îáúåì -)
if(a_Volume[0]*Percent / 100 < a_Volume[1] &&
a_MFI[0] > a_MFI[1])
{
ExtBlueBuffer[i] = Low[i]; // - Pips*Point;
break;
}
// èìååì óâÿäàþùèé ôðàêòàë (MFI - îáúåì -)
if(a_Volume[0]*Percent / 100 < a_Volume[1] &&
a_MFI[0] < a_MFI[1])
{
ExtSaddleBrownBuffer[i] = Low[i]; // - Pips*Point;
break;
}
}
j++;
}
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments