//+------------------------------------------------------------------+
//|                                                Step-Channels.mq4 |
//|                              Copyright © 2010, Farshad Saremifar |
//|                                      Farshad.Saremifar@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Farshad Saremifar"
#property link      "Farshad.Saremifar@gmail.com"
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color2 Red
#property indicator_color1 DodgerBlue
#property indicator_color4 Red
#property indicator_color3 DodgerBlue
#property indicator_color6 Red
#property indicator_color5 DodgerBlue
#property indicator_color8 Red
#property indicator_color7 DodgerBlue
#property indicator_width7 3
#property indicator_width8 3
//---- input parameters
extern int MAPeriod1=0;
extern int MAPeriod2=21;
extern int MAPeriod3=220;
extern int     Length      = 10;      // Volty Length
extern double  Kv          = 2;     // Sensivity Factor
extern int     StepSize    = 300;       // Constant Step Size (if need)
extern int     MA_Mode     = 0;       // Volty MA Mode : 0-SMA, 1-LWMA 
extern int     Advance     = 0;       // Offset
extern double  Percentage  = 0;       // Percentage of Up/Down Moving   
extern bool    HighLow     = false;   // High/Low Mode Switch (more sensitive)
 int     ColorMode   = 0;       // Color Mode Switch
 int     BarsNumber  = 0;    
extern double fibo1=0.21;
extern double fibo2=0.55;
extern double fibo3=0.9;
extern double fibo4=1.2;


int limit;



int TimeFrame=0;


double  max =0;
double  min =0;

double    Inc0 = 0.0000;
double    Inc1 = 0.0000;
double    Inc2 = 0.0000;
double    Inc3 = 0.0000;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,DoubleToStr(fibo1,3)+"%");

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,DoubleToStr(fibo1,3)+"%");   
   
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexLabel(2,DoubleToStr(fibo2,3)+"%");   
   
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexLabel(3,DoubleToStr(fibo2,3)+"%");   
   
   
   
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexLabel(4,DoubleToStr(fibo3,3)+"%");      
   
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexLabel(5,DoubleToStr(fibo3,3)+"%");      
   
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexLabel(6,DoubleToStr(fibo4,3)+"%");   
      
   SetIndexStyle(7,DRAW_LINE);
   SetIndexBuffer(7,ExtMapBuffer8);
   SetIndexLabel(7,DoubleToStr(fibo4,3)+"%");   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   max =0;
   min =0;
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   

 int  counted_bars=IndicatorCounted();
     
  int Nbars=Bars;
   if ( counted_bars > 0 )  limit=Nbars-counted_bars;
   if ( counted_bars < 0 )  return(0);
   if ( counted_bars ==0 )  limit=Nbars-Length-1; 
   
   
  
   for (int i =limit; i>=0; i--)
   {
   double ma =iCustom(NULL,TimeFrame,"StepMA",MAPeriod1,MAPeriod2,MAPeriod3,Length,Kv,StepSize,MA_Mode,Advance,Percentage,HighLow,ColorMode,BarsNumber,0,i);
   double step =iCustom(NULL,TimeFrame,"StepMA",MAPeriod1,MAPeriod2,MAPeriod3,Length,Kv,StepSize,MA_Mode,Advance,Percentage,HighLow,ColorMode,BarsNumber,6,i);
      ExtMapBuffer1[i] = ma + step*Point * fibo1;
      ExtMapBuffer2[i] = ma - step*Point * fibo1;
      ExtMapBuffer3[i] = ma + step*Point * fibo2;
      ExtMapBuffer4[i] = ma - step*Point * fibo2;


      ExtMapBuffer5[i] = ma + step*Point * fibo3;
      ExtMapBuffer6[i] = ma - step*Point * fibo3;
      ExtMapBuffer7[i] = ma + step*Point * fibo4;
      ExtMapBuffer8[i] = ma - step*Point * fibo4;
      
      
   }

   return(0);
  }
//+------------------------------------------------------------------+