BB_channels_mikko_sw

Download script
Author: Mikko
BB_channels_mikko_sw

This tool is designed to provide traders with a comprehensive visual overview of market volatility and price range by analyzing Bollinger Bands over multiple timeframes simultaneously. Instead of looking at a single standard indicator, this script creates a multi-layered perspective of the market's boundaries.

Core Logic Overview

The primary objective of this script is to scan a wide range of historical data points (based on user-defined settings) to identify the highest and lowest extremes of various Bollinger Band components. It looks at three specific types of bands: Upper, Lower, and Middle (Main).

Rather than showing you just one line, the script performs a repetitive "scan" across a large window of data. For every point on your current chart, it calculates where the Upper, Lower, and Middle bands sit across a vast history of previous price movements.

Key Functional Components

  • Multi-Point Scanning: The tool does not just look at the current moment. It evaluates a range starting from a "beginning" point to an "end" point (e.g., looking back over hundreds of bars).
  • Extreme Identification: Within that large window, the logic constantly asks: "What is the highest value reached by the Upper Band?" and "What is the lowest value reached by the Lower Band?" It repeats this for all three types of bands.
  • Data Aggregation: The script tracks seven distinct data streams. These represent the maximums and minimums of the Upper, Lower, and Middle bands across the entire scanning window.
  • Dynamic Price Mapping: In addition to these boundary lines, the script maps the actual closing prices of the market so you can see how the current price interacts with these identified extremes.

How it appears on your chart

Instead of a simple moving average or a single band, this indicator creates a "channel" environment. By plotting the maximums and minimums of these bands over a wide area, it provides a visual representation of the total "trading zone."

Essentially, it tells you the boundaries of where the price has behaved most significantly over a specific historical period. This allows you to see the "outer limits" of market volatility, helping you identify whether the current price action is staying within historical norms or pushing into new territory.

Indicators Used
Bollinger bands indicator
Miscellaneous
Implements a curve of type %1
17 Views
1 Downloads
1 Favorites
BB_channels_mikko_sw
//+------------------------------------------------------------------+
//|                                        BB Channel indicator sw   |
//|                                                   (C) Mikkom     |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Mikko"
#property link      "noneOfYOurBusiness"

#property indicator_separate_window
//#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 DarkGreen
#property indicator_color2 ForestGreen
#property indicator_color3 C'255,83,17' //OrangeRed
#property indicator_color4 Red
#property indicator_color5 Aqua
#property indicator_color6 DodgerBlue
#property indicator_color7 Yellow

#property indicator_width1 3
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 3
#property indicator_style5 2
#property indicator_style6 4

double highup[];
double lowup[];
double highdown[];
double lowdown[];
double highmiddle[];
double lowmiddle[];
double priceBuffer[];

// Hourly settings
extern int begin = 20;  //24 
extern int end = 200;   //720 
extern int step = 5;   //12 
extern int deviation = 2;
extern int MaxBarsToCount   = 1200;

int init() {

   IndicatorBuffers(7);
   
   SetIndexBuffer(0, highup);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(1, lowup);     
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2, highdown);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(3, lowdown);     
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(4, highmiddle);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(5, lowmiddle);     
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(6, priceBuffer);     
   SetIndexStyle(7,DRAW_LINE);

   
   IndicatorShortName(" BBchannelsMikko "+begin+"-"+end+"("+step+")");
  
  // SetIndexDrawBegin(0, 0);  
   
   return(0);
}
  
int deinit() {
   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;
       limit= MathMin(limit,MaxBarsToCount);
   for(int i = limit; i >= 0; i--) {

      highup[i] = 0;
      lowup[i] = 100000;
      highdown[i] = 0;
      lowdown[i] = 100000;
      highmiddle[i] = 0;
      lowmiddle[i] = 100000;
      
       
      for(int j=begin; j<=end; j+=step) {
         double bbup = iBands(Symbol(),0,j,deviation,0,PRICE_OPEN,MODE_UPPER,i);
         double bbdown = iBands(Symbol(),0,j,deviation,0,PRICE_OPEN,MODE_LOWER,i);
         double bbmiddle= iBands(Symbol(),0,j,deviation,0,PRICE_OPEN,MODE_MAIN,i);

         if(bbup == 0 || bbdown == 0 || bbmiddle == 0) {
            highup[i] = 0;
            lowup[i] = 0;
            highdown[i] = 0;
            lowdown[i] = 0;
            highmiddle[i] = 0;
            lowmiddle[i] = 0;
            break;
         }

         if(bbup > highup[i])
            highup[i] = bbup;
         if(bbup < lowup[i])
            lowup[i] = bbup;

         if(bbdown > highdown[i])
            highdown[i] = bbdown;
         if(bbdown < lowdown[i])
            lowdown[i] = bbdown;

         if(bbmiddle > highmiddle[i])
            highmiddle[i] = bbmiddle;
         if(bbmiddle < lowmiddle[i])
            lowmiddle[i] = bbmiddle;
            
      }

   } 

   i=Bars-1;
   if(counted_bars>1) i=Bars-counted_bars-1;
   while(i>=0) { priceBuffer[i]=Close[i]; i--; }

   return(0);
}

Comments