//+------------------------------------------------------------------+
//|                                                      maxmove.mq4 |
//|                                                              EKS |
//|                                           -----------------.com |
//+------------------------------------------------------------------+
#property copyright "EKS"
#property link      "1101"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers    1
#property indicator_color1     clrRed
#property indicator_width1 2
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
double max_m[];
extern int candles = 500;
extern double stopd = 20;
//bool creteria[];

int OnInit()
  {
//--- indicator buffers mapping
 //  IndicatorBuffers(2);
   IndicatorShortName("max_movement");
   SetIndexBuffer(0,max_m);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   
   
//---
   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[])
  {
//---
   stopd = stopd *0.0001;
   int i,k;
   double stop;
   for (i=0; i<candles ;i++)
   {  
      
      stop = Close[i]+ stopd;
      for (k=0; k<i ;k++)
      {
         // this data is for max movement in bearish direction for every candle that matches crtiteria
         if(max_m[i] >(Low[k]-Close[i])&&(High[k]<stop))//another comparison needed - criteria[i]==False
         
         {
            max_m[i] = (Low[k]-Close[i])*10000;
            }
         else if (High[k]>stop)
         {
         // then criteria[i] should be = True
         }
           
      }
      
   }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
