Stretch
Download scriptThe Stretch indicator is designed to provide traders with a visual representation of price volatility and price action "expansion" by measuring the distance between the market's opening price and its highest and lowest points over a specific timeframe.
How It Works
Instead of looking at the total range of a candle (the distance from high to low), this script focuses specifically on the movement relative to the Open price. For every bar on your chart, the logic performs the following steps:
- Distance Calculation: It examines each individual candle within a user-defined period. It calculates two specific distances:
- The distance from the Open to the High.
- The distance from the Open to the Low.
- Selection Logic: The script compares these two distances and selects only the smaller of the two. By choosing the smaller value, the indicator filters out "extreme" outliers and focuses on the primary direction of the price movement relative to where the candle started.
- Averaging (The Histogram): It takes these selected values over a set number of bars and calculates their average. This result is displayed as a Histogram. A taller histogram indicates that, on average, the price is moving further away from its opening points during that period.
Trend Smoothing
To make this data easier to read and to filter out "noise" (minor, jagged movements), the script applies a secondary calculation:
- Moving Average: It takes the values generated by the histogram and runs a Moving Average over them. This is displayed as a dotted line.
What This Tells You
By viewing these two components together—the Histogram and the Dotted Line—you can identify the intensity of price movement. The Histogram shows you the raw "Stretch" of the market in real-time, while the Dotted Line provides a smoothed trend of that stretch, helping you distinguish between temporary spikes and sustained momentum.
//+------------------------------------------------------------------+
//| Stretch.mq4
//| Copyright http://www.pointzero-trading.com
//+------------------------------------------------------------------+
#property copyright "Copyright © Pointzero-trading.com"
#property link "http://www.pointzero-trading.com"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 MediumSeaGreen
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 1
#property indicator_style2 STYLE_DOT
#define MaMethod 2
//--External variables
extern int StPeriod = 10;
extern int AvPeriod = 12;
//-- Buffers
double FextMapBuffer1[];
double FextMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//|------------------------------------------------------------------|
int init()
{
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0, FextMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,FextMapBuffer2);
IndicatorShortName("Stretch ("+ StPeriod +","+ AvPeriod +")");
Comment("Copyright © http://www.pointzero-trading.com");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
// Start, limit, etc..
int start = 1;
int limit;
int counted_bars = IndicatorCounted();
// nothing else to do?
if(counted_bars < 0)
return(-1);
// do not check repeated bars
limit = Bars - 1 - counted_bars;
// Iteration
for(int pos = limit; pos >= start; pos--)
{
// Stretch for today
double sum = 0;
FextMapBuffer1[pos] = EMPTY_VALUE;
for(int i = 0; i < StPeriod; i++)
{
double oh = MathAbs(High[pos+i] - Open[pos+i]);
double ol = MathAbs(Open[pos+i] - Low[pos+i]);
if(ol < oh) sum += ol; else sum+= oh;
}
FextMapBuffer1[pos] = sum / StPeriod;
}
for(pos = limit; pos >= start; pos--) FextMapBuffer2[pos] = iMAOnArray(FextMapBuffer1, Bars, AvPeriod, 0, MaMethod, pos);
return(0);
}
Comments