Range_v1
Download scriptThis tool is designed to help traders visualize and analyze market volatility by tracking the size of price movements over time. Instead of focusing on the specific direction of the price (up or down), it focuses entirely on the "range"—the distance between the highest and lowest points reached during a specific period.
How the Logic Works
The script examines each candle on your chart and compares its total height (the range) to the height of the previous candle. It then categorizes every movement into one of three distinct types:
- Expanding Range (Higher): If the current candle’s price range is larger than the one before it, the tool flags this as an increase in volatility.
- Contracting Range (Lower): If the current candle’s price range is smaller than the previous one, the tool identifies this as a decrease in volatility.
- Consistent Range (No Change): If the price range remains exactly the same as the previous period, it marks this as a neutral move with no change in volatility.
Visual Presentation
The script provides a clear visual output in a separate window beneath your main chart using a color-coded histogram:
- Green highlights periods where the range is increasing.
- Red (FireBrick) highlights periods where the range is decreasing.
- Black identifies periods where the range remains unchanged.
Additionally, the tool dynamically places a text label on the chart that displays the exact numerical value of the current price range in real-time. This allows you to see at a glance whether the market is becoming more active or settling into a quieter phase.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| Range V1.0 |
//| |
//| Copyright © 2005, Jason Robinson |
//| (jasonrobinsonuk, jnrtrading) |
//| http://www.jnrtrading.co.uk |
//| |
//| THIS VERSION IS FROM MY WEBSITE |
//| (unless it has been posted by me on a forum) |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Jason Robinson"
#property link "http://www.jnrtrading.co.uk"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 FireBrick
#property indicator_color3 Black
#property indicator_minimum 0
double higher[];
double lower[];
double noChange[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0, higher);
SetIndexLabel(0, "Higher");
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1, lower);
SetIndexLabel(1, "Lower");
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2, noChange);
SetIndexLabel(2, "No Change");
IndicatorShortName("Range (H L nC)");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i = 0; i <= limit; i++) {
if (High[i] - Low[i] > High[i+1] - Low[i+1]) {
higher[i] = High[i] - Low[i];
lower[i] = 0;
noChange[i] = 0;
}
else if (High[i] - Low[i] < High[i+1] - Low[i+1]) {
lower[i] = High[i] - Low[i];
higher[i] = 0;
noChange[i] = 0;
}
else {
noChange[i] = High[i] - Low[i];
lower[i] = 0;
higher[i] = 0;
}
ObjectDelete("Range");
ObjectCreate("Range", OBJ_TEXT, 1, Time[0], High[0] - Low[0]);
ObjectSetText("Range", " " + DoubleToStr(High[0] - Low[0], 4), 10, "Verdana", Black);
}
return(0);
}
Comments