True Range Bands

Download script
Author: Copyright � 2010, basisforex@gmail.com
True Range Bands

This tool is designed to provide a visual framework for understanding market trends and volatility by dynamically plotting three distinct lines on your trading chart. It helps traders identify the "heart" of the price action while establishing boundaries based on how much the price typically swings.

How the Logic Works

The script operates by calculating three primary components: a central baseline, an upper boundary, and a lower boundary.

1. The Central Baseline (Moving Average) The foundation of the indicator is a moving average. Instead of just looking at where the market closes, it calculates a balanced average by combining the highest point, the lowest point, and the closing price of each candle over a specific period. This creates a smooth, "dotted" center line that represents the equilibrium of the current price trend.

2. Measuring Market Volatility To determine how wide the outer bands should be, the script uses an "Average True Range" (ATR). This is a standard measurement of how much a currency pair moves on average over a certain timeframe. By using this, the indicator automatically expands when the market is volatile and contracts when the market is calm.

3. Dynamic Band Positioning The most unique feature of this script is how it decides which direction the "Upper" and "Lower" lines should lean. It looks at where the current price sits in relation to the central baseline:

  • Bullish Sentiment: If the current price is trading above the central line, the script assumes an upward bias. It places the Upper Band further away (multiplied by a specific deviation factor) and keeps the Lower Band closer to the center.
  • Bearish Sentiment: If the price is trading below the central line, the script shifts its logic. It pushes the Lower Band further down and keeps the Upper Band closer to the center.
  • Neutral Sentiment: If the price is exactly on the line, it defaults to a symmetrical expansion on both sides.

Summary for Traders

Essentially, this script visualizes "Price Room." It tells you where the market is currently trending (the center line) and provides a dynamic ceiling and floor that adjust automatically based on current market speed. When the price moves toward these bands, it signals that the market is reaching an extended zone relative to its recent average behavior.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each bar
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
True Range Bands
/*------------------------------------------------------------------+
 |                                             True Range Bands.mq4 |
 |                                                 Copyright © 2010 |
 |                                             basisforex@gmail.com |
 +------------------------------------------------------------------*/
#property copyright "Copyright © 2010, basisforex@gmail.com"
#property link      "basisforex@gmail.com"
//----
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 Yellow
#property indicator_color3 Yellow
//----
extern int       nPeriod     = 13;
extern double    Deviation   = 1.618;
extern int       MaShift     = 0;
//----
double MaBuffer[];
double MaTUp[];
double MaTDn[];
//+------------------------------------------------------------------+
int init()
 {
   SetIndexShift(0, MaShift);
   SetIndexShift(1, MaShift);
   SetIndexShift(2, MaShift);
//----
   SetIndexBuffer(0, MaBuffer);
   SetIndexBuffer(1, MaTUp);
   SetIndexBuffer(2, MaTDn);
//----
   SetIndexStyle(0, DRAW_LINE, STYLE_DOT);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE);
//----
   SetIndexLabel(0, "MA");
   SetIndexLabel(1, "MaUp");
   SetIndexLabel(1, "MaDn");
//----
   return(0);
 }
//+------------------------------------------------------------------+
int start()
 {
   int limit;
   double a;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
   limit = Bars - counted_bars;
   for(int i = 0; i < limit; i++)
    {
      for(int j = 0; j < nPeriod; j++)
       {
         a = a + (iHigh(NULL, 0, i + j) + iLow(NULL, 0, i + j) + iClose(NULL, 0, i + j) * 2) / 4;
       }       
      MaBuffer[i]  =  a / nPeriod;
      a = 0;
      if(iClose(NULL, 0, i) > MaBuffer[i])
       {
         MaTUp[i] = MaBuffer[i] + iATR(NULL, 0, nPeriod, i) * Deviation;
         MaTDn[i] = MaBuffer[i] - iATR(NULL, 0, nPeriod, i);
       }  
      else if(iClose(NULL, 0, i) < MaBuffer[i])
       {
         MaTDn[i] = MaBuffer[i] - iATR(NULL, 0, nPeriod, i) * Deviation;
         MaTUp[i] = MaBuffer[i] + iATR(NULL, 0, nPeriod, i);
       } 
      else if(iClose(NULL, 0, i) == MaBuffer[i])
       {
         MaTDn[i] = MaBuffer[i] - iATR(NULL, 0, nPeriod, i) * Deviation;
         MaTUp[i] = MaBuffer[i] + iATR(NULL, 0, nPeriod, i) * Deviation;
       }  
    }  
   //-----
   return(0);
 }
//+------------------------------------------------------------------+

Comments