Results 1 to 3 of 3

Thread: Bollinger bands

  1. #1
    Standard Member Array
    Join Date
    Jul 2010
    Location
    Sweden
    Posts
    17
    Thanks
    31
    Thanked 0 Times in 0 Posts

    Bollinger bands

    I would like to attach bollinger bands based on a 20 period smoothed moving average on the mt4. I suppose that the standard bb indicator that comes with mt4 is based on a exponential moving average or am I wrong? If it is, can i found a custom bb indicator based on the smoothed moving average somewhere?
    Last edited by zktier; 07-19-2010 at 07:32 PM.

  2. " "
  3. #2
    Silver Member Array
    Join Date
    May 2009
    Posts
    164
    Thanks
    276
    Thanked 84 Times in 34 Posts
    //+------------------------------------------------------------------+
    //| Bands.mq4 |
    //| Copyright 2005, MetaQuotes Software Corp. |
    //| http://www.metaquotes.net/ |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2005, MetaQuotes Software Corp."
    #property link "http://www.metaquotes.net/"

    #property indicator_chart_window
    #property indicator_buffers 3
    #property indicator_color1 LightSeaGreen
    #property indicator_color2 LightSeaGreen
    #property indicator_color3 LightSeaGreen
    //---- indicator parameters
    extern int BandsPeriod=20;
    extern int BandsShift=0;
    extern double BandsDeviations=2.0;
    //---- buffers
    double MovingBuffer[];
    double UpperBuffer[];
    double LowerBuffer[];
    //+------------------------------------------------------------------+
    //| Custom indicator initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    //---- indicators
    SetIndexStyle(0,DRAW_LINE);
    SetIndexBuffer(0,MovingBuffer);
    SetIndexStyle(1,DRAW_LINE);
    SetIndexBuffer(1,UpperBuffer);
    SetIndexStyle(2,DRAW_LINE);
    SetIndexBuffer(2,LowerBuffer);
    //----
    SetIndexDrawBegin(0,BandsPeriod+BandsShift);
    SetIndexDrawBegin(1,BandsPeriod+BandsShift);
    SetIndexDrawBegin(2,BandsPeriod+BandsShift);
    //----
    return(0);
    }
    //+------------------------------------------------------------------+
    //| Bollinger Bands |
    //+------------------------------------------------------------------+
    int start()
    {
    int i,k,counted_bars=IndicatorCounted();
    double deviation;
    double sum,oldval,newres;
    //----
    if(Bars<=BandsPeriod) return(0);
    //---- initial zero
    if(counted_bars<1)
    for(i=1;i<=BandsPeriod;i++)
    {
    MovingBuffer[Bars-i]=EMPTY_VALUE;
    UpperBuffer[Bars-i]=EMPTY_VALUE;
    LowerBuffer[Bars-i]=EMPTY_VALUE;
    }
    //----
    int limit=Bars-counted_bars;
    if(counted_bars>0) limit++;
    for(i=0; i MovingBuffer[i]=iMA(NULL,0,BandsPeriod,BandsShift,MODE_SMMA,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=MovingBuffer[i];
    while(k>=i)
    {
    newres=Close[k]-oldval;
    sum+=newres*newres;
    k--;
    }
    deviation=BandsDeviations*MathSqrt(sum/BandsPeriod);
    UpperBuffer[i]=oldval+deviation;
    LowerBuffer[i]=oldval-deviation;
    i--;
    }
    //----
    return(0);
    }
    //+------------------------------------------------------------------+

  4. #3
    Bronze Member Array
    Join Date
    Feb 2009
    Posts
    52
    Thanks
    70
    Thanked 20 Times in 6 Posts
    tq drbastem

Similar Threads

  1. Bollinger Bands-Trend Following
    By teodosy87 in forum Forex Clips and Movie Tutorial
    Replies: 4
    Last Post: 09-18-2010, 10:05 PM
  2. What Are Bollinger Bands?
    By mark04 in forum Technical Analysis
    Replies: 5
    Last Post: 09-08-2010, 08:25 PM
  3. Trading with Bollinger Bands and the ATR
    By KelvinHand in forum Forex Clips and Movie Tutorial
    Replies: 6
    Last Post: 04-07-2010, 03:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •