//+------------------------------------------------------------------+
//|                                                   KG Average.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.forexindo.com/forum/showthread.php?t=95&page=9"

#property indicator_chart_window
#property indicator_buffers 3

//---- buffers
double AverageMonth;
double AverageWeek;
double AverageDay;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int i = ObjectsTotal() - 1; i >= 0; i--)
     {
       string label = ObjectName(i);
       if(StringSubstr(label, 0, 10) != "KG Average")
           continue;
       ObjectDelete(label);   
     }   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   int limit=Bars-counted_bars;
   
   AverageMonth= (iHigh(NULL,PERIOD_MN1,1) + iLow(NULL,PERIOD_MN1,1) +
                  iOpen(NULL,PERIOD_MN1,1) + iClose(NULL,PERIOD_MN1,1))/4;
   AverageWeek = (iHigh(NULL,PERIOD_W1,1) + iLow(NULL,PERIOD_W1,1) +
                  iOpen(NULL,PERIOD_W1,1) + iClose(NULL,PERIOD_W1,1))/4;
   AverageDay  = (iHigh(NULL,PERIOD_D1,1) + iLow(NULL,PERIOD_D1,1) +
                  iOpen(NULL,PERIOD_D1,1) + iClose(NULL,PERIOD_D1,1))/4;                                    
      
      
   
   string AVM = "KG Average Month";
   ObjectDelete(AVM);
   ObjectCreate(AVM, OBJ_HLINE, 0, 0, 0);
   ObjectSet(AVM, OBJPROP_PRICE1, AverageMonth);
   ObjectSet(AVM, OBJPROP_COLOR, Magenta);
   
   string AVW = "KG Average Week";
   ObjectDelete(AVW);
   ObjectCreate(AVW, OBJ_HLINE, 0, 0, 0);
   ObjectSet(AVW, OBJPROP_PRICE1, AverageWeek);
   ObjectSet(AVW, OBJPROP_COLOR, Yellow);
   
   string AVD = "KG Average Day";
   ObjectDelete(AVD);
   ObjectCreate(AVD, OBJ_HLINE, 0, 0, 0);
   ObjectSet(AVD, OBJPROP_PRICE1, AverageDay);
   ObjectSet(AVD, OBJPROP_COLOR, DarkOrange);
   
   //----
   return(0);
  }
//+------------------------------------------------------------------+