//+------------------------------------------------------------------+
//|                                           SINGLE_Buffer_Ergo.mq4 |
//|                                                Copyright 05_2015 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Yellow

#property indicator_level1 0

extern int TimeFrame  =0;
extern int TimeFrame1 =0;
extern int CountBars  =500;
extern int x_prd      =0;
//---- buffers
double Multi_Indic[];

string short_name;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init() {

//---- name for DataWindow and indicator subwindow label 
    short_name = "SINGLE_Buffer_Ergo("+TimeFrame+")";
    IndicatorShortName(short_name);
    IndicatorBuffers(1);
    SetIndexBuffer(0,Multi_Indic);   
    SetIndexStyle(0,DRAW_LINE,0,1);
   
//----
   return (0);
}
int deinit() {
   return (0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   if (CountBars>=Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars);


   int i, counted_bars=IndicatorCounted();

   double t_prd;
//----
   if(Bars<=x_prd) return(0);
//---- initial zero
   if(counted_bars<x_prd)
   {
      for(i=1;i<=x_prd;i++) Multi_Indic[CountBars-i]=0.0;  
     
   }
//----
   i=CountBars-x_prd-1;
   
   t_prd=x_prd/2+1;

   while(i>=0)
   
     {
     Multi_Indic[i]=(iCustom(NULL, 0, "Ergo", 4, i))/1000 ; 
        
     i--;  
     
     }
     
   return(0);
  }
  
//+------------------------------------------------------------------+  