//+------------------------------------------------------------------+
//|                                             KG MACD Shift v1.mq4 |
//|                                    copyleft 2012, Diksy Media F. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "copyleft 2012, Diksy Media F."
#property link      ""

#property indicator_separate_window
#property indicator_buffers 7
#property indicator_style2 STYLE_SOLID
#property indicator_style3 STYLE_SOLID
#property indicator_style4 STYLE_SOLID
#property indicator_style5 STYLE_DOT
#property indicator_style6 STYLE_DOT
#property indicator_style7 STYLE_SOLID
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 2
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 White
#property indicator_color5 White
#property indicator_color6 White
#property indicator_color7 Lime

static int VALUE = 0, UP = 1, DOWN = 2, SMA = 3, UPPER_BB = 4, LOWER_BB = 5, LSMA = 6;
double value_buff[], up_buff[], down_buff[], sma_buff[], upper_bb_buff[], lower_bb_buff[], lsma_buff[];
//--- input parameters
extern int       Periode=24;
extern int       Harga=PRICE_CLOSE;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorDigits(Digits);
   SetIndexBuffer(UP, up_buff);
   SetIndexBuffer(DOWN, down_buff);
   SetIndexBuffer(VALUE, value_buff);
   SetIndexBuffer(SMA, sma_buff);
   SetIndexBuffer(UPPER_BB, upper_bb_buff);
   SetIndexBuffer(LOWER_BB, lower_bb_buff);
   SetIndexBuffer(LSMA, lsma_buff);
   SetIndexStyle(UP, DRAW_HISTOGRAM);
   SetIndexStyle(DOWN, DRAW_HISTOGRAM);
   SetIndexStyle(VALUE, DRAW_NONE);
   SetIndexStyle(SMA, DRAW_LINE);
   SetIndexStyle(UPPER_BB, DRAW_LINE);
   SetIndexStyle(LOWER_BB, DRAW_LINE);
   SetIndexStyle(LSMA, DRAW_LINE);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   int index = 0;
   for(index = Bars; index >= 0; index--) value_buff[index] = Close[index] - iMA(NULL, 0, 1, Periode, MODE_SMA, Harga, index);
   for(index = Bars - Periode; index >= 0; index--)
   {
      if(value_buff[index] > 0)
      {
         up_buff[index] = value_buff[index];
         down_buff[index] = 0;
      }
      else if(value_buff[index] < 0)
      {
         up_buff[index] = 0;
         down_buff[index] = value_buff[index];
      }
      else
      {
         up_buff[index] = 0;
         down_buff[index] = 0;
      }
      sma_buff[index] = iMAOnArray(value_buff, Bars, Periode, 0, MODE_SMA, index);
      upper_bb_buff[index] = iBandsOnArray(value_buff, Bars, Periode, 1, 0, MODE_UPPER, index);
      lower_bb_buff[index] = iBandsOnArray(value_buff, Bars, Periode, 1, 0, MODE_LOWER, index);
      lsma_buff[index] = 3*iMAOnArray(value_buff, Bars, Periode, 0, MODE_LWMA, index) - 2*iMAOnArray(value_buff, Bars, Periode, 0, MODE_SMA, index);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+