This script is designed to function as a visual market analysis tool for the MetaTrader platform. Its primary objective is to identify and highlight specific price "breakouts" based on the highest highs and lowest lows of a designated number of previous price bars (defaulting to three).
Core Operational Logic
The script works by constantly scanning the historical price data to determine the local momentum of the market. It establishes a "swing" state—essentially a toggle between bullish and bearish tendencies—based on the following logic:
1. Identifying Thresholds For every point on the chart, the tool looks back at a specific window of bars (the "Lines Break" parameter). It automatically calculates two key levels:
- The highest peak reached during that window.
- The lowest trough reached during that window.
2. Detecting the Shift The logic is designed to wait for price to breach these established boundaries.
- If the current price drops below the lowest point of the previous window, the tool registers a downward swing.
- If the current price rises above the highest point of the previous window, the tool registers an upward swing.
3. Visual Representation Once a shift in direction is detected, the script applies a visual indicator to the chart:
- When the market is in an upward swing, it marks the high and low points of the current price action.
- When the market is in a downward swing, it flips the logic to highlight the price movement in a way that emphasizes the bearish trend.
Summary for Traders
In simple terms, this tool acts as an automated "breakout" monitor. Instead of you having to manually look back at the last few candles to see if the current price has surpassed a recent high or low, the script does this calculations instantly. It identifies when the price has moved beyond the immediate "noise" of the previous bars and provides a visual histogram to help you see which direction the momentum is currently leaning.
//+------------------------------------------------------------------+
//| 3LineBreak.mq4 |
//| Copyright © 2004, Poul_Trade_Forum |
//| Aborigen |
//| http://forex.kbpauk.ru/ |
//+------------------------------------------------------------------+
#property copyright "Poul Trade Forum"
#property link "http://forex.kbpauk.ru/"
#property indicator_chart_window
#property indicator_buffers 2
//---- input parameters
extern int Lines_Break=3;
//---- buffers
double HighBuffer[];
double LowBuffer[];
double VALUE1,VALUE2,Swing=1,OLDSwing;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,2,Blue);
SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,2,Red);
SetIndexBuffer(0,HighBuffer);
SetIndexBuffer(1,LowBuffer);
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
//---- name for DataWindow and indicator subwindow label
short_name="3LineBreak";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,10);
SetIndexDrawBegin(1,10);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted(),i,shift;
//---- TODO: add your code here
if (counted_bars==0) counted_bars=Lines_Break+1;
i=(Bars-counted_bars);
for (shift=i; shift>=0;shift--)
{
OLDSwing=Swing;
VALUE1=High[Highest(NULL,0,MODE_HIGH,Lines_Break,shift+1)];
VALUE2= Low[Lowest(NULL,0,MODE_LOW,Lines_Break,shift+1)];
if (OLDSwing==1 && Low[shift]<VALUE2) Swing=-1;
if (OLDSwing==-1 && High[shift]>VALUE1 ) Swing=1;
if (Swing==1)
{ HighBuffer[shift]=High[shift]; LowBuffer[shift]=Low[shift]; }
if (Swing==-1)
{ LowBuffer[shift]=High[shift]; HighBuffer[shift]=Low[shift]; }
//----
}
return(0);
}
//+------------------------------------------------------------------+
Comments