//+------------------------------------------------------------------+
//|                                                KG SEAWAVE MA.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 5

extern int Corner=1;
extern color MA_Month_Color=Aqua;
extern color MA_Week_Color=Magenta;
extern color MA_Day_Color=Lime;
extern color MA_6H_Color=Yellow;
extern color MA_1H_Color=MediumBlue;

//---- buffers
double MAMonth[];
double MAWeek[];
double MA24H[];
double MA6H[];
double MA1H[];
int    PerMonth;
int    PerWeek;
int    Per24H;
int    Per6H;
int    Per1H;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,0,2,MA_Month_Color);
   SetIndexBuffer(0,MAMonth);
   SetIndexLabel(0,"MA Month");
   SetIndexStyle(1,DRAW_LINE,0,2,MA_Week_Color);
   SetIndexBuffer(1,MAWeek);
   SetIndexLabel(1,"MA Week");
   SetIndexStyle(2,DRAW_LINE,0,2,MA_Day_Color);
   SetIndexBuffer(2,MA24H);
   SetIndexLabel(2,"MA Day");
   SetIndexStyle(3,DRAW_LINE,0,2,MA_6H_Color);
   SetIndexBuffer(3,MA6H);
   SetIndexLabel(3,"MA 6H");
   SetIndexStyle(4,DRAW_LINE,0,2,MA_1H_Color);
   SetIndexBuffer(4,MA1H);
   SetIndexLabel(4,"MA 1H");

   string label1 = "KG MA Month";
   ObjectDelete(label1);
   ObjectCreate( label1, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label1,"Monthly",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",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",8, "Arial Bold", MA_Day_Color);
   ObjectSet( label3, OBJPROP_CORNER, Corner );
   ObjectSet( label3, OBJPROP_XDISTANCE, 3 );
   ObjectSet( label3, OBJPROP_YDISTANCE, 30 );
   
 

   string label6 = "Bollinger Bands";
   ObjectDelete(label6);
   ObjectCreate( label6, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label6,"BB",8, "Arial Bold", MA_1H_Color);
   ObjectSet( label6, OBJPROP_CORNER, Corner );
   ObjectSet( label6, OBJPROP_XDISTANCE, 51 );
   ObjectSet( label6, OBJPROP_YDISTANCE, 50 );

   string label7 = "Trend";
   ObjectDelete(label7);
   ObjectCreate( label7, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label7,"T",8, "Arial Bold", MA_1H_Color);
   ObjectSet( label7, OBJPROP_CORNER, Corner );
   ObjectSet( label7, OBJPROP_XDISTANCE, 74 );
   ObjectSet( label7, OBJPROP_YDISTANCE, 50 );

 

//----
   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;
 

   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);
      MAWeek[i]=iMA(NULL,0,PerWeek,0,MODE_SMA,PRICE_WEIGHTED,i);
      MA24H[i]=iMA(NULL,0,Per24H,0,MODE_SMA,PRICE_WEIGHTED,i);
     
   }
   
   string Sign;   
   color Col;
   
   // Perhitungan kondisi Flat base on BB SD1
   
   double BBUpper=iBands(NULL,0,PerMonth,1,0,PRICE_WEIGHTED,MODE_UPPER,0);
   double BBLower=iBands(NULL,0,PerMonth,1,0,PRICE_WEIGHTED,MODE_LOWER,0);
   if (iMA(NULL,0,2,0,MODE_SMA,PRICE_WEIGHTED,0)>BBLower && iMA(NULL,0,2,0,MODE_SMA,PRICE_WEIGHTED,0)<BBUpper) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (iMA(NULL,0,2,0,MODE_SMA,PRICE_WEIGHTED,0)>BBUpper) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign13 = "Monthly BB";
   ObjectDelete(sign13);
   ObjectCreate(sign13, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign13, Sign ,10, "Wingdings", Col);
   ObjectSet(sign13, OBJPROP_CORNER, Corner );
   ObjectSet(sign13, OBJPROP_XDISTANCE, 53 );
   ObjectSet(sign13, OBJPROP_YDISTANCE, 10 );
   
   BBUpper=iBands(NULL,0,PerWeek,1,0,PRICE_WEIGHTED,MODE_UPPER,0);
   BBLower=iBands(NULL,0,PerWeek,1,0,PRICE_WEIGHTED,MODE_LOWER,0);
   if (iMA(NULL,0,2,0,MODE_SMA,PRICE_WEIGHTED,0)>BBLower && iMA(NULL,0,2,0,MODE_SMA,PRICE_WEIGHTED,0)<BBUpper) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (iMA(NULL,0,2,0,MODE_SMA,PRICE_WEIGHTED,0)>BBUpper) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign23 = "Weekly BB";
   ObjectDelete(sign23);
   ObjectCreate(sign23, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign23, Sign ,10, "Wingdings", Col);
   ObjectSet(sign23, OBJPROP_CORNER, Corner );
   ObjectSet(sign23, OBJPROP_XDISTANCE, 53 );
   ObjectSet(sign23, OBJPROP_YDISTANCE, 20 );

   BBUpper=iBands(NULL,0,Per24H,1,0,PRICE_WEIGHTED,MODE_UPPER,0);
   BBLower=iBands(NULL,0,Per24H,1,0,PRICE_WEIGHTED,MODE_LOWER,0);
   if (iMA(NULL,0,2,0,MODE_SMA,PRICE_WEIGHTED,0)>BBLower && iMA(NULL,0,2,0,MODE_SMA,PRICE_WEIGHTED,0)<BBUpper) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (iMA(NULL,0,2,0,MODE_SMA,PRICE_WEIGHTED,0)>BBUpper) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign33 = "Daily BB";
   ObjectDelete(sign33);
   ObjectCreate(sign33, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign33, Sign ,10, "Wingdings", Col);
   ObjectSet(sign33, OBJPROP_CORNER, Corner );
   ObjectSet(sign33, OBJPROP_XDISTANCE, 53 );
   ObjectSet(sign33, OBJPROP_YDISTANCE, 30 );


   
   // Perhitungan untuk trend
   
   double MAOpen=iMA(NULL,0,PerMonth,0,MODE_SMA,PRICE_WEIGHTED,1);
   double MAClose=iMA(NULL,0,PerMonth,0,MODE_SMA,PRICE_WEIGHTED,0);
   if (MAClose==MAOpen) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAClose > MAOpen) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign1 = "Monthly Wave";
   ObjectDelete(sign1);
   ObjectCreate(sign1, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign1, Sign ,10, "Wingdings", Col);
   ObjectSet(sign1, OBJPROP_CORNER, Corner );
   ObjectSet(sign1, OBJPROP_XDISTANCE, 73 );
   ObjectSet(sign1, OBJPROP_YDISTANCE, 10 );
   
   MAOpen=iMA(NULL,0,PerWeek,0,MODE_SMA,PRICE_WEIGHTED,1);
   MAClose=iMA(NULL,0,PerWeek,0,MODE_SMA,PRICE_WEIGHTED,0);
   if (MAClose==MAOpen) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAClose > MAOpen) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign2 = "Weekly Wave";
   ObjectDelete(sign2);
   ObjectCreate(sign2, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign2, Sign ,10, "Wingdings", Col);
   ObjectSet(sign2, OBJPROP_CORNER, Corner );
   ObjectSet(sign2, OBJPROP_XDISTANCE, 73 );
   ObjectSet(sign2, OBJPROP_YDISTANCE, 20 );

   MAOpen=iMA(NULL,0,Per24H,0,MODE_SMA,PRICE_WEIGHTED,1);
   MAClose=iMA(NULL,0,Per24H,0,MODE_SMA,PRICE_WEIGHTED,0);
   if (MAClose==MAOpen) { Sign="ó"; Col=Yellow; } //Sideway
   else 
      if (MAClose > MAOpen) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   string sign3 = "Daily Wave";
   ObjectDelete(sign3);
   ObjectCreate(sign3, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(sign3, Sign ,10, "Wingdings", Col);
   ObjectSet(sign3, OBJPROP_CORNER, Corner );
   ObjectSet(sign3, OBJPROP_XDISTANCE, 73 );
   ObjectSet(sign3, OBJPROP_YDISTANCE, 30 );

  

//----
   return(0);
  }
//+------------------------------------------------------------------+