modified-bollinger-bands_main_optpq

Modified Bollinger Bands

Download

Product Description

Very simple modification to the bollinger bands indicator, removing the middle line (moving average) and leaving only the outer support and resistance bands.

ModifiedBollingerBands.mq4 (Currently Viewing)
/* 
 * Copyright (c) 2011, 2015 TradertoolsFX
 *  
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
 
#property copyright "Copyright (c) 2011, 2015 TradertoolsFX"
#property link 	  "http://www.tradertools-fx.com"
#property description "This content is released under the terms of the MIT license (http://opensource.org/licenses/mit-license.html)."

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

// User Parameters
extern int period = 20;
extern int std_deviations = 2;
extern int shift = 0;
extern ENUM_APPLIED_PRICE applied_price = 0;

double upper_band[], lower_band[];

int init() {
   SetIndexShift(0, shift);
   SetIndexShift(1, shift);

   SetIndexBuffer(0, upper_band);
   SetIndexBuffer(1, lower_band );
  
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
  
   SetIndexLabel(0, "Upper Band");
   SetIndexLabel(1, "Lower Band");
   
   return(0);
}

int start() {
   int counted_bars = IndicatorCounted();
   if (counted_bars < 0 ) {
      return(-1);
   }
   
   if (counted_bars > 0) {
      counted_bars--;
   }
   
   int limit = Bars - counted_bars - 1;    
   
   for (int i = 0; i < limit; i++) {
      upper_band[i] = iBands(NULL, 0, period, std_deviations, 0, applied_price, MODE_UPPER, i);
      lower_band[i] = iBands(NULL, 0, period, std_deviations, 0, applied_price, MODE_LOWER, i);
   }
   
   return(0);
}