RangerBB
Download scriptThe Ranger indicator is a technical analysis tool designed to help traders visualize price momentum and volatility by measuring the distance between current market prices and specific moving averages. Instead of simply following the price, this tool calculates the "gap" or "stretch" in the market to identify potential overextended movements.
How the Logic Works
The script operates through a multi-layered calculation process:
1. Measuring Market Deviation The core logic begins by calculating how far the current closing price sits away from two different moving averages simultaneously: one based on the highest prices (peaks) and one based on the lowest prices (troughs) over a specific timeframe. By combining these two distances, the indicator creates a unique value that represents the total "spread" or variance of the price relative to its recent historical average.
2. Establishing a Baseline Once this spread is calculated, the indicator tracks it over time to create a primary data line. This line essentially shows you how much the market is deviating from its normal behavior at any given moment. When the market is stable, this value remains relatively consistent; when the market becomes erratic or moves rapidly in one direction, the value shifts significantly.
3. Defining the "Ranger" Bounds To make this data actionable for a trader, the script then applies a secondary layer of analysis:
- The Center Line: It calculates an average of the spread values to create a steady baseline (the "Zero" line).
- Volatility Bands: It measures the standard deviation—a mathematical way to see how much the spread typically fluctuates. It then projects two boundaries (Upper and Lower bands) above and below the center line.
What This Means for the User
The final result is a visual channel that helps you see when the market is "overstretched."
- The Center Line represents the normal, expected movement of the price spread.
- The Upper and Lower Bands act as boundaries. When the data line pushes toward or outside of these bands, it indicates that the market's current movement is becoming extreme compared to recent history.
By observing how the price interacts with these boundaries, traders can better identify moments of exhaustion where a trend might be losing steam or where a significant reversal could occur.
//+------------------------------------------------------------------+
//| Ranger.mq4 |
//| doshur |
//| http://www.doshur.com |
//+------------------------------------------------------------------+
#property copyright "doshur"
#property link "http://www.doshur.com"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 SkyBlue
#property indicator_color2 Red
#property indicator_color3 RoyalBlue
#property indicator_color4 LimeGreen
extern int MA = 13;
extern int Mode = 1; // 0 - SMA, 1 - EMA, 2 - SMMA, 3 - LWMA
extern int Band = 20;
extern int BandMode = 1;
//---- buffers
double ExtMapBuffer1[];
double UpperBuffer[];
double LowerBuffer[];
double ZeroBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,UpperBuffer);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,LowerBuffer);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,ZeroBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i;
int counted_bars = IndicatorCounted();
double MA_UP, MA_DN, Result;
double BB, Zero;
limit = Bars - counted_bars;
//----
for(i = 0; i <= limit; i++)
{
MA_UP = Close[i] - iMA(NULL, 0, MA, 0, Mode, PRICE_HIGH, i);
MA_DN = Close[i] - iMA(NULL, 0, MA, 0, Mode, PRICE_LOW, i);
Result = MA_UP + MA_DN;
ExtMapBuffer1[i] = Result;
}
for(i = 0; i <= limit; i++)
{
BB = iStdDevOnArray(ExtMapBuffer1,0,Band,0,BandMode,i);
Zero = iMAOnArray(ExtMapBuffer1,0,Band,0,BandMode,i);
UpperBuffer[i] = Zero + BB;
LowerBuffer[i] = Zero - BB;
ZeroBuffer[i] = Zero;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments