BBflat

This script is designed as a custom technical analysis tool for the MetaTrader trading platform. Its primary purpose is to visualize specific market dynamics by calculating and plotting four distinct data points simultaneously in a separate window below the main price chart.

Core Logic and Functionality

The script operates by analyzing historical price data based on user-defined parameters, such as the lookback period (the amount of past data to consider), the calculation method, and the price type. It processes these inputs to generate four distinct visual layers:

1. Standard Deviation Boundaries (Volatility Tracking) The tool calculates the "Standard Deviation" of the market, which is a mathematical way to measure how much the price is fluctuating away from its average.

  • It plots a positive boundary and a negative boundary based on a user-defined multiplier.
  • These two lines effectively create an "envelope" or "channel." When the market stays within these lines, it is considered to be behaving normally; when the price pushes toward or beyond these boundaries, it signals increased volatility or potential overextended movements.

2. Price Variance (Distance from Average) In addition to the volatility boundaries, the script calculates the specific distance between the current closing price and a Moving Average (a smoothed average of price history).

  • This helps traders visualize how "stretched" the current price is compared to its recent trend.
  • By tracking this difference, the tool allows you to see if the market is currently over-extended in one direction or if it is returning toward its mean value.

Visual Representation

The script organizes these calculations into four separate visual components:

  • Upper and Lower Limits: Represented by the positive and negative deviation lines (the "envelope").
  • Distance Metric: A fourth line that tracks the numerical gap between the current price and the moving average.

By combining these elements, the tool provides a comprehensive look at market momentum and volatility, helping users identify whether the market is trending steadily or experiencing erratic price swings.

Indicators Used
Moving average indicatorStandard Deviation indicator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
BBflat
//+------------------------------------------------------------------+
//|                                                       BBflat.mq4 |
//|                                                          by Raff |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Aqua
#property indicator_style1 2
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Blue

extern int period=9;
extern int shift=0;
extern int method=0;
extern int price=0;
extern double deviation=1.5;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer4);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
     int limit, counted_bars=IndicatorCounted();
     double ima, std;
     if(counted_bars<0) return(-1);
     if(counted_bars>0) counted_bars--;
     limit=Bars-counted_bars;
     for(int i=0; i<limit; i++)
       {
	    ima=iMA(NULL,0,period,shift,method,price,i);
       std=deviation*iStdDev(NULL,0,period,shift,method,price,i);
		 ExtMapBuffer1[i]=0;
       ExtMapBuffer2[i]=std;
       ExtMapBuffer3[i]=-std;
       ExtMapBuffer4[i]=Close[i]-ima;
       }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments