//+------------------------------------------------------------------+
//|                                                        lm_MMA_1a100.mq4 |
//|                   |
//|                                              |
//+------------------------------------------------------------------+
#property copyright   ""
#property link        ""
#property description "lm_cours_temps_exponentiel"
#property strict
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
//--- input parameter

//--- buffers
double ExtHighBuffer[],ExtLowBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit(void)
  {
   string short_name="lm_cours_temps_exponentiel";
//--- 1 additional buffer used for counting.
   IndicatorBuffers(2);
   IndicatorDigits(Digits);
//--- drawing style
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtHighBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtLowBuffer);   
//--- name for DataWindow and indicator subwindow label

   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
  }
//+------------------------------------------------------------------+
//|                                                      |
//+------------------------------------------------------------------+
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 limite=300,j,per,old_per;
   double haHigh,haLow;
     
   old_per=0;    
   for(int i=1; i<limite; i++)
     { 
       per=MathFloor(MathExp(MathSqrt(i)-1));
       
       j=iHighest(NULL,0,MODE_HIGH,per-old_per,old_per); 
       if(j==-1)
         break;//j=0; 
       haHigh=High[j]; 
       ExtHighBuffer[i]=haHigh;
       
       j=iLowest(NULL,0,MODE_LOW,per-old_per,old_per); 
       if(j==-1)
         break;//j=0; 
       haLow=Low[j]; 
       ExtLowBuffer[i]=haLow; 
       old_per=per;

     }
//---
   return(rates_total);
  }
