BarSize
Download scriptThis tool is designed to help traders visualize and identify significant price movements on a trading chart by filtering out "market noise." Instead of showing every single price fluctuation, the script highlights specific candles that stand out due to their unusual size relative to recent history.
How the Logic Works
The core functionality of this indicator relies on two main steps: calculating a "normal" movement average and then identifying deviations from that average.
1. Establishing a Baseline The script looks back at a specific number of previous price bars (defined by a user-adjustable parameter). It calculates the average height of these candles based on their highest and lowest points. This creates a dynamic benchmark of what a "standard" candle size looks like in the current market condition.
2. Identifying Significant Volatility The script then examines each individual candle on the chart to see if its total size (the distance from its high point to its low point) is larger than the average it just calculated. If a candle is smaller than the average, the script ignores it. If the candle is significantly larger, it is flagged as a notable move.
3. Visual Representation Once a candle is identified as being "abnormally" large, the script captures its specific data points—the opening price, closing price, highest point, and lowest point. It then plots these values on the chart as histograms.
Practical Use
By highlighting only these oversized candles, the tool allows a trader to quickly see where high-volume activity or sudden bursts of momentum occurred. Rather than looking at a cluttered chart of minor price ticks, you can easily spot the moments where the market experienced significant expansion, helping to identify key trends or volatility shifts at a glance.
//+------------------------------------------------------------------+
//| BarSize.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
//---- input parameters
extern int ParamPer=15;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexBuffer(3,ExtMapBuffer4);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
int i,limit;
double AvereageCandle;
if (counted_bars==0) limit=Bars-ParamPer;
if (counted_bars>0) limit=Bars-counted_bars;
limit--;
for (i=limit;i>=0;i--)
{
AvereageCandle=iMA(NULL,0,ParamPer,0,MODE_SMA,PRICE_HIGH,1)-iMA(NULL,0,ParamPer,0,MODE_SMA,PRICE_LOW,1);
if (High[i]-Low[i]>AvereageCandle)
{
if (Close[i]>Open[i])
{
ExtMapBuffer1[i]=Open[i];
ExtMapBuffer2[i]=Close[i];
ExtMapBuffer3[i]=Low[i];
ExtMapBuffer4[i]=High[i];
}
else
{
ExtMapBuffer1[i]=Open[i];
ExtMapBuffer2[i]=Close[i];
ExtMapBuffer3[i]=High[i];
ExtMapBuffer4[i]=Low[i];
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments