Indicators: Fractal Levels

 

Fractal Levels:

A regular modification of the fractals by B. Williams.

Author: lotos4u

 

Can it be possible to have a MTF version of this indicator?

Dilip

 

Forum on trading, automated trading systems and testing trading strategies

Indicators: i-Fractals-sig

newdigital, 2014.06.03 11:51

Follow The Fractal Tool Toward Better Breakout Entries (based on dailyfx article)

  • Fractals Defined
  • How Traders Can Use Fractals
  • Real-Time Fractal Set-Up
“You can either buy low & sell high or trade with the trend, but you cannot do both.”
-Bill Williams


Many traders spend too much time looking for the best possible entry. However, the entry can be based on any number of technical indicators. For traders who are a fan of price-action, you could do no worse than finding triggers based on a fractal breakout in the direction of the trend.

Fractals Defined



Let’s start with an introduction to fractals. The actually are applied to trading from nature and not the other way around. It may be helpful to know that fractals are effectively a way of looking a sub-sets of large pieces of data to understand what developments are being created in real-time. From a trading / market perspective, fractals are an indicator highlighting the chart’s local highs and lows where the price movement reversed marking a 5-bar high or low. These reversal points are called respectively Fractal highs and lows.

The Hand is a Perfect Fractal



Before we take this natural reoccurrence to the market, you should see how your hand, with fingers pointing up is the perfect up fractal and with your palm facing you, is a perfect down fractal. A Market swing Fractal shows a price extreme in the middle of 5 bars whereas an up fractal has the middle bar with a highest high in the middle with two lower highs on the left and two lower highs on the right. A down fractal will have a low price extreme in the middle bar of a 5-bar sequence with the higher lows on the left and two higher lows on the right.

How Traders Can Use Fractals

Volatility is a key determinant to trading opportunities. One of the common triggers that volatility is in play is when a prior high or low is taken out and a new trend begins. Fractals can be applied to the chart so that you can see when a recent key level has broken which can lead to a price-action trading opportunity.

Fractals revolve around price action highs and lows and can easily pinpoint places for a breakout entry or tight price action based stop. Fractals can be used in a variety of ways. Most commonly, traders will look for a bar to close above a prior up fractal to show an upside breakout or a close below a prior down fractal to signal a downside breakout that is potentially worth trading. Another positive aspect is that when you have a comfortable view of a strong trend in play, you can use fractals as a trailing stop from a prior counter-trend move which made a fractal.

Real-Time Fractal Set-Up

For purpose of review, fractals mark price changes or pivots in the market. For reasons known or unknown, they are reaction points that can help you spot key places to place an entry order or stop. From a trader’s stand-point, they allow you to enter on a confirming view of your analysis vs. a hunch that a market is oversold or overbought and is time to enter like this trade set-up on the Australian Dollar.

A Fractal Based Entry on AUDUSD :


Every trader should embrace the following seven words:
I don’t know what will happen next

This isn’t meant to disregard your analysis but tell a simple fact about trading. Anything can happen in the market place and an infinite number of possibilities are plausible. As a trader, we can develop a strategy with set rules that work with our psychology to give us an edge but it will not predict the future. Therefore, we can use fractals as a trigger to put us into a trade or out of a trade and we may not know if the trade will end in a profit but we can now that we’re only acting on objective evidence.


 

Hi Lotus..

It useful indicator but,,,break up Fractal Sign its not found, i try to compile .. there is picture where breakup fractal not found..can you fix this problem?

Regards

no Breakout Up faractal Sign

 

I try to fix its...  :)..but there is no alarm...MT5 version have an alarm..

//+------------------------------------------------------------------+

//|                                                    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 1
#property indicator_width2 1
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 3
#property indicator_width6 3

#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Purple
#property indicator_color4 Purple
#property indicator_color5 Gray
#property indicator_color6 Gray

extern int LeftBars  = 2;
extern int RightBars = 2;

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, 161);
   //SetIndexArrow(4, 217);
   SetIndexBuffer(4, ArrowBreakUpBuffer5);
   SetIndexEmptyValue(4, 0.0);
   SetIndexLabel(4, "Ïðîáîé ÂÂÅÐÕ");
   
   SetIndexStyle(5, DRAW_ARROW);
   SetIndexArrow(5, 161);
   //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();
   if(counted_bars < 0)  return(-1);
   if(counted_bars > 0)   counted_bars--;
   int limit = Bars - counted_bars;
   if(counted_bars==0) limit-=1+MathMax(LeftBars,RightBars);

   for(int i = limit-1; i >= 0; i--)
   {
      LineUpBuffer1[i] = isFractalUp(i, LeftBars, RightBars,limit);
      if(LineUpBuffer1[i] == 0)
         LineUpBuffer1[i] = LineUpBuffer1[i+1];
      else
         ArrowUpBuffer3[i] = LineUpBuffer1[i];
      
      LineDownBuffer2[i] = isFractalDown(i, LeftBars, RightBars,limit);
      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];
      if(Close[i] > LineUpBuffer1[i] && Close[i+1] <= LineUpBuffer1[i+1])
         ArrowBreakUpBuffer5[i] = Close[i];
   }
   //LineUpBuffer1[-1] = LineUpBuffer1[0];
   //LineDownBuffer2[-1] = LineDownBuffer2[0];
   return(0);
}





double isFractalUp(int index, int lBars, int rBars, int maxind)
{
   int left = lBars, right = rBars;
   double max = High[index]; //Ïðèíèìàåì çà ìàêñèìóì çíà÷åíèå Õàÿ èññëåäóåìîãî áàðà
   for(int i = index - right; i <= (index + left); i++)
   {
     if (i<0 || i>maxind) return(0);
      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 maxind)
{
   int left = lBars, right = rBars;
   double min = Low[index] ;
   for(int i = index - right; i <= (index + left); i++)
   {
      if (i<0 || i>maxind) return(0);
      if(!(Low[i] > 0.0))return(0);
      //if(min >= Low[i] && i != index)
      if(min > Low[i] && i != index)
      {
         if(min > Low[i])
            return(0);

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

   }
   return(min);
}
 

Please use the </> button to insert your above code.


 

Does anybody know why I cannot test it in Strategy Tester?

The levels do not get updated from the beginning date of my test, they simply stay the same all the time.

The same happens when I use this indicator in an EA with iCustom, the buffer values do not change.


Edit:

I added another input variable to the indicator, named MaxBars.

If you do not touch this value, the indicator will work well and display well on the chart and in Strategy Tester.

If you want to use this indicator in an EA, it is best to change the value of MaxBars to something like 200. If you need more history bars, then you may give it a larger number.

The larger it gets, the slower your EA will be in Strategy Tester and in live trading. But, 200 bars back should be enough for most applications.

Files: