Indicators: Fractals - adjustable period and prices

 

Fractals - adjustable period and prices:

Fractals - adjustable period and prices

Fractals - adjustable period and prices

Author: Mladen Rakic

Fractals - adjustable period and prices
Fractals - adjustable period and prices
  • www.mql5.com
One of the "classics" but with a twist - unlike the built in fractals indicator, this one allows you to : adjust the fractals period (the built in fractal indicator is using period 5)chose prices for high and low (might be useful in some cases - in extreme whipsaw market conditions, for example...
 
Looks great, as always! :) Does it have a MQL5 version?
 

Hi, Thank you for posting this. Please tell me what setting you have on the lower 15 chart EURUSD. I am not able to duplicate it with a 5 period on my chart. (The fractal appears after the close of the 2nd bar???) If I set the period to 10 it looks more like what you have on that chart . My understanding is that if I set the period to 10 then the fractal will not appear until the 5th bar closes. Is that correct?


I am looking for a Key reversal mt 4 indicator. Thank you a lot for your insight and help.

 
when do the red and blue occur in real time.  are they placed after the fact so to speak. interesting. 
 

Great work on the indicator.

How do i  get the up or down value from it?

val=iCustom(NULL, 0, "FractalsAdjustable", 9, PRICE_HIGH, 0.2, 0.2, x) is always equal to 2147483647.00

Thanks

 
Very interesting!!! Where can i download?
 
amillax:

Great work on the indicator.

How do i  get the up or down value from it?

val=iCustom(NULL, 0, "FractalsAdjustable", 9, PRICE_HIGH, 0.2, 0.2, x) is always equal to 2147483647.00

Thanks

2147483647 is EMPTY_VALUE

Simply compare if val!=EMPTY_VALUE

 
황인우:
Very interesting!!! Where can i download?

https://www.mql5.com/en/code/25473

Fractals - adjustable period and prices
Fractals - adjustable period and prices
  • www.mql5.com
One of the "classics" but with a twist - unlike the built in fractals indicator, this one allows you to : adjust the fractals period (the built in fractal indicator is using period 5)chose prices for high and low (might be useful in some cases - in extreme whipsaw market conditions, for example...
 

Can anyone convert to mql5?

Thank you.

 
What a bit of brilliance. Would it be possible to connect a fractal lows with a fractal high over "X" bars within a "X" pips limit buy a trendline, like support and resistance? When I try and add code and save candle and price values, the drawings disappear, any help would be appreciated.
 

this indicator in mql5

#property indicator_chart_window
#property indicator_plots 2
#property indicator_type1 DRAW_ARROW
#property indicator_type2 DRAW_ARROW
#property indicator_color1 clrRed
#property indicator_color2 clrBlue
#property indicator_width1 2
#property indicator_width2 2
#property strict

#property indicator_buffers 2

input int                FractalPeriod          = 5;                // Fractal period: 5 for built in fractal
input ENUM_APPLIED_PRICE PriceHigh              = PRICE_HIGH;       // Price high
input ENUM_APPLIED_PRICE PriceLow               = PRICE_LOW;        // Price low
input double             UpperArrowDisplacement = 0.2;              // Upper arrow displacement
input double             LowerArrowDisplacement = 0.2;              // Lower arrow displacement

double v1[], v2[];
int handleMAHigh, handleMALow, handleATR;

//----------------------------------------------------------------------

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   int adjustedFractalPeriod = FractalPeriod;
   if(adjustedFractalPeriod % 2 == 0)
      adjustedFractalPeriod += 1;
   SetIndexBuffer(0, v1);
   SetIndexBuffer(1, v2);
   PlotIndexSetInteger(0, PLOT_ARROW, 159);
   PlotIndexSetInteger(1, PLOT_ARROW, 159);
   PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 2);
   PlotIndexSetInteger(1, PLOT_LINE_WIDTH, 2);
   IndicatorSetString(INDICATOR_SHORTNAME, "Fractals - adjustable price");
   handleMAHigh = iMA(_Symbol, _Period, 1, 0, MODE_SMA, PriceHigh);
   handleMALow = iMA(_Symbol, _Period, 1, 0, MODE_SMA, PriceLow);
   handleATR = iATR(_Symbol, _Period, 20);
   if(handleMAHigh == INVALID_HANDLE || handleMALow == INVALID_HANDLE || handleATR == INVALID_HANDLE)
     {
      Print("Error creating indicators' handles");
      return(INIT_FAILED);
     }
   return(INIT_SUCCEEDED);
  }

//----------------------------------------------------------------------

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int adjustedFractalPeriod = FractalPeriod;
   if(adjustedFractalPeriod % 2 == 0)
      adjustedFractalPeriod += 1;
   int limit = MathMax(prev_calculated, adjustedFractalPeriod);
   int half = adjustedFractalPeriod / 2;
   double maHigh[], maLow[], atr[];
   if(CopyBuffer(handleMAHigh, 0, 0, rates_total, maHigh) < 0 ||
      CopyBuffer(handleMALow, 0, 0, rates_total, maLow) < 0 ||
      CopyBuffer(handleATR, 0, 0, rates_total, atr) < 0)
     {
      Print("Error copying indicator data");
      return(prev_calculated);
     }
   if(ArraySize(maHigh) < rates_total || ArraySize(maLow) < rates_total || ArraySize(atr) < rates_total)
     {
      Print("Array size error");
      return(prev_calculated);
     }
   for(int i = limit; i < rates_total; i++)
     {
      bool found = true;
      double compareTo = maHigh[i];
      for(int k = 1; k <= half; k++)
        {
         if((i + k) < rates_total && maHigh[i + k] > compareTo)
           {
            found = false;
            break;
           }
         if((i - k) >= 0 && maHigh[i - k] >= compareTo)
           {
            found = false;
            break;
           }
        }
      if(found)
         v1[i] = high[i] + atr[i] * UpperArrowDisplacement;
      else
         v1[i] = EMPTY_VALUE;
      found = true;
      compareTo = maLow[i];
      for(int k = 1; k <= half; k++)
        {
         if((i + k) < rates_total && maLow[i + k] < compareTo)
           {
            found = false;
            break;
           }
         if((i - k) >= 0 && maLow[i - k] <= compareTo)
           {
            found = false;
            break;
           }
        }
      if(found)
         v2[i] = low[i] - atr[i] * LowerArrowDisplacement;
      else
         v2[i] = EMPTY_VALUE;
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+