//+------------------------------------------------------------------+
//|                      Copyright © 2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link      "kgforexworld.com"

#property indicator_chart_window
#property indicator_buffers 8

extern int   Corner            = 1,
             Price_Type        = 0,
             Width             = 2; 
extern bool  Show_LSMA         = true;               
extern color LSMA_4Year_Color  = Maroon,
             LSMA_Year_Color   = BlueViolet,
             LSMA_4Month_Color = SandyBrown,
             LSMA_Month_Color  = Aqua,
             LSMA_Week_Color   = Magenta,
             LSMA_Day_Color    = Lime,
             LSMA_8H_Color     = Yellow,
             LSMA_4H_Color     = RoyalBlue;
//---- buffers
double LSMA4Year[],LSMAYear[],LSMA4Month[],LSMAMonth[],LSMAWeek[],LSMA24H[],LSMA8H[],LSMA4H[];
int    Per4Year=0,PerYear=0,Per4Month=0,PerMonth=0,PerWeek=0,Per24H=0,Per8H=0,Per4H=0,X3=90,start.bar=0,Applied_Price = PRICE_WEIGHTED;

string bsb1 = "KG BSBand 4Year",
       bsb2 = "KG BSBand Year",
       bsb3 = "KG BSBand 4Month",
       bsb4 = "KG BSBand Month",
       bsb5 = "KG BSBand Week",
       bsb6 = "KG BSBand Day",
       bsb7 = "KG BSBand 8H",
       bsb8 = "KG BSBand 4H";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   if(Show_LSMA)
   {
   SetIndexStyle(0,DRAW_LINE,0,Width,LSMA_4Year_Color);
   SetIndexBuffer(0,LSMA4Year);   
   SetIndexStyle(1,DRAW_LINE,0,Width,LSMA_Year_Color);
   SetIndexBuffer(1,LSMAYear);   
   SetIndexStyle(2,DRAW_LINE,0,Width,LSMA_4Month_Color);
   SetIndexBuffer(2,LSMA4Month);   
   SetIndexStyle(3,DRAW_LINE,0,Width,LSMA_Month_Color);
   SetIndexBuffer(3,LSMAMonth);   
   SetIndexStyle(4,DRAW_LINE,0,Width,LSMA_Week_Color);
   SetIndexBuffer(4,LSMAWeek);   
   SetIndexStyle(5,DRAW_LINE,0,Width,LSMA_Day_Color);
   SetIndexBuffer(5,LSMA24H);   
   SetIndexStyle(6,DRAW_LINE,0,Width,LSMA_8H_Color);
   SetIndexBuffer(6,LSMA8H);   
   SetIndexStyle(7,DRAW_LINE,0,Width,LSMA_4H_Color);
   SetIndexBuffer(7,LSMA4H);   
   }
   
   if(!Show_LSMA)
   {
   SetIndexStyle(0,DRAW_NONE);
   SetIndexBuffer(0,LSMA4Year);
   SetIndexStyle(1,DRAW_NONE);
   SetIndexBuffer(1,LSMAYear);  
   SetIndexStyle(2,DRAW_NONE); 
   SetIndexBuffer(2,LSMA4Month);
   SetIndexStyle(3,DRAW_NONE);
   SetIndexBuffer(3,LSMAMonth);
   SetIndexStyle(4,DRAW_NONE); 
   SetIndexBuffer(4,LSMAWeek);
   SetIndexStyle(5,DRAW_NONE); 
   SetIndexBuffer(5,LSMA24H); 
   SetIndexStyle(6,DRAW_NONE);
   SetIndexBuffer(6,LSMA8H);
   SetIndexStyle(7,DRAW_NONE);
   SetIndexBuffer(7,LSMA4H);   
   }
   
   SetLabel("KG LSMA 4Year", "4Yearly", 8, "Arial Bold", LSMA_4Year_Color, Corner, 5, 10);   
   SetLabel("KG LSMA Year", "Yearly", 8, "Arial Bold", LSMA_Year_Color, Corner, 5, 20);   
   SetLabel("KG LSMA 4Month", "4Monthly", 8, "Arial Bold", LSMA_4Month_Color, Corner, 5, 30);   
   SetLabel("KG LSMA Month", "Monthly", 8, "Arial Bold", LSMA_Month_Color, Corner, 5, 40);  
   SetLabel("KG LSMA Week", "Weekly", 8, "Arial Bold", LSMA_Week_Color, Corner, 5, 50);   
   SetLabel("KG LSMA Day", "Daily", 8, "Arial Bold", LSMA_Day_Color, Corner, 5, 60);  
   SetLabel("KG LSMA 8H", "8H", 8, "Arial Bold", LSMA_8H_Color, Corner, 5, 70);   
   SetLabel("KG LSMA 4H", "4H", 8, "Arial Bold", LSMA_4H_Color, Corner, 5, 80);
  
   SetLabel("KG LSMA", "LSMA", 8, "Arial Bold", LSMA_Day_Color, Corner, 10, 100);  
   SetLabel("KG LSMA Trend", "Trend", 8, "Arial Bold", LSMA_Day_Color, Corner, 48, 100);   
   SetLabel("KG MA Bollinger Bands", "BB", 8, "Arial Bold", LSMA_Day_Color, Corner, 85, 100);   
   SetLabel("KG BSB", "BSB", 8, "Arial Bold", LSMA_Day_Color, Corner, 107, 100);           
   
   getPeriod();      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll(0,OBJ_LABEL);  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
//----   
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   for(int i=0; i<limit; i++)
   { 
      LSMA4Year[i]=3*iMA(Symbol(),0,Per4Year,0,MODE_LWMA,Price_Type,i)-2*iMA(Symbol(),0,Per4Year,0,MODE_SMA,Price_Type,i);
      LSMAYear[i]=3*iMA(Symbol(),0,PerYear,0,MODE_LWMA,Price_Type,i)-2*iMA(Symbol(),0,PerYear,0,MODE_SMA,Price_Type,i);
      LSMA4Month[i]=3*iMA(Symbol(),0,Per4Month,0,MODE_LWMA,Price_Type,i)-2*iMA(Symbol(),0,Per4Month,0,MODE_SMA,Price_Type,i);
      LSMAMonth[i]=3*iMA(Symbol(),0,PerMonth,0,MODE_LWMA,Price_Type,i)-2*iMA(Symbol(),0,PerMonth,0,MODE_SMA,Price_Type,i);
      LSMAWeek[i]=3*iMA(Symbol(),0,PerWeek,0,MODE_LWMA,Price_Type,i)-2*iMA(Symbol(),0,PerWeek,0,MODE_SMA,Price_Type,i);
      LSMA24H[i]=3*iMA(Symbol(),0,Per24H,0,MODE_LWMA,Price_Type,i)-2*iMA(Symbol(),0,Per24H,0,MODE_SMA,Price_Type,i);
      LSMA8H[i]=3*iMA(Symbol(),0,Per8H,0,MODE_LWMA,Price_Type,i)-2*iMA(Symbol(),0,Per8H,0,MODE_SMA,Price_Type,i);
      LSMA4H[i]=3*iMA(Symbol(),0,Per4H,0,MODE_LWMA,Price_Type,i)-2*iMA(Symbol(),0,Per4H,0,MODE_SMA,Price_Type,i);
   }
        
      start.bar = Per4H; if(Period()<PERIOD_H4) { bsband(bsb8, LSMA_4H_Color, X3, 80);
      }      
      start.bar = Per8H; if(Period()<PERIOD_D1) { bsband(bsb7, LSMA_8H_Color, X3, 70); 
      }                                    
      start.bar = Per24H; if(Period()<PERIOD_D1) { bsband(bsb6, LSMA_Day_Color, X3, 60);
      }      
      start.bar = PerWeek; if(Period()<PERIOD_W1) { bsband(bsb5, LSMA_Week_Color, X3, 50);
      }      
      start.bar = PerMonth; if(Period()<PERIOD_MN1) {bsband(bsb4, LSMA_Month_Color, X3, 40);
      }
      start.bar = Per4Month; bsband(bsb3, LSMA_4Month_Color, X3, 30);
      start.bar = PerYear;   bsband(bsb2, LSMA_Year_Color, X3, 20);     
      start.bar = Per4Year;  bsband(bsb1, LSMA_4Year_Color, X3, 10);        
     
   string Sign;
   color Col; 
   
   double LSMAOpen=3*iMA(Symbol(),0,Per4Year,0,MODE_LWMA,Price_Type,1)-2*iMA(Symbol(),0,Per4Year,0,MODE_SMA,Price_Type,1);
   double LSMAClose=3*iMA(Symbol(),0,Per4Year,0,MODE_LWMA,Price_Type,0)-2*iMA(Symbol(),0,Per4Year,0,MODE_SMA,Price_Type,0);   
   if (LSMAOpen==LSMAClose) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (LSMAOpen < LSMAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("KG LSMA 4Year Sign", Sign, Col, Corner, 53, 10);    
        
   LSMAOpen=3*iMA(Symbol(),0,PerYear,0,MODE_LWMA,Price_Type,1)-2*iMA(Symbol(),0,PerYear,0,MODE_SMA,Price_Type,1);
   LSMAClose=3*iMA(Symbol(),0,PerYear,0,MODE_LWMA,Price_Type,0)-2*iMA(Symbol(),0,PerYear,0,MODE_SMA,Price_Type,0);
   if (LSMAOpen==LSMAClose) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (LSMAOpen < LSMAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("KG LSMA Year Sign", Sign, Col, Corner, 53, 20);      
         
   LSMAOpen=3*iMA(Symbol(),0,Per4Month,0,MODE_LWMA,Price_Type,1)-2*iMA(Symbol(),0,Per4Month,0,MODE_SMA,Price_Type,1);
   LSMAClose=3*iMA(Symbol(),0,Per4Month,0,MODE_LWMA,Price_Type,0)-2*iMA(Symbol(),0,Per4Month,0,MODE_SMA,Price_Type,0);
   if (LSMAOpen==LSMAClose) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (LSMAOpen < LSMAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("KG LSMA 4Month Sign", Sign, Col, Corner, 53, 30);   
         
   if(Period()<PERIOD_MN1)
   {      
   LSMAOpen=3*iMA(Symbol(),0,PerMonth,0,MODE_LWMA,Price_Type,1)-2*iMA(Symbol(),0,PerMonth,0,MODE_SMA,Price_Type,1);
   LSMAClose=3*iMA(Symbol(),0,PerMonth,0,MODE_LWMA,Price_Type,0)-2*iMA(Symbol(),0,PerMonth,0,MODE_SMA,Price_Type,0);
   if (LSMAOpen==LSMAClose) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (LSMAOpen < LSMAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("KG LSMA Month Sign", Sign, Col, Corner, 53, 40);     
   }
   
   if(Period()<PERIOD_W1)
   {      
   LSMAOpen=3*iMA(Symbol(),0,PerWeek,0,MODE_LWMA,Price_Type,1)-2*iMA(Symbol(),0,PerWeek,0,MODE_SMA,Price_Type,1);
   LSMAClose=3*iMA(Symbol(),0,PerWeek,0,MODE_LWMA,Price_Type,0)-2*iMA(Symbol(),0,PerWeek,0,MODE_SMA,Price_Type,0);
   if (LSMAOpen==LSMAClose) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (LSMAOpen < LSMAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("KG LSMA Week Sign", Sign, Col, Corner, 53, 50);     
   }
   
   if(Period()<PERIOD_D1)
   {      
   LSMAOpen=3*iMA(Symbol(),0,Per24H,0,MODE_LWMA,Price_Type,1)-2*iMA(Symbol(),0,Per24H,0,MODE_SMA,Price_Type,1);
   LSMAClose=3*iMA(Symbol(),0,Per24H,0,MODE_LWMA,Price_Type,0)-2*iMA(Symbol(),0,Per24H,0,MODE_SMA,Price_Type,0);
   if (LSMAOpen==LSMAClose) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (LSMAOpen < LSMAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("KG LSMA Day Sign", Sign, Col, Corner, 53, 60);    
          
   LSMAOpen=3*iMA(Symbol(),0,Per8H,0,MODE_LWMA,Price_Type,1)-2*iMA(Symbol(),0,Per8H,0,MODE_SMA,Price_Type,1);
   LSMAClose=3*iMA(Symbol(),0,Per8H,0,MODE_LWMA,Price_Type,0)-2*iMA(Symbol(),0,Per8H,0,MODE_SMA,Price_Type,0);
   if (LSMAOpen==LSMAClose) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (LSMAOpen < LSMAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("KG LSMA 8H Sign", Sign, Col, Corner, 53, 70);   
   }
   
   if(Period()<PERIOD_H4)
   {   
   LSMAOpen=3*iMA(Symbol(),0,Per4H,0,MODE_LWMA,Price_Type,1)-2*iMA(Symbol(),0,Per4H,0,MODE_SMA,Price_Type,1);
   LSMAClose=3*iMA(Symbol(),0,Per4H,0,MODE_LWMA,Price_Type,0)-2*iMA(Symbol(),0,Per4H,0,MODE_SMA,Price_Type,0);
   if (LSMAOpen==LSMAClose) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (LSMAOpen < LSMAClose) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("KG LSMA 4H Sign", Sign, Col, Corner, 53, 80);     
   }
            
   // Perhitungan kondisi Flat base on BB SD1
   
   double BBUpper=iBands(NULL,0,Per4Year,1,0,Applied_Price,MODE_UPPER,0);
   double BBLower=iBands(NULL,0,Per4Year,1,0,Applied_Price,MODE_LOWER,0);
   if (Close[0]>=BBLower && Close[0]<=BBUpper) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (Close[0]>BBUpper && Close[0]>BBLower) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("4Yearly BB", Sign, Col, Corner, 85, 10);
   
   BBUpper=iBands(NULL,0,PerYear,1,0,Applied_Price,MODE_UPPER,0);
   BBLower=iBands(NULL,0,PerYear,1,0,Applied_Price,MODE_LOWER,0);
   if (Close[0]>=BBLower && Close[0]<=BBUpper) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (Close[0]>BBUpper && Close[0]>BBLower) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("Yearly BB", Sign, Col, Corner, 85, 20);
   
   BBUpper=iBands(NULL,0,Per4Month,1,0,Applied_Price,MODE_UPPER,0);
   BBLower=iBands(NULL,0,Per4Month,1,0,Applied_Price,MODE_LOWER,0);
   if (Close[0]>=BBLower && Close[0]<=BBUpper) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (Close[0]>BBUpper && Close[0]>BBLower) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("4Monthly BB", Sign, Col, Corner, 85, 30);
   
   if(Period()<PERIOD_MN1)
   {
   BBUpper=iBands(NULL,0,PerMonth,1,0,Applied_Price,MODE_UPPER,0);
   BBLower=iBands(NULL,0,PerMonth,1,0,Applied_Price,MODE_LOWER,0);
   if (Close[0]>=BBLower && Close[0]<=BBUpper) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (Close[0]>BBUpper && Close[0]>BBLower) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("Monthly BB", Sign, Col, Corner, 85, 40);
   }
   
   if(Period()<PERIOD_W1)
   {  
   BBUpper=iBands(NULL,0,PerWeek,1,0,Applied_Price,MODE_UPPER,0);
   BBLower=iBands(NULL,0,PerWeek,1,0,Applied_Price,MODE_LOWER,0);
   if (Close[0]>=BBLower && Close[0]<=BBUpper) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (Close[0]>BBUpper && Close[0]>BBLower) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("Weekly BB", Sign, Col, Corner, 85, 50); 
   }
   
   if(Period()<PERIOD_D1)
   {
   BBUpper=iBands(NULL,0,Per24H,1,0,Applied_Price,MODE_UPPER,0);
   BBLower=iBands(NULL,0,Per24H,1,0,Applied_Price,MODE_LOWER,0);
   if (Close[0]>=BBLower && Close[0]<=BBUpper) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (Close[0]>BBUpper && Close[0]>BBLower) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("Daily BB", Sign, Col, Corner, 85, 60);
 
   BBUpper=iBands(NULL,0,Per8H,1,0,Applied_Price,MODE_UPPER,0);
   BBLower=iBands(NULL,0,Per8H,1,0,Applied_Price,MODE_LOWER,0);
   if (Close[0]>=BBLower && Close[0]<=BBUpper) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (Close[0]>BBUpper && Close[0]>BBLower) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("8H BB", Sign, Col, Corner, 85, 70);
   }
   
   if(Period()<PERIOD_H4)
   {
   BBUpper=iBands(NULL,0,Per4H,1,0,Applied_Price,MODE_UPPER,0);
   BBLower=iBands(NULL,0,Per4H,1,0,Applied_Price,MODE_LOWER,0);
   if (Close[0]>=BBLower && Close[0]<=BBUpper) { Sign="ó"; Col=DarkOrange; } //Sideway
   else 
      if (Close[0]>BBUpper && Close[0]>BBLower) { Sign="ñ"; Col=Lime; } //Trend Up
      else { Sign="ò"; Col=Red; } //Trend Down
   SetSign("4H BB", Sign, Col, Corner, 85, 80);   
   }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

void bsband(string nama_label, color warna, int l, int m)
{
   double hi = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, start.bar, 0));
   double lo = iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW, start.bar, 0));       
                      
   string hasilnya;
   double band3=(hi+lo)/2; //Middle
   double band1=(hi+band3)/2;//Upper
   double band2=(lo+band3)/2;//Lower
   
   if (Bid>band1) hasilnya=">BS";
   if (Bid<band1 && Bid>band3) hasilnya=">BSB";
   if (Bid<band3 && Bid>band2) hasilnya="<BSB";
   if (Bid<band2) hasilnya="<SB";

   ObjectDelete(nama_label);
   ObjectCreate(nama_label, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(nama_label, hasilnya ,8, "Arial Bold", warna);
   ObjectSet(nama_label, OBJPROP_CORNER, Corner );
   ObjectSet(nama_label, OBJPROP_XDISTANCE, l+15 );
   ObjectSet(nama_label, OBJPROP_YDISTANCE, m );      
   
}

void SetSign(string name_, string Sign_, int Col_, int Corner_, int x_, int y_)
{
   ObjectDelete(name_);
   ObjectCreate(name_, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(name_, Sign_ ,10, "Wingdings", Col_);
   ObjectSet(name_, OBJPROP_CORNER, Corner_ );
   ObjectSet(name_, OBJPROP_XDISTANCE, x_ );
   ObjectSet(name_, OBJPROP_YDISTANCE, y_ );  
}

void SetLabel(string label_, string text_, int size_, string font_, color color_, int Corner_, int x_, int y_)
{
   ObjectDelete(label_);
   ObjectCreate( label_, OBJ_LABEL, 0, 0, 0 );
   ObjectSetText(label_, text_, size_, font_, color_);
   ObjectSet( label_, OBJPROP_CORNER, Corner_ );
   ObjectSet( label_, OBJPROP_XDISTANCE, x_ );
   ObjectSet( label_, OBJPROP_YDISTANCE, y_ );
}

void getPeriod() {
   switch(Period()) {
   case 1     : Per4H=240; Per8H=480; Per24H=1440; PerWeek=7200; PerMonth=28800; Per4Month=115200; PerYear=345600; Per4Year=1382400; break;
   case 5     : Per4H=48; Per8H=96; Per24H=288; PerWeek=1440; PerMonth=5760; Per4Month=23040; PerYear=69120; Per4Year=276480; break;
   case 10    : Per4H=getrenkodailyavg()/6; Per8H=getrenkodailyavg()/3; Per24H=getrenkodailyavg(); PerWeek=getrenkoweeklyavg(); PerMonth=getrenkomonthlyavg(); 
                Per4Month=getrenkomonthlyavg()*4; PerYear=getrenkomonthlyavg()*12; Per4Year=getrenkomonthlyavg()*48; break;
   case 15    : Per4H=16; Per8H=32; Per24H=96; PerWeek=480; PerMonth=1920; Per4Month=7680; PerYear=23040; Per4Year=92160; break;
   case 20    : Per4H=getrenkodailyavg()/6; Per8H=getrenkodailyavg()/3; Per24H=getrenkodailyavg(); PerWeek=getrenkoweeklyavg(); PerMonth=getrenkomonthlyavg(); 
                Per4Month=getrenkomonthlyavg()*4; PerYear=getrenkomonthlyavg()*12; Per4Year=getrenkomonthlyavg()*48; break;
   case 30    : Per4H=8; Per8H=16; Per24H=48; PerWeek=240; PerMonth=960; Per4Month=3840; PerYear=11520; Per4Year=46080; break;
   case 60    : Per4H=4; Per8H=8; Per24H=24; PerWeek=120; PerMonth=480; Per4Month=1920; PerYear=5760; Per4Year=23040; break;
   case 240   : Per4H=0; Per8H=2; Per24H=6; PerWeek=30; PerMonth=120; Per4Month=480; PerYear=1440; Per4Year=5760; break;
   case 1440  : Per4H=0; Per8H=0; Per24H=0; PerWeek=5; PerMonth=20; Per4Month=80; PerYear=240; Per4Year=960; break;
   case 10080 : Per4H=0; Per8H=0; Per24H=0; PerWeek=0; PerMonth=4; Per4Month=16; PerYear=48; Per4Year=192; break;
   case 43200 : Per4H=0; Per8H=0; Per24H=0; PerWeek=0; PerMonth=0; Per4Month=4; PerYear=12; Per4Year=48; break; 
   }
}

int getrenkodailyavg()
{
   int temp;
   int hasil=0;
   int hari=20;
   for(int i=0;i<hari;i++)
   {
      if(TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))==0 || TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))==6)hari=hari+1;
      if(TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))!=0 && TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))!=6)
      {
         if(i==0)
         {
            temp=iBarShift(NULL,0,StrToTime(TimeToStr(iTime(NULL,PERIOD_D1,i))),false);
         }
         else
         {
            temp=iBarShift(NULL,0,StrToTime(TimeToStr(iTime(NULL,PERIOD_D1,i))),false)-iBarShift(NULL,0,StrToTime(TimeToStr(iTime(NULL,PERIOD_D1,i-1))),false);
         }
         hasil=hasil+temp;
      }
   }
   return(MathCeil(hasil/20));

}

int getrenkoweeklyavg()
{
   int temp;
   int hasil=0;
   int hari=80;
   for(int i=0;i<hari;i++)
   {
      if(TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))==0 || TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))==6)hari=hari+1;
      if(TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))!=0 && TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))!=6)
      {
         if(i==0)
         {
            temp=iBarShift(NULL,0,StrToTime(TimeToStr(iTime(NULL,PERIOD_D1,i))),false);
         }
         else
         {
            temp=iBarShift(NULL,0,StrToTime(TimeToStr(iTime(NULL,PERIOD_D1,i))),false)-iBarShift(NULL,0,StrToTime(TimeToStr(iTime(NULL,PERIOD_D1,i-1))),false);
         }
         hasil=hasil+temp;
      }
   }
   return(MathCeil(hasil/16));

}

int getrenkomonthlyavg()
{
   int temp;
   int hasil=0;
   int hari=240;
   for(int i=0;i<hari;i++)
   {
      if(TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))==0 || TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))==6)hari=hari+1;
      if(TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))!=0 && TimeDayOfWeek(iTime(NULL,PERIOD_D1,i))!=6)
      {
         if(i==0)
         {
            temp=iBarShift(NULL,0,StrToTime(TimeToStr(iTime(NULL,PERIOD_D1,i))),false);
         }
         else
         {
            temp=iBarShift(NULL,0,StrToTime(TimeToStr(iTime(NULL,PERIOD_D1,i))),false)-iBarShift(NULL,0,StrToTime(TimeToStr(iTime(NULL,PERIOD_D1,i-1))),false);
         }
         hasil=hasil+temp;
      }
   }
   return(MathCeil(hasil/12));
  
}   
    
    