Navigation:Home > Content >

BB_Percent.mq4

Time: 2016-08-19 | Download file:BB_Percent.mq4

#property indicator_separate_window

#property indicator_buffers 3
#property indicator_color1 DimGray
#property indicator_color2 Red
#property indicator_color3 LimeGreen
#property indicator_width2 2
#property indicator_width3 2
#property indicator_level1 40
#property indicator_level2 60

extern int     bbperiod    = 110;
extern double  deviation   = 1;
extern double  bblevel1    = 40.0;
extern double  bblevel2    = 60.0;

double BBBuffer[];
double BBBuffer2[];
double BBBuffer3[];

int init(){
   string short_name;

   SetIndexStyle(0,DRAW_LINE,0,1);
   SetIndexBuffer(0,BBBuffer);
   SetIndexStyle(1,DRAW_LINE,0,2);
   SetIndexBuffer(1,BBBuffer2);
   SetIndexStyle(2,DRAW_LINE,0,2);
   SetIndexBuffer(2,BBBuffer3);

   short_name="BBP("+bbperiod+")";
   IndicatorShortName(short_name);

   SetIndexDrawBegin(0,bbperiod);
   SetIndexDrawBegin(1,bbperiod);
   SetIndexDrawBegin(2,bbperiod);

   return(0);
}

int start(){
   int i,counted_bars=IndicatorCounted();
   double LB,UB;

   if(Bars<=bbperiod)return(0);

   if(counted_bars<1)for(i=1;i<=bbperiod;i++)BBBuffer[Bars-i]=0.0;

   i=Bars-bbperiod-1;
   if(counted_bars>=bbperiod)i=Bars-counted_bars-1;
   while(i>=0){
      LB=iBands(NULL,0,bbperiod,deviation,0,PRICE_CLOSE,MODE_LOWER,i);
      UB=iBands(NULL,0,bbperiod,deviation,0,PRICE_CLOSE,MODE_UPPER,i);
      BBBuffer[i]=(iClose(NULL,0,i)-LB)/(UB-LB)*100;
      if(BBBuffer[i]bblevel2)BBBuffer3[i]=BBBuffer[i];
      i--;
   }
   return(0);
}

Recommend