Three Line Break_v2
Download scriptThis technical tool is designed to help traders visualize and identify structural shifts in market price movement by tracking "breaks" in specific price boundaries. Instead of simply following every minor fluctuation, the script identifies significant changes in momentum based on a user-defined period.
Core Operational Logic
The script operates by analyzing the relationship between the opening and closing prices of candles to determine the current market trend. It categorizes price action into two primary directions: upward (bullish) and downward (bearish).
To maintain clarity, the tool creates "boundary boxes" based on a specific number of previous periods (the Break Period). These boxes act as a memory for the market's recent highs and lows. The logic functions as follows:
- Trend Identification: The tool looks at whether the price is moving up or down. If a candle closes higher than it opened, it leans toward an upward trend; if it closes lower, it leans downward.
- Break Detection: The script constantly monitors the current closing price against the boundaries of these "boxes."
- In an uptrend, the tool looks for a significant drop where the price falls below a specific previous low.
- In a downtrend, the tool looks for a significant rise where the price climbs above a specific previous high.
- Dynamic Updating: Once a "break" is detected—meaning the price has pushed past the established boundary—the script resets its logic. It flips the trend direction and updates the boundaries using the new price data. This ensures that the tool is always reacting to the most recent structural shift rather than outdated information.
Visual Representation
The results are displayed on your chart as two distinct color-coded histograms (Blue and Red). These visual elements represent the high and low points of the detected market structure. By observing these lines, a trader can more easily see where the price is currently "contained" and at what point it has officially broken out into a new trend direction.
In essence, this script filters out the "noise" of minor price movements to highlight the major structural transitions in the market, allowing for a clearer view of current price dynamics.
//+------------------------------------------------------------------+
//| Three Line Break.mq4 |
//| Equipe Forex |
//| http://www.equipeforex.com |
//+------------------------------------------------------------------+
#property copyright "Equipe Forex"
#property link "http://www.equipeforex.com"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int BreakPeriod=5;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,ExtMapBuffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i, j, CurrentTrend;
bool CalculateLowHigh=true;
double Value1, Value2, LowestBox, HighestBox;
double BoxHigh[], BoxLow[];
//----
ArrayResize(BoxHigh, BreakPeriod + 2);
ArrayResize(BoxLow, BreakPeriod + 2);
//
ArrayInitialize(BoxHigh, -1000);
ArrayInitialize(BoxLow, 1000);
//
i=Bars-1;
if (Close[i] < Open[i])
{
CurrentTrend=-1;
BoxHigh[BreakPeriod + 1]=Open[i];
BoxLow[BreakPeriod + 1]=Close[i];
Value1=Low[i];
Value2=High[i];
}
else
{
CurrentTrend=1;
BoxHigh[BreakPeriod + 1]=Close[i];
BoxLow[BreakPeriod + 1]=Open[i];
Value1=High[i];
Value2=Low[i];
}
ExtMapBuffer1[i]=Value1;
ExtMapBuffer2[i]=Value2;
i--;
while(i>=0)
{
Value1=0;
Value2=0;
//----
if (CalculateLowHigh)
{
LowestBox=BoxLow[ArrayMinimum(BoxLow)];
HighestBox=BoxHigh[ArrayMaximum(BoxHigh)];
CalculateLowHigh=false;
}
if (((CurrentTrend > 0) && (Close[i] < LowestBox)) ||
(CurrentTrend < 0) && (Close[i] < BoxLow[BreakPeriod + 1]))
{
Value1=Low[i];
Value2=High[i];
//
shiftArrays(BoxLow, BoxHigh);
//
BoxHigh[BreakPeriod + 1]=BoxLow[BreakPeriod + 1];
BoxLow[BreakPeriod + 1]=Close[i];
//
CurrentTrend=-1;
CalculateLowHigh=true;
}
else if (((CurrentTrend < 0) && (Close[i] > HighestBox)) ||
(CurrentTrend > 0) && (Close[i] > BoxHigh[BreakPeriod + 1]))
{
Value1=High[i];
Value2=Low[i];
//
shiftArrays(BoxLow, BoxHigh);
//
BoxLow[BreakPeriod + 1]=BoxHigh[BreakPeriod + 1];
BoxHigh[BreakPeriod + 1]=Close[i];
//
CurrentTrend=1;
CalculateLowHigh=true;
}
ExtMapBuffer1[i]=Value1;
ExtMapBuffer2[i]=Value2;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| shift array function |
//+------------------------------------------------------------------+
void shiftArrays(double& array1[], double& array2[])
{
for(int j=0; j<=BreakPeriod; j++)
{
array1[j]=array1[j + 1];
array2[j]=array2[j + 1];
}
}
//+------------------------------------------------------------------+
Comments