FractalBestAll

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
FractalBestAll

This script is designed as a visual tool for trading platforms to help identify specific structural turning points in price action. It automatically scans historical market data to locate "Fractals"—which are essentially peaks and valleys that represent temporary shifts in momentum.

How the Logic Works

The core functionality of the script relies on a five-bar comparison method. Instead of simply looking at a single high or low point, the tool evaluates a specific candle by comparing it to its immediate neighbors on both sides.

Identifying Upper Fractals (Resistance Points) To mark a peak, the script looks for a candle where the highest price is greater than the highs of the two candles preceding it and the two candles following it. When this condition is met, the tool places a visual marker (a red arrow) slightly below that specific peak. This helps traders identify areas where the price has recently pushed upward before retreating.

Identifying Lower Fractals (Support Points) Conversely, to mark a valley, the script looks for a candle where the lowest price is lower than the lows of the two candles preceding it and the two candles following it. When this occurs, the tool places a visual marker (a blue arrow) slightly above that specific low point. This helps traders identify areas where the price has recently dropped before potentially bouncing back up.

Visual Representation on the Chart

The script handles all the heavy lifting of scanning these patterns across the entire history of the chart. It creates two distinct visual layers:

  • Red Arrows: Automatically appear at significant "high" points to highlight potential overhead resistance.
  • Blue Arrows: Automatically appear at significant "low" points to highlight potential underlying support.

By automating this detection, the tool allows a user to see at a glance where the market has established structural "turning points" without having to manually measure every candle's price movement.

Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
FractalBestAll
//+------------------------------------------------------------------+
//|                                                     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,241);
    SetIndexStyle(1,DRAW_ARROW);
    SetIndexArrow(1,242);
//----
    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;
    double up,dw,nul=0.0001;
    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
//----5 bars Fractal
       if(High[i+3]>High[i+4] && High[i+3]>High[i+5] && High[i+3]>High[i+2] && High[i+3]>High[i+1])
        { 
         up=Low[i]-3*Point;
         dUpFractalsBuffer[i]=up;
        }
       else {dUpFractalsBuffer[i]=nul;} 
       if(Low[i+3]<Low[i+4] && Low[i+3]<Low[i+5] && Low[i+3]<Low[i+2] && Low[i+3]<Low[i+1])
        { 
         dw=High[i]+3*Point;
         dDownFractalsBuffer[i]=dw;
           i--;
           continue;
         }
        else {dDownFractalsBuffer[i]=nul;}                                    
      i--;
     }

//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments