InsideBar
Download scriptThis tool is designed to analyze price action on a trading chart by identifying specific patterns of "contraction" and "momentum shifts." It scans historical and real-time data to highlight moments where the market's volatility decreases significantly, which can often precede a significant breakout or trend reversal.
The logic operates based on two distinct identification methods:
1. The "Inside Bar" Pattern
The script first looks for a classic price action formation known as an Inside Bar. This occurs when the entire range of a current candle (the distance between its highest and lowest points) is completely contained within the range of the previous candle. To the human eye, this represents a period of consolidation where the market is "resting" or indecisive before choosing a new direction.
2. Relative Volatility Comparison
Beyond just looking at the previous candle, the script performs a more rigorous statistical check. It measures the "body size" (the difference between the opening and closing prices) of the current candle and compares it against the body sizes of the five preceding candles. If the current candle has a smaller body than all five of those candles combined, the script flags it as a point of significant contraction.
Visual and Audible Alerts
When the script detects that a new candle meets either of the criteria above—meaning the market is showing a notable decrease in movement—it triggers several simultaneous actions:
- Visual Marking: It places indicators on the chart to highlight these specific candles.
- On-Screen Notification: A text comment appears on the chart displaying the current time and confirming that an "Inside bar" has been detected.
- Audio Alert: The system plays a notification sound to grab the trader's attention immediately.
Summary for Traders
Essentially, this script acts as a filter for market noise. Instead of alerting you to every minor price movement, it focuses exclusively on moments where the market is "coiling up." By identifying these periods of low volatility and small candle bodies, the tool helps traders spot potential setups where a large breakout may be imminent.
//+------------------------------------------------------------------+
//| InsideBar.mq4 |
//| Copyright © 2006, Eli Hayun |
//| http://www.elihayun.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Eli Hayun"
#property link "http://www.elihayun.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int NumPrevBars=4;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY, 4);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY, 4);
SetIndexBuffer(2,ExtMapBuffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for (int i=0; i<limit; i++)
{
ExtMapBuffer1[i] = 0; ExtMapBuffer2[i] = 0;
if ( (Low[i] > Low[i+1]) && (High[i] < High[i+1]))
{
ExtMapBuffer1[i] = Close[i];
ExtMapBuffer2[i] = Open[i];
}
double r0 = MathAbs(Open[i] - Close[i]);
double r1 = MathAbs(Open[i+1] - Close[i+1]);
double r2 = MathAbs(Open[i+2] - Close[i+2]);
double r3 = MathAbs(Open[i+3] - Close[i+3]);
double r4 = MathAbs(Open[i+4] - Close[i+4]);
if (r0 < r1 && r0 < r2 && r0 < r3 && r0 < r4)
{
ExtMapBuffer1[i] = Close[i];
ExtMapBuffer2[i] = Open[i];
}
}
if (ExtMapBuffer1[1] != 0 && NewBar())
{
Comment(TimeToStr(Time[0])," Inside bar"); Print(Symbol(), " Inside bar");
PlaySound("expert.wav");
}
//----
return(0);
}
//+------------------------------------------------------------------+
bool NewBar()
{
static datetime dt = 0;
if (dt != Time[0])
{
dt = Time[0];
return(true);
}
return(false);
}
Comments