Trying to Code Indicator similar to Fractals

To add comments, please log in or register
Kila Akil
70
Kila Akil  
//+------------------------------------------------------------------+
//|                                        PivotHighLowIndicator.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Blue
#property indicator_color3 Blue

double highs[];
double lows [];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,highs);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0, 159);
   SetIndexBuffer(1,lows);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1, 159);   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 limit = rates_total-prev_calculated;
for(int i=1;limit;i++)
   {
   
if (High[i+1]>High[i]
   && High[i+1]>High[i+2])
   {
   highs[i+1]=High[i+1];
   }
   
if (Low[i+1]<Low[i]
   &&Low[i+1]<Low[i+2])
   lows[i+1]=Low[i+1];
   
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


Above is code for an indicator that works similar to the fractals concept.


1. The indicator plots a shape above any candle who's high is higher than the following and preceding high. If a candle meets these criteria, the high point is identified as a 'first order pivot high'. 


2. I would like to add a secondary function to my code that compares each first order pivot high as follows:

 Plot a shape above any first order pivot high that is higher than the following and preceding first order pivot highs. If a candle meets these criteria, the high point is identified as a 'second order pivot high'.


I have managed to do the first stage, but I can't figure out how to implement the secondary stage. Appreciate any advice.

To add comments, please log in or register