Fractals+Signal+diapazon
Download scriptThis script is designed as a technical analysis tool for MetaTrader 4, specifically created to identify "Fractals"—which are specific patterns in price action that represent local highs and lows. Unlike standard fractal indicators that only look at a fixed number of candles, this logic is more robust because it dynamically identifies these peaks and valleys across various different configurations.
Core Logic Overview
The primary goal of the script is to scan the historical price chart and pinpoint significant turning points. It does this by analyzing clusters of price bars to see if a specific "peak" or "valley" stands out significantly compared to the bars surrounding it.
Instead of looking for just one type of formation, the script evaluates five different structural variations (ranging from 5-bar to 9-bar patterns). This allows the tool to recognize a variety of market movements, including:
- Simple Peaks/Valleys: Where a single candle is higher or lower than its immediate neighbors.
- Plateaus: Where multiple consecutive candles reach the same high or low price before the trend reverses.
How it Functions on the Chart
The logic performs three main tasks simultaneously when it identifies a fractal:
-
Fractal Identification (Visual Markers): It places specific markers on the chart to highlight where these peaks and valleys occur. These are categorized into "Up Fractals" (high points) and "Down Fractals" (low points), helping traders see the structural boundaries of the market.
-
Signal Generation: The script generates specific signals based on these findings. When a high point is confirmed, it places a signal at a distance below the current price; when a low point is confirmed, it places a signal above the price. These act as immediate visual cues for potential trend changes or exhaustion points.
-
Range Mapping (Diapazon): The script tracks "Ranges." It captures the opening price and the fractal peak/valley price to create a visual bridge or section on the chart. This helps in identifying the specific price zone that was covered during that movement, allowing traders to see the relationship between where a move started and where it peaked.
Summary for the User
Essentially, this script acts as an advanced "map" of market highs and lows. It ignores minor noise by checking for various structural patterns (5 through 9 bars wide), ensuring that only significant turning points are marked. By combining fractal identification, visual signals, and range mapping, it provides a comprehensive view of the price architecture, making it easier to see where the market has historically "turned" and how large those movements were.
//+------------------------------------------------------------------+
//| Fractals5+Signal.mq4 |
//+------------------------------------------------------------------+
#property copyright "© Maloma"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 OrangeRed
#property indicator_color4 CornflowerBlue
#property indicator_color5 Magenta
#property indicator_color6 Teal
//---- input parameters
//---- buffers
double dUpFractalsBuffer[];
double dDownFractalsBuffer[];
double dUpSignalBuffer[];
double dDownSignalBuffer[];
double UpDiapazonBuffer[];
double DnDiapazonBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator buffers mapping
SetIndexBuffer(0,dUpFractalsBuffer);
SetIndexBuffer(1,dDownFractalsBuffer);
SetIndexBuffer(2,dUpSignalBuffer);
SetIndexBuffer(3,dDownSignalBuffer);
SetIndexBuffer(4,UpDiapazonBuffer);
SetIndexBuffer(5,DnDiapazonBuffer);
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW,EMPTY,2);
SetIndexArrow(0,119);
SetIndexStyle(1,DRAW_ARROW,EMPTY,2);
SetIndexArrow(1,119);
SetIndexStyle(2,DRAW_ARROW,EMPTY,2);
SetIndexArrow(2,241);
SetIndexStyle(3,DRAW_ARROW,EMPTY,2);
SetIndexArrow(3,242);
SetIndexStyle(4,DRAW_SECTION,EMPTY,2);
SetIndexStyle(5,DRAW_SECTION,EMPTY,2);
//----
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
SetIndexEmptyValue(2,0.0);
SetIndexEmptyValue(3,0.0);
SetIndexEmptyValue(4,0.0);
SetIndexEmptyValue(5,0.0);
//---- name for DataWindow
SetIndexLabel(0,"Fractal Up");
SetIndexLabel(1,"Fractal Down");
SetIndexLabel(2,"Signal Up");
SetIndexLabel(3,"Signal Down");
SetIndexLabel(4,"Diapazon Up");
SetIndexLabel(5,"Diapazon Down");
//---- initialization done
IndicatorShortName("F5S");
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,nCountedBars;
nCountedBars=IndicatorCounted();
//---- check for possible errors
if(nCountedBars<0 || Bars<5) return(-1);
//----
i=Bars-nCountedBars-1;
while(i>=0)
{
//----Up and Down Fractals
//----5 bars Fractal
if(High[i+3]>High[i+3+1] && High[i+3]>High[i+3+2] && High[i+3]>High[i+3-1] && High[i+3]>High[i+3-2])
{
dUpSignalBuffer[i]= Low[i]-3*Point;
dUpFractalsBuffer[i+3]= High[i+3];
UpDiapazonBuffer[i]= Open[i];
UpDiapazonBuffer[i+3]= High[i+3];
}
if(Low[i+3]<Low[i+3+1] && Low[i+3]<Low[i+3+2] && Low[i+3]<Low[i+3-1] && Low[i+3]<Low[i+3-2])
{
dDownSignalBuffer[i]= High[i]+3*Point;
dDownFractalsBuffer[i+3]= Low[i+3];
DnDiapazonBuffer[i]= Open[i];
DnDiapazonBuffer[i+3]= Low[i+3];
i--;
continue;
}
//----6 bars Fractal
if(High[i+3]==High[i+3+1] && High[i+3]>High[i+3+2] && High[i+3]>High[i+3+3] && High[i+3]>High[i+3-1] && High[i+3]>High[i+3-2])
{
dUpSignalBuffer[i]= Low[i]-3*Point;
dUpFractalsBuffer[i+3]= High[i+3];
UpDiapazonBuffer[i]= Open[i];
UpDiapazonBuffer[i+3]= High[i+3];
}
if(Low[i+3]==Low[i+3+1] && Low[i+3]<Low[i+3+2] && Low[i+3]<Low[i+3+3] && Low[i+3]<Low[i+3-1] && Low[i+3]<Low[i+3-2])
{
dDownSignalBuffer[i]= High[i]+3*Point;
dDownFractalsBuffer[i+3]= Low[i+3];
DnDiapazonBuffer[i]= Open[i];
DnDiapazonBuffer[i+3]= Low[i+3];
i--;
continue;
}
//----7 bars Fractal
if(High[i+3]>=High[i+3+1] && High[i+3]==High[i+3+2] && High[i+3]>High[i+3+3] && High[i+3]>High[i+3+4] && High[i+3]>High[i+3-1] &&
High[i+3]>High[i+3-2])
{
dUpSignalBuffer[i]= Low[i]-3*Point;
dUpFractalsBuffer[i+3]= High[i+3];
UpDiapazonBuffer[i]= Open[i];
UpDiapazonBuffer[i+3]= High[i+3];
}
if(Low[i+3]<=Low[i+3+1] && Low[i+3]==Low[i+3+2] && Low[i+3]<Low[i+3+3] && Low[i+3]<Low[i+3+4] && Low[i+3]<Low[i+3-1] &&
Low[i+3]<Low[i+3-2])
{
dDownSignalBuffer[i]= High[i]+3*Point;
dDownFractalsBuffer[i+3]= Low[i+3];
DnDiapazonBuffer[i]= Open[i];
DnDiapazonBuffer[i+3]= Low[i+3];
i--;
continue;
}
//----8 bars Fractal
if(High[i+3]>=High[i+3+1] && High[i+3]==High[i+3+2] && High[i+3]==High[i+3+3] && High[i+3]>High[i+3+4] && High[i+3]>High[i+3+5] &&
High[i+3]>High[i+3-1] && High[i+3]>High[i+3-2])
{
dUpSignalBuffer[i]= Low[i]-3*Point;
dUpFractalsBuffer[i+3]= High[i+3];
UpDiapazonBuffer[i]= Open[i];
UpDiapazonBuffer[i+3]= High[i+3];
}
if(Low[i+3]<=Low[i+3+1] && Low[i+3]==Low[i+3+2] && Low[i+3]==Low[i+3+3] && Low[i+3]<Low[i+3+4] && Low[i+3]<Low[i+3+5] &&
Low[i+3]<Low[i+3-1] && Low[i+3]<Low[i+3-2])
{
dDownSignalBuffer[i]= High[i]+3*Point;
dDownFractalsBuffer[i+3]= Low[i+3];
DnDiapazonBuffer[i]= Open[i];
DnDiapazonBuffer[i+3]= Low[i+3];
i--;
continue;
}
//----9 bars Fractal
if(High[i+3]>=High[i+3+1] && High[i+3]==High[i+3+2] && High[i+3]>=High[i+3+3] && High[i+3]==High[i+3+4] && High[i+3]>High[i+3+5] &&
High[i+3]>High[i+3+6] && High[i+3]>High[i+3-1] && High[i+3]>High[i+3-2])
{
dUpSignalBuffer[i]= Low[i]-3*Point;
dUpFractalsBuffer[i+3]= High[i+3];
UpDiapazonBuffer[i]= Open[i];
UpDiapazonBuffer[i+3]= High[i+3];
}
if(Low[i+3]<=Low[i+3+1] && Low[i+3]==Low[i+3+2] && Low[i+3]<=Low[i+3+3] && Low[i+3]==Low[i+3+4] && Low[i+3]<Low[i+3+5] &&
Low[i+3]<Low[i+3+6] && Low[i+3]<Low[i+3-1] && Low[i+3]<Low[i+3-2])
{
dDownSignalBuffer[i]= High[i]+3*Point;
dDownFractalsBuffer[i+3]= Low[i+3];
DnDiapazonBuffer[i]= Open[i];
DnDiapazonBuffer[i+3]= Low[i+3];
i--;
continue;
}
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments