Pure Fractals

Author: Copyright © 2019, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Pure Fractals
ÿþ//+------------------------------------------------------------------+

//|                                                Pure Fractals.mq5 |

//|                              Copyright © 2019, Vladimir Karputov |

//|                                           http://wmua.ru/slesar/ |

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

#property copyright "Copyright © 2019, Vladimir Karputov"

#property link      "http://wmua.ru/slesar/"

#property version   "1.001"

//---- indicator settings

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

#property indicator_type1   DRAW_ARROW

#property indicator_type2   DRAW_ARROW

#property indicator_color1  clrGold

#property indicator_color2  clrGold

#property indicator_label1  "Pure Fractal Up"

#property indicator_label2  "Pure Fractal Down"

//---- indicator buffers

double m_UpperBuffer[];

double m_LowerBuffer[];

//--- 10 pixels upper from high price

int    m_ArrowShift=-20;

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

//| Custom indicator initialization function                         |

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

void OnInit()

  {

//---- indicator buffers mapping

   SetIndexBuffer(0,m_UpperBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,m_LowerBuffer,INDICATOR_DATA);

   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);

//---- sets first bar from what index will be drawn

   PlotIndexSetInteger(0,PLOT_ARROW,233);

   PlotIndexSetInteger(1,PLOT_ARROW,234);

//---- arrow shifts when drawing

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,m_ArrowShift);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-m_ArrowShift);

//---- sets drawing line empty value--

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- initialization done

  }

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

//|  Accelerator/Decelerator Oscillator                              |

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

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 i,limit;

//---

   if(rates_total<5)

      return(0);

//---

   if(prev_calculated<7)

     {

      limit=2;

      //--- clean up arrays

      ArrayInitialize(m_UpperBuffer,EMPTY_VALUE);

      ArrayInitialize(m_LowerBuffer,EMPTY_VALUE);

     }

   else

      limit=rates_total-5;



   for(i=limit; i<rates_total-3 && !IsStopped(); i++)

     {

      //---- Upper Fractal

      if((high[i]>high[i+1] && high[i+1]>high[i+2] &&

          high[i]>high[i-1] && high[i-1]>high[i-2]) &&

         (low[i+1]>low[i+2] &&

          low[i-1]>low[i-2]))

        {

         m_UpperBuffer[i]=high[i];

        }

      else

         m_UpperBuffer[i]=EMPTY_VALUE;

      //---- Lower Fractal

      if((low[i]<low[i+1] && low[i+1]<low[i+2] &&

          low[i]<low[i-1] && low[i-1]<low[i-2]) &&

         (high[i+1]<high[i+2] &&

          high[i-1]<high[i-2]))

        {

         m_LowerBuffer[i]=low[i];

        }

      else

         m_LowerBuffer[i]=EMPTY_VALUE;

     }

//--- OnCalculate done. Return new prev_calculated.

   return(rates_total);

  }

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---