StretchBreakoutChannel
Download scriptThis tool is designed to provide traders with a visual representation of potential price boundaries based on historical volatility and specific market "stretches." It helps identify levels where the price might be reaching an extreme point, allowing for a clearer understanding of potential breakout zones or reversal areas.
How the Logic Works
The indicator operates by analyzing daily price action to establish a dynamic range around the opening price of each day. Here is the step-by-step breakdown of its logic:
1. Data Source and Timeframe Analysis Even though you may be viewing the chart on various shorter timeframes (like 1-hour or 15-minute charts), the indicator specifically looks at Daily (D1) data. It synchronizes this daily information with your current view, ensuring that the boundaries remain consistent regardless of which specific minute you are looking at during the day.
2. Calculating the "Stretch" Value The core engine of this script relies on an external calculation called a "Stretch." It takes a user-defined period (the lookback timeframe) to measure how far the price has moved or deviated from its norm. This value represents the intensity of the current market movement.
3. Establishing the Boundary Channels Once the "Stretch" value is identified for a specific day, the script calculates two distinct lines based on that day's opening price:
- The Upper Bound: The script adds the Stretch value to the daily opening price.
- The Lower Bound: The script subtracts the Stretch value from the daily opening price.
4. Visual Representation The result is a channel displayed directly on your chart. These two lines act as dynamic "fences." When the market price approaches these lines, it signifies that the price has moved a significant distance from the daily open relative to recent volatility.
Key Takeaway for Traders
Instead of using static horizontal lines, this logic provides a reactive channel. Because the "Stretch" is calculated based on specific periods, the width of the channel expands or contracts automatically depending on how volatile the market is behaving. It serves as a visual guide to help identify when a trend is becoming overextended.
//+------------------------------------------------------------------+
//| StretchBreakoutChannel.mq4
//| Copyright http://www.pointzero-trading.com
//+------------------------------------------------------------------+
#property copyright "Copyright © Pointzero-trading.com"
#property link "http://www.pointzero-trading.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_SOLID
//-- External variables
extern int StPeriod = 10;
//-- Buffers
double FextMapBuffer1[];
double FextMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//|------------------------------------------------------------------|
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0, FextMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,FextMapBuffer2);
IndicatorShortName("Stretch Breakout Channel ("+ StPeriod +")");
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 = 0;
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--)
{
int dshift = iBarShift(Symbol(), PERIOD_D1, Time[pos], false);
double stretch = iCustom(Symbol(), PERIOD_D1, "Stretch", StPeriod, 0, dshift+1);
double OPEN = iOpen(Symbol(), PERIOD_D1, dshift);
FextMapBuffer1[pos] = OPEN + stretch;
FextMapBuffer2[pos] = OPEN - stretch;
}
return(0);
}
Comments