//+------------------------------------------------------------------+
//|                                                        KG MA.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
//Kang Gun MA

#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 1

extern int Corner=4;
extern color MA_Month_Color=Turquoise;


//---- buffers
double MAMonth[];

int    PerMonth;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,0,2,MA_Month_Color);
   SetIndexBuffer(0,MAMonth);
   SetIndexLabel(0,"MA Month");


   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int i = ObjectsTotal() - 1; i >= 0; i--)
     {
       string label = ObjectName(i);
       if(StringSubstr(label, 0, 5) != "KG MA")
           continue;
       ObjectDelete(label);   
     }   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   int ActivePer=Period();
   PerMonth=28800/ActivePer;


   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   for(int i=0; i<limit; i++)
   { 
      MAMonth[i]=iMA(NULL,0,PerMonth,0,MODE_SMA,PRICE_WEIGHTED,i);

   }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+