FractalLevels

Download script
Author: Copyright � 2008, lotos4u
FractalLevels

This script is a specialized technical analysis tool designed to identify key structural turning points in financial charts—specifically "Fractals." In trading, fractals represent local peaks and valleys that signify where the market sentiment might be shifting between upward and downward trends.

Core Functionality

The logic operates by scanning historical price data to find specific patterns where a candle's high or low point stands out significantly compared to its immediate neighbors. Instead of just showing isolated dots, this script does more: it tracks these levels over time to create "zones" of significance.

How the Logic Works

1. Identifying Peaks and Valleys (Fractals) The script looks at a specific window of candles (defined by the user as "Left Bars" and "Right Bars").

  • Upper Fractals: It searches for a candle where the high price is higher than all surrounding candles within that window. These represent potential areas of Resistance.
  • Lower Fractals: It searches for a candle where the low price is lower than all surrounding candles within that window. These represent potential areas of Support.

2. Tracking Support and Resistance Levels Once a new fractal is identified, the script doesn't simply ignore the previous one. It maintains the "memory" of these levels. If a new peak or valley isn't found immediately, the script carries forward the value of the last known level. This creates a continuous visual representation of the most recent significant support and resistance barriers on your chart.

3. Visual Signaling (Arrows and Breaks) The tool provides different visual cues to help you distinguish between different market actions:

  • Fractal Alerts: It places specific arrows on the chart exactly where a new high or low fractal is confirmed. This tells you that a new structural point has been established.
  • Breakout Detection: One of the most practical features of this script is its ability to monitor "Breaks." It specifically watches for instances where the current market price closes below a previously established support level (a bearish break) or above a resistance level (a bullish break). When this happens, the script triggers a specific signal, notifying you that the market has broken through a significant barrier.

Summary for the User

Essentially, this script automates the "eye work" of identifying where the price is struggling to move higher or lower. It maps out the "ceiling" and "floor" of the market in real-time, marks the exact moment those levels are formed, and alerts you when the price finally crashes through those barriers, providing a clearer picture of trend changes and potential entry/exit opportunities.

Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
FractalLevels
//+------------------------------------------------------------------+
//|                                                    iFractals.mq4 |
//|                                        Copyright © 2008, lotos4u |
//|                                                lotos4u@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, lotos4u"
#property link      "lotos4u@gmail.com"

#property indicator_chart_window
#property indicator_buffers 6

#property indicator_width1 4
#property indicator_width2 4
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 2

#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Gold
#property indicator_color4 Gold
#property indicator_color5 White
#property indicator_color6 White


extern int LeftBars  = 3;
extern int RightBars = 3;


double LineUpBuffer1[];
double LineDownBuffer2[];
double ArrowUpBuffer3[];
double ArrowDownBuffer4[];
double ArrowBreakUpBuffer5[];
double ArrowBreakDownBuffer6[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   SetIndexStyle(0, DRAW_LINE);
   SetIndexArrow(0, 158);
   SetIndexBuffer(0, LineUpBuffer1);
   SetIndexEmptyValue(0, 0.0);
   SetIndexLabel(0, "Ôðàêòàëüíîå ñîïðîòèâëåíèå");
   
   SetIndexStyle(1, DRAW_LINE);
   SetIndexArrow(1, 158);
   SetIndexBuffer(1, LineDownBuffer2);
   SetIndexEmptyValue(1, 0.0);
   SetIndexLabel(1, "Ôðàêòàëüíàÿ ïîääåðæêà");

   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, 119);
   //SetIndexArrow(2, 217);
   SetIndexBuffer(2, ArrowUpBuffer3);
   SetIndexEmptyValue(2, 0.0);
   SetIndexLabel(2, "Ôðàêòàë ÂÅÐÕ");
   
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, 119);
   //SetIndexArrow(3, 218);
   SetIndexBuffer(3, ArrowDownBuffer4);
   SetIndexEmptyValue(3, 0.0);
   SetIndexLabel(3, "Ôðàêòàë ÂÍÈÇ");

   SetIndexStyle(4, DRAW_ARROW);
   SetIndexArrow(4, 119);
   //SetIndexArrow(4, 217);
   SetIndexBuffer(4, ArrowBreakUpBuffer5);
   SetIndexEmptyValue(4, 0.0);
   SetIndexLabel(4, "Ïðîáîé ÂÂÅÐÕ");
   
   SetIndexStyle(5, DRAW_ARROW);
   SetIndexArrow(5, 119);
   //SetIndexArrow(5, 218);
   SetIndexBuffer(5, ArrowBreakDownBuffer6);
   SetIndexEmptyValue(5, 0.0);
   SetIndexLabel(5, "Ïðîáîé ÂÍÈÇ");

   return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit(){return(0);}



//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int counted_bars = IndicatorCounted(), limit;
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;

   for(int i = limit-1; i >= 0; i--)
   {
      LineUpBuffer1[i] = isFractalUp(i, LeftBars, RightBars);
      if(LineUpBuffer1[i] == 0)
         LineUpBuffer1[i] = LineUpBuffer1[i+1];
      else
         ArrowUpBuffer3[i] = LineUpBuffer1[i];
      
      LineDownBuffer2[i] = isFractalDown(i, LeftBars, RightBars);
      if(LineDownBuffer2[i] == 0)
         LineDownBuffer2[i] = LineDownBuffer2[i+1];
      else
         ArrowDownBuffer4[i] = LineDownBuffer2[i];
         
      if(Close[i] < LineDownBuffer2[i] && Close[i+1] >= LineDownBuffer2[i+1])
         ArrowBreakDownBuffer6[i] = Close[i];
   }
   LineUpBuffer1[-1] = LineUpBuffer1[0];
   LineDownBuffer2[-1] = LineDownBuffer2[0];
   return(0);
}





double isFractalUp(int index, int lBars, int rBars)
{
   int left = lBars, right = rBars;
   double max = High[index];
   for(int i = index - right; i <= (index + left); i++)
   {
      if(!(High[i] > 0.0))return(0);
      if(max <= High[i] && i != index)
      {
         if(max < High[i])
            return(0);
         if(MathAbs(i - index) > 1)
            return(0);
      }
   }
   return(max);
}




double isFractalDown(int index, int lBars, int rBars)
{
   int left = lBars, right = rBars;
   double min = Low[index], test;
   for(int i = index - right; i <= (index + left); i++)
   {
      if(!(Low[i] > 0.0))return(0);
      if(min >= Low[i] && i != index)
      {
         if(min > Low[i])
            return(0);

         if(MathAbs(i - index) > 1)
            return(0);
      }

   }
   return(min);
}

Comments