//+------------------------------------------------------------------+
//|                                                        Delta.mq4 |
//|                           Copyright © 2008, D500       ELR       |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, D500."
#property indicator_separate_window
#property indicator_buffers 8

#property indicator_color1 clrWhite
#property indicator_width1 2

#property indicator_color2 clrGreen
#property indicator_width2 2
 
#property indicator_color3 clrDarkOrange
#property indicator_width3 2

#property indicator_color4 clrRed
#property indicator_width4 2

#property indicator_color5 clrGreenYellow
#property indicator_width5 2
 
#property indicator_color6 clrGreen
#property indicator_width6 1
#property indicator_style6 2
 
#property indicator_color7 clrOrange
#property indicator_width7 1
  
#property indicator_color8 clrGray
#property indicator_width8 1

extern int PERIOD=13;
extern int PERIOD_Signal=13;
extern int PERIOD_Smooth=2;
 
double Buffer0[];
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
double Buffer7[];
double znach;
//+------------------------------------------------------------------+
int init()
   {
   SetIndexBuffer(0,Buffer0);
   SetIndexStyle(0,DRAW_LINE);

   SetIndexBuffer(1,Buffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexLabel(1,"Основное значение");
 
   SetIndexBuffer(2,Buffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexLabel(2,"Основное значение");

   SetIndexBuffer(3,Buffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexLabel(3,"Основное значение");

   SetIndexBuffer(4,Buffer4);
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexLabel(4,"Основное значение");

   SetIndexBuffer(5,Buffer5);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexLabel(5,"Сигнальная линия");
 
   SetIndexBuffer(6,Buffer6);
   SetIndexStyle(6,DRAW_LINE);
 
   SetIndexBuffer(7,Buffer7);
   SetIndexStyle(7,DRAW_LINE);

   return(0);
   }
//+------------------------------------------------------------------+
int start()
{
   int    counted_bars=IndicatorCounted();
   int limit;
   limit=Bars-counted_bars;
  
   for(int i=0;i<limit;i++)
   {
      znach = ((High[i]+Low[i])/2)-iMA(NULL,0,PERIOD,0,1,0,i);
      Buffer7[i] = znach;
   }
   for(i=0;i<limit;i++)
   {
      if(Buffer7[i]>=0.0)
      {
         if(Buffer7[i]>=Buffer7[i+1])
         {
            Buffer1[i]=Buffer7[i];
            Buffer2[i]=EMPTY_VALUE;
            Buffer3[i]=EMPTY_VALUE;
            Buffer4[i]=EMPTY_VALUE;
         }
         else
         {
            Buffer1[i]=EMPTY_VALUE;
            Buffer2[i]=Buffer7[i];
            Buffer3[i]=EMPTY_VALUE;
            Buffer4[i]=EMPTY_VALUE;
         }
      }
      else
      {
         if(Buffer7[i]>=Buffer7[i+1])
         {
            Buffer1[i]=EMPTY_VALUE;
            Buffer2[i]=EMPTY_VALUE;
            Buffer3[i]=EMPTY_VALUE;
            Buffer4[i]=Buffer7[i];
         }
         else
         {
            Buffer1[i]=EMPTY_VALUE;
            Buffer2[i]=EMPTY_VALUE;
            Buffer3[i]=Buffer7[i];
            Buffer4[i]=EMPTY_VALUE;
         }
      }
   }
   for(i=0;i<limit;i++)
   {
      Buffer0[i]=0.0;
      Buffer5[i]=iMAOnArray(Buffer7,Bars,PERIOD_Signal,0,MODE_SMA,i);
      double Sum_Buf_3 = Buffer7[i];
      if (PERIOD_Smooth<0)
         PERIOD_Smooth=0;
      Buffer6[i]=iMAOnArray(Buffer7,Bars,PERIOD_Smooth+1,0,MODE_SMA,i);   
   }
   return(0);
}
//+------------------------------------------------------------------+   