Download MetaTrader 5
To add comments, please log in or register
Publish your article. Millions of traders are looking for good ideas!
Larry
1238
Larry 2010.09.25 03:49 

I am converting an MT4 indicator for Bollinger Bands to MT5.  I started by creating a new indicator in the editor and then going through the wizard to setup inputs and line params.  Now I am in the OnCalculate section and I want to make sure I get the MT4 to MT5 right.  Here is my code for MT4 start function, can you show me the changes I need to make to make it work for MT5?

 

      double deviation;
      double sum,oldval,newres;
   //----
      if(Bars<=BandsPeriod) return(0);
   //---- initial zero
      if(counted_bars<1)
         for(i=1;i<=BandsPeriod;i++)
           {
            Median[Bars-i]=EMPTY_VALUE;
            UpperBand[Bars-i]=EMPTY_VALUE;
            LowerBand[Bars-i]=EMPTY_VALUE;
           }
   //----
      int limit=Bars-counted_bars;
      if(counted_bars>0) limit++;
      for(i=0; i<limit; i++)
         Median[i]=iMA(NULL,0,BandsPeriod,BandsShift,MODE_SMA,PRICE_CLOSE,i);
   //----
      i=Bars-BandsPeriod+1;
      if(counted_bars>BandsPeriod-1) i=Bars-counted_bars-1;
      while(i>=0)
        {
         sum=0.0;
         k=i+BandsPeriod-1;
         oldval=Median[i];
         while(k>=i)
           {
            newres=Close[k]-oldval;
            sum+=newres*newres;
            k--;
           }
         deviation=BandsDeviations*MathSqrt(sum/BandsPeriod);
         UpperBand[i]=oldval+deviation;
         LowerBand[i]=oldval-deviation;
         i--;
        }
I will see what I can learn through the tutorials and such, just wondering if you could show me how to do a conversion process.
Bollinger Bands ®
  • votes: 14
  • 2010.01.26
  • MetaQuotes Software Corp. | English Russian Chinese Spanish Portuguese
  • www.mql5.com
The Bollinger Bands ® Indicator (BB) is similar to Envelopes. The only difference is that the bands of Envelopes are plotted a fixed distance (%) away from the moving average, while the Bollinger Bands are plotted a certain number of standard deviations away from it.
Larry
1238
Larry 2010.09.25 05:12  

Never mind, I just discovered that the iBands does what my old code used to do.  The MT4 version of bands did not have a median line, so I had this custom one that did.  Now it is standard in iBands.  Sorry.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events - Documentation on MQL5
/
To add comments, please log in or register