Fractals9
Download scriptThis script is designed as a visual tool for financial market analysis, specifically used to identify significant turning points in price action. It automatically scans historical price data to pinpoint "Fractals," which are specific patterns that represent local highs and lows within a given timeframe.
Core Logic and Functionality
The primary goal of this tool is to help traders identify structural peaks and valleys without having to manually scan every candle on a chart. It accomplishes this through the following logic:
- Pattern Recognition: The script looks for specific price formations where a central "peak" or "valley" is surrounded by lower (or higher) neighboring values. It evaluates the relationship between a current price point and several surrounding bars to confirm if it qualifies as a structural extreme.
- Upper Fractals (Resistance): The logic identifies high points in the market. For a point to be marked as an "Up Fractal," the script checks if the price at that moment is higher than the candles immediately preceding and following it. This helps traders visualize potential resistance levels or areas where selling pressure may have outweighed buying pressure.
- Lower Fractals (Support): Conversely, the script identifies low points in the market. It looks for instances where a price point is lower than its neighbors, marking a "Down Fractal." These points are useful for identifying potential support levels or zones where buying interest might have overtaken selling pressure.
- Visual Output: Once the script identifies these specific structural points, it automatically places colored arrows on the chart (Red for upper peaks and Blue for lower valleys). This allows for immediate visual confirmation of the market's geometry.
Practical Application
By distilling complex price movements into these simple visual markers, the tool assists in:
- Trend Identification: Recognizing the sequence of highs and lows to see the overall direction of the market.
- Support and Resistance Mapping: Identifying key zones where the price has historically reversed or consolidated.
- Price Action Analysis: Filtering out "market noise" to focus on significant structural shifts in price movement.
//+------------------------------------------------------------------+
//| Fractals.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters
//---- buffers
double dUpFractalsBuffer[];
double dDownFractalsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator buffers mapping
SetIndexBuffer(0,dUpFractalsBuffer);
SetIndexBuffer(1,dDownFractalsBuffer);
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,119);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,119);
//----
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
//---- name for DataWindow
SetIndexLabel(0,"Fractal Up");
SetIndexLabel(1,"Fractal Down");
//---- initialization done
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) return(-1);
//---- last counted bar will be recounted
if(nCountedBars<=2)
i=Bars-nCountedBars-3;
if(nCountedBars>2)
{
nCountedBars--;
i=Bars-nCountedBars-1;
}
while(i>=2)
{
//----Up and Down Fractals
//----9 bars Fractal
if((Bars-i-1)>=6)
{
if(High[i]>=High[i+1] && High[i]==High[i+2] && High[i]>=High[i+3] && High[i]==High[i+4] && High[i]>High[i+5] &&
High[i]>High[i+6] && High[i]>High[i-1] && High[i]>High[i-2])
dUpFractalsBuffer[i]= High[i];
if(Low[i]<=Low[i+1] && Low[i]==Low[i+2] && Low[i]<=Low[i+3] && Low[i]==Low[i+4] && Low[i]<Low[i+5] &&
Low[i]<Low[i+6] && Low[i]<Low[i-1] && Low[i]<Low[i-2])
{
dDownFractalsBuffer[i]= Low[i];
i--;
continue;
}
}
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments