//+------------------------------------------------------------------+
//|                                                 KG MA V 1.3b.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 8

extern int Corner=1;
extern int MA_Mode=MODE_SMA;
extern color MA_Month_Color=Beige;
extern color MA_Week_Color=Beige;
extern color MA_Day_Color=Beige;
extern color MA_8H_Color=Beige;
extern color MA_4H_Color=Beige;
extern color MA_1H_Color=Beige;
extern color MA_30M_Color=Beige;
extern color MA_15M_Color=Beige;
//---- buffers
double MAMonth[];
double MAWeek[];
double MA24H[];
double MA8H[];
double MA4H[];
double MA1H[];
double MA30M[];
double MA15M[];
int    PerMonth;
int    PerWeek;
int    Per24H;
int    Per8H;
int    Per4H;
int    Per1H;
int    Per30M;
int    Per15M;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
 
   
   string label1 = "KG MA Month";
   ObjectDelete(label1);
   ObjectCreate( label1, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label1,"Monthly MA",8, "Arial Bold", MA_Month_Color);
   ObjectSet( label1, OBJPROP_CORNER, Corner );
   ObjectSet( label1, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label1, OBJPROP_YDISTANCE, 10 );
   
   string label2 = "KG MA Week";
   ObjectDelete(label2);
   ObjectCreate( label2, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label2,"Weekly MA",8, "Arial Bold", MA_Week_Color);
   ObjectSet( label2, OBJPROP_CORNER, Corner );
   ObjectSet( label2, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label2, OBJPROP_YDISTANCE, 20 );
   
   string label3 = "KG MA Day";
   ObjectDelete(label3);
   ObjectCreate( label3, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label3,"Daily MA",8, "Arial Bold", MA_Day_Color);
   ObjectSet( label3, OBJPROP_CORNER, Corner );
   ObjectSet( label3, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label3, OBJPROP_YDISTANCE, 30 );
   
   string label4 = "KG MA 8H";
   ObjectDelete(label4);
   ObjectCreate( label4, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label4,"8H MA",8, "Arial Bold", MA_8H_Color);
   ObjectSet( label4, OBJPROP_CORNER, Corner );
   ObjectSet( label4, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label4, OBJPROP_YDISTANCE, 40 );
   
   string label5 = "KG MA 4H";
   ObjectDelete(label5);
   ObjectCreate( label5, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label5,"4H MA",8, "Arial Bold", MA_4H_Color);
   ObjectSet( label5, OBJPROP_CORNER, Corner );
   ObjectSet( label5, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label5, OBJPROP_YDISTANCE, 50 );
   
   string label6 = "KG MA 1H";
   ObjectDelete(label6);
   ObjectCreate( label6, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label6,"1H MA",8, "Arial Bold", MA_1H_Color);
   ObjectSet( label6, OBJPROP_CORNER, Corner );
   ObjectSet( label6, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label6, OBJPROP_YDISTANCE, 60 );

   string label7 = "KG MA 30M";
   ObjectDelete(label7);
   ObjectCreate( label7, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label7,"30M MA",8, "Arial Bold", MA_30M_Color);
   ObjectSet( label7, OBJPROP_CORNER, Corner );
   ObjectSet( label7, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label7, OBJPROP_YDISTANCE, 70 );
   
   string label8 = "KG MA 15M";
   ObjectDelete(label8);
   ObjectCreate( label8, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label8,"15M MA",8, "Arial Bold", MA_15M_Color);
   ObjectSet( label8, OBJPROP_CORNER, Corner );
   ObjectSet( label8, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label8, OBJPROP_YDISTANCE, 80 );

   
   string label9 = "Momentum";
   ObjectDelete(label9);
   ObjectCreate( label9, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label9,"MOM",7, "Arial Bold", MA_15M_Color);
   ObjectSet( label9, OBJPROP_CORNER, Corner );
   ObjectSet( label9, OBJPROP_XDISTANCE, 78 );
   ObjectSet( label9, OBJPROP_YDISTANCE, 100 );

//----
   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;
   Per24H=1440/ActivePer;
   Per8H=480/ActivePer;
   Per4H=240/ActivePer;
   Per1H=60/ActivePer;
   Per30M=30/ActivePer;
   Per15M=15/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);
      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);
      MA1H[i]=iMA(NULL,0,Per1H,0,MA_Mode,PRICE_WEIGHTED,i);
      MA30M[i]=iMA(NULL,0,Per30M,0,MA_Mode,PRICE_WEIGHTED,i);
      MA15M[i]=iMA(NULL,0,Per15M,0,MA_Mode,PRICE_WEIGHTED,i);
   }
   
   string Sign;
   color Col;
   
   double MAOpen=iMA(NULL,0,PerMonth,0,MA_Mode,PRICE_WEIGHTED,1);
   double MAClose=iMA(NULL,0,PerMonth,0,MA_Mode,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign1 = "KG MA Month 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=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign2 = "KG MA Week 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=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign3 = "KG MA Day 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,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=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign4 = "KG MA 8H 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,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=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign5 = "KG MA 4H Sign";
   ObjectDelete(sign5);
   ObjectCreate(sign5, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign5, Sign ,10, "Wingdings", Col);
   ObjectSet(sign5, OBJPROP_CORNER, Corner );
   ObjectSet(sign5, OBJPROP_XDISTANCE, 63 );
   ObjectSet(sign5, OBJPROP_YDISTANCE, 50 );

   MAOpen=iMA(NULL,0,Per1H,0,MA_Mode,PRICE_WEIGHTED,1);
   MAClose=iMA(NULL,0,Per1H,0,MA_Mode,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign6 = "KG MA 1H 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, 60 );

   MAOpen=iMA(NULL,0,Per30M,0,MA_Mode,PRICE_WEIGHTED,1);
   MAClose=iMA(NULL,0,Per30M,0,MA_Mode,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign7 = "KG MA 30M 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, 70 );
   
   MAOpen=iMA(NULL,0,Per15M,0,MA_Mode,PRICE_WEIGHTED,1);
   MAClose=iMA(NULL,0,Per15M,0,MA_Mode,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign8 = "KG MA 15M Sign";
   ObjectDelete(sign8);
   ObjectCreate(sign8, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign8, Sign ,10, "Wingdings", Col);
   ObjectSet(sign8, OBJPROP_CORNER, Corner );
   ObjectSet(sign8, OBJPROP_XDISTANCE, 63 );
   ObjectSet(sign8, OBJPROP_YDISTANCE, 80 );
   
   // Momentum column
   
   MAOpen=iMomentum(NULL,10080,4,PRICE_WEIGHTED,1);
   MAClose=iMomentum(NULL,10080,4,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign19 = "Momentum Month Sign";
   ObjectDelete(sign19);
   ObjectCreate(sign19, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign19, Sign ,10, "Wingdings", Col);
   ObjectSet(sign19, OBJPROP_CORNER, Corner );
   ObjectSet(sign19, OBJPROP_XDISTANCE, 83 );
   ObjectSet(sign19, OBJPROP_YDISTANCE, 10 );
   
   MAOpen=iMomentum(NULL,1440,5,PRICE_WEIGHTED,1);
   MAClose=iMomentum(NULL,1440,5,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign29 = "Momentum Week Sign";
   ObjectDelete(sign29);
   ObjectCreate(sign29, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign29, Sign ,10, "Wingdings", Col);
   ObjectSet(sign29, OBJPROP_CORNER, Corner );
   ObjectSet(sign29, OBJPROP_XDISTANCE, 83 );
   ObjectSet(sign29, OBJPROP_YDISTANCE, 20 );

   MAOpen=iMomentum(NULL,240,6,PRICE_WEIGHTED,1);
   MAClose=iMomentum(NULL,240,6,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign39 = "Momentum Day Sign";
   ObjectDelete(sign39);
   ObjectCreate(sign39, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign39, Sign ,10, "Wingdings", Col);
   ObjectSet(sign39, OBJPROP_CORNER, Corner );
   ObjectSet(sign39, OBJPROP_XDISTANCE, 83 );
   ObjectSet(sign39, OBJPROP_YDISTANCE, 30 );

   MAOpen=iMomentum(NULL,60,8,PRICE_WEIGHTED,1);
   MAClose=iMomentum(NULL,60,8,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign49 = "Momentum 8H Sign";
   ObjectDelete(sign49);
   ObjectCreate(sign49, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign49, Sign ,10, "Wingdings", Col);
   ObjectSet(sign49, OBJPROP_CORNER, Corner );
   ObjectSet(sign49, OBJPROP_XDISTANCE, 83 );
   ObjectSet(sign49, OBJPROP_YDISTANCE, 40 );
   
   MAOpen=iMomentum(NULL,60,4,PRICE_WEIGHTED,1);
   MAClose=iMomentum(NULL,60,4,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign59 = "Momentum 4H Sign";
   ObjectDelete(sign59);
   ObjectCreate(sign59, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign59, Sign ,10, "Wingdings", Col);
   ObjectSet(sign59, OBJPROP_CORNER, Corner );
   ObjectSet(sign59, OBJPROP_XDISTANCE, 83 );
   ObjectSet(sign59, OBJPROP_YDISTANCE, 50 );

   MAOpen=iMomentum(NULL,15,4,PRICE_WEIGHTED,1);
   MAClose=iMomentum(NULL,15,4,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign69 = "Momentum 1H Sign";
   ObjectDelete(sign69);
   ObjectCreate(sign69, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign69, Sign ,10, "Wingdings", Col);
   ObjectSet(sign69, OBJPROP_CORNER, Corner );
   ObjectSet(sign69, OBJPROP_XDISTANCE, 83 );
   ObjectSet(sign69, OBJPROP_YDISTANCE, 60 );

   MAOpen=iMomentum(NULL,5,6,PRICE_WEIGHTED,1);
   MAClose=iMomentum(NULL,5,6,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign79 = "Momentum 30M Sign";
   ObjectDelete(sign79);
   ObjectCreate(sign79, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign79, Sign ,10, "Wingdings", Col);
   ObjectSet(sign79, OBJPROP_CORNER, Corner );
   ObjectSet(sign79, OBJPROP_XDISTANCE, 83 );
   ObjectSet(sign79, OBJPROP_YDISTANCE, 70 );
   
   MAOpen=iMomentum(NULL,5,3,PRICE_WEIGHTED,1);
   MAClose=iMomentum(NULL,5,3,PRICE_WEIGHTED,0);
   if (MAOpen==MAClose) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAOpen < MAClose) { Sign="ñ"; Col=Blue; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign89 = "Momentum 15M Sign";
   ObjectDelete(sign89);
   ObjectCreate(sign89, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign89, Sign ,10, "Wingdings", Col);
   ObjectSet(sign89, OBJPROP_CORNER, Corner );
   ObjectSet(sign89, OBJPROP_XDISTANCE, 83 );
   ObjectSet(sign89, OBJPROP_YDISTANCE, 80 );
   
//----
   return(0);
  }
//+------------------------------------------------------------------+