//+------------------------------------------------------------------+
//|                                         KG MA modified V 1.1.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 6

extern int Corner=1;
extern int MA_Mode=MODE_SMA;
extern color MA_1MN_Color=Aqua;
extern color MA_1W_Color=Magenta;
extern color MA_3D_Color=White;
extern color MA_1D_Color=Lime;
extern color MA_8H_Color=Yellow;
extern color MA_4H_Color=MediumBlue;
//---- buffers
double MAMonth[];
double MAWeek[];
double MA72H[];
double MA24H[];
double MA8H[];
double MA4H[];
int    PerMonth;
int    PerWeek;
int    Per72H;
int    Per24H;
int    Per8H;
int    Per4H;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,0,2,MA_1MN_Color);
   SetIndexBuffer(0,MAMonth);
   SetIndexLabel(0,"MA 1MN");
   SetIndexStyle(1,DRAW_LINE,0,2,MA_1W_Color);
   SetIndexBuffer(1,MAWeek);
   SetIndexLabel(1,"MA 1W");
   SetIndexStyle(2,DRAW_LINE,0,2,MA_3D_Color);
   SetIndexBuffer(2,MA72H);
   SetIndexLabel(2,"MA 3D");
   SetIndexStyle(3,DRAW_LINE,0,2,MA_1D_Color);
   SetIndexBuffer(3,MA24H);
   SetIndexLabel(3,"MA 1D");
   SetIndexStyle(4,DRAW_LINE,0,2,MA_8H_Color);
   SetIndexBuffer(4,MA8H);
   SetIndexLabel(4,"MA 8H");
   SetIndexStyle(5,DRAW_LINE,0,2,MA_4H_Color);
   SetIndexBuffer(5,MA4H);
   SetIndexLabel(5,"MA 4H");

   
   string label1 = "KG MA 1MN";
   ObjectDelete(label1);
   ObjectCreate( label1, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label1,"1MN MA",8, "Arial Bold", MA_1MN_Color);
   ObjectSet( label1, OBJPROP_CORNER, Corner );
   ObjectSet( label1, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label1, OBJPROP_YDISTANCE, 10 );
   
   string label2 = "KG MA 1W";
   ObjectDelete(label2);
   ObjectCreate( label2, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label2,"1W MA",8, "Arial Bold", MA_1W_Color);
   ObjectSet( label2, OBJPROP_CORNER, Corner );
   ObjectSet( label2, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label2, OBJPROP_YDISTANCE, 20 );
   
   string label3 = "KG MA 3D";
   ObjectDelete(label3);
   ObjectCreate( label3, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label3,"3D MA",8, "Arial Bold", MA_3D_Color);
   ObjectSet( label3, OBJPROP_CORNER, Corner );
   ObjectSet( label3, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label3, OBJPROP_YDISTANCE, 30 );
   
   string label4 = "KG MA 1D";
   ObjectDelete(label4);
   ObjectCreate( label4, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label4,"1D MA",8, "Arial Bold", MA_1D_Color);
   ObjectSet( label4, OBJPROP_CORNER, Corner );
   ObjectSet( label4, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label4, OBJPROP_YDISTANCE, 40 );
     
   string label5 = "KG MA 8H";
   ObjectDelete(label5);
   ObjectCreate( label5, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label5,"8H MA",8, "Arial Bold", MA_8H_Color);
   ObjectSet( label5, OBJPROP_CORNER, Corner );
   ObjectSet( label5, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label5, OBJPROP_YDISTANCE, 50 );
   
   string label6 = "KG MA 4H";
   ObjectDelete(label6);
   ObjectCreate( label6, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label6,"4H MA",8, "Arial Bold", MA_4H_Color);
   ObjectSet( label6, OBJPROP_CORNER, Corner );
   ObjectSet( label6, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label6, OBJPROP_YDISTANCE, 60 );
   

//----
   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;
   PerWeek=7200/ActivePer;
   Per72H=4320/ActivePer;
   Per24H=1440/ActivePer;
   Per8H=480/ActivePer;
   Per4H=240/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,MA_Mode,PRICE_WEIGHTED,i);
      MAWeek[i]=iMA(NULL,0,PerWeek,0,MA_Mode,PRICE_WEIGHTED,i);
      MA72H[i]=iMA(NULL,0,Per72H,0,MA_Mode,PRICE_WEIGHTED,i);
      MA24H[i]=iMA(NULL,0,Per24H,0,MA_Mode,PRICE_WEIGHTED,i);
      MA8H[i]=iMA(NULL,0,Per8H,0,MA_Mode,PRICE_WEIGHTED,i);
      MA4H[i]=iMA(NULL,0,Per4H,0,MA_Mode,PRICE_WEIGHTED,i);
   }
   
   string Sign;
   double MAOpen=iMA(NULL,0,PerMonth,0,MA_Mode,PRICE_WEIGHTED,1);
   double MAClose=iMA(NULL,0,PerMonth,0,MA_Mode,PRICE_WEIGHTED,0);
   color Col;
   
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign1 = "KG MA 1MN Sign";
   ObjectDelete(sign1);
   ObjectCreate(sign1, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign1, Sign ,10, "Wingdings", Col);
   ObjectSet(sign1, OBJPROP_CORNER, Corner );
   ObjectSet(sign1, OBJPROP_XDISTANCE, 63 );
   ObjectSet(sign1, OBJPROP_YDISTANCE, 10 );
   
   MAOpen=iMA(NULL,0,PerWeek,0,MA_Mode,PRICE_WEIGHTED,1);
   MAClose=iMA(NULL,0,PerWeek,0,MA_Mode,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign2 = "KG MA 1W Sign";
   ObjectDelete(sign2);
   ObjectCreate(sign2, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign2, Sign ,10, "Wingdings", Col);
   ObjectSet(sign2, OBJPROP_CORNER, Corner );
   ObjectSet(sign2, OBJPROP_XDISTANCE, 63 );
   ObjectSet(sign2, OBJPROP_YDISTANCE, 20 );

   MAOpen=iMA(NULL,0,Per24H,0,MA_Mode,PRICE_WEIGHTED,1);
   MAClose=iMA(NULL,0,Per24H,0,MA_Mode,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign3 = "KG MA 3D Sign";
   ObjectDelete(sign3);
   ObjectCreate(sign3, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign3, Sign ,10, "Wingdings", Col);
   ObjectSet(sign3, OBJPROP_CORNER, Corner );
   ObjectSet(sign3, OBJPROP_XDISTANCE, 63 );
   ObjectSet(sign3, OBJPROP_YDISTANCE, 30 );

   MAOpen=iMA(NULL,0,Per24H,0,MA_Mode,PRICE_WEIGHTED,1);
   MAClose=iMA(NULL,0,Per24H,0,MA_Mode,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign4 = "KG MA 1D Sign";
   ObjectDelete(sign4);
   ObjectCreate(sign4, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign4, Sign ,10, "Wingdings", Col);
   ObjectSet(sign4, OBJPROP_CORNER, Corner );
   ObjectSet(sign4, OBJPROP_XDISTANCE, 63 );
   ObjectSet(sign4, OBJPROP_YDISTANCE, 40 );
   
   MAOpen=iMA(NULL,0,Per8H,0,MA_Mode,PRICE_WEIGHTED,1);
   MAClose=iMA(NULL,0,Per8H,0,MA_Mode,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign6 = "KG MA 8H Sign";
   ObjectDelete(sign6);
   ObjectCreate(sign6, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign6, Sign ,10, "Wingdings", Col);
   ObjectSet(sign6, OBJPROP_CORNER, Corner );
   ObjectSet(sign6, OBJPROP_XDISTANCE, 63 );
   ObjectSet(sign6, OBJPROP_YDISTANCE, 50 );

    MAOpen=iMA(NULL,0,Per4H,0,MA_Mode,PRICE_WEIGHTED,1);
   MAClose=iMA(NULL,0,Per4H,0,MA_Mode,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign7 = "KG MA 4H Sign";
   ObjectDelete(sign7);
   ObjectCreate(sign7, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign7, Sign ,10, "Wingdings", Col);
   ObjectSet(sign7, OBJPROP_CORNER, Corner );
   ObjectSet(sign7, OBJPROP_XDISTANCE, 63 );
   ObjectSet(sign7, OBJPROP_YDISTANCE, 60 );

   
//----
   return(0);
  }
//+------------------------------------------------------------------+