Navigation:Home > Content >

BBRSI_v1.mq4

Time: 2017-03-14 | Download file:BBRSI_v1.mq4

//+------------------------------------------------------------------+
//|                                                       SMARSI.mq4 |
//|                          Typical RSI revised By TrendLaboratory  |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                       E-mail: [email protected] |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 30
#property indicator_level2 70
#property indicator_buffers 4
#property indicator_color1 DodgerBlue
#property indicator_color2 Yellow
#property indicator_color3 Yellow
#property indicator_color4 Yellow

//---- input parameters
extern int RSIPeriod=14;
extern int BBPeriod=20;
extern int Price=0;
extern int Deviation=2;
//---- buffers
double RSIBuffer[];
double BBBuffer[];
double UpBuffer[];
double DnBuffer[];

double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(6);
   SetIndexBuffer(4,PosBuffer);
   SetIndexBuffer(5,NegBuffer);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,RSIBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,BBBuffer);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,UpBuffer);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,DnBuffer);


//---- name for DataWindow and indicator subwindow label
   short_name="BBRSI("+RSIPeriod+","+BBPeriod+","+Price+","+Deviation+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   SetIndexLabel(1,"BB mid");
   SetIndexLabel(2,"BB up");
   SetIndexLabel(3,"BB down");
   
//----
   SetIndexDrawBegin(0,RSIPeriod+BBPeriod);
   SetIndexDrawBegin(1,RSIPeriod+BBPeriod);
   SetIndexDrawBegin(2,RSIPeriod+BBPeriod);
   SetIndexDrawBegin(3,RSIPeriod+BBPeriod);


//----
   return(0);
  }
//+------------------------------------------------------------------+
//| BB and Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive;
//----
   if(Bars<=RSIPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=RSIPeriod;i++) RSIBuffer[Bars-i]=0.0;
//----
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   int MAPeriod=1;
   while(i>=0)
     {
      double sumn=0.0,sump=0.0;
      for (int k=RSIPeriod-1;k>=0;k--)
           { 
            rel=iMA(NULL,0,MAPeriod,0,MODE_SMA,Price,i+k)-iMA(NULL,0,MAPeriod,0,MODE_SMA,Price,i+k+1);
            if(rel>0) sump+=rel;
            else      sumn-=rel;
           }
         positive=sump/RSIPeriod;
         negative=sumn/RSIPeriod;
      
      PosBuffer[i]=positive;
      NegBuffer[i]=negative;
      if(negative==0.0) RSIBuffer[i]=0.0;
      else RSIBuffer[i]=100.0-100.0/(1+positive/negative);
       
      i--;
     }
     int total=0;
     for (i=Bars-RSIPeriod-BBPeriod-1;i>=0;i--)
     {
     UpBuffer[i]=iBandsOnArray(RSIBuffer,total,BBPeriod,2,0,MODE_UPPER,i);
     DnBuffer[i]=iBandsOnArray(RSIBuffer,total,BBPeriod,2,0,MODE_LOWER,i);
     BBBuffer[i]=0.5*(UpBuffer[i]+DnBuffer[i]);
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Recommend