# Bar size expert

307

Hello experts,

I´ve been trying to develop my own expert but it is harder than I thought.

What I want is this:

I want the expert to calculate the average bar size of the last 15 periods, if the last bar is larger than the average and it is a bull bar then color it in blue, if it is a bear bar color it in red. The size of each bar is calculated measuring the high and the low of each bar, for instance, high: 1.2340 low: 1.2328, then the size of that bar would be 12 pips.

I believe programming this expert is easy, I am just not a good programmer.

Any help will be greatly appreciated.

Regards,

307

Any ideas?

100

Any ideas?

As far as I know, it is difficult to change colors of bars or candlesticks.
Your calculations seem to be easy, but redrawing bars/candlesticks is a problem.
307

Hello JosTheelen,

Thank you very much for your response.

I see, and how about an arrow to indicate the cadndlestick is larger than the average?

Thank you again for your help.

Regards,

307

Hello JosTheelen,

Thank you very much for your response.

I see, and how about an arrow to indicate the cadndlestick is larger than the average?

Thank you again for your help.

Regards,

307

Hello back

Anyone willing to help me?

100

Hello back

Anyone willing to help me?

I will look at it these days. Is the last bar part of those 15 periods or just the 16'th?
100

JosTheelen wrote:
Hello back

Anyone willing to help me?

I will look at it these days. Is the last bar part of those 15 periods or just the 16'th?

No response??
14802

Average of (High - Low) == Average(High)-Average(Low)
Thus, we having this simple indicator:

```//+------------------------------------------------------------------+
//|                                                      BarSize.mq4 |
//|                                        https://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);
}
//+------------------------------------------------------------------+```

100

Thanks Rosh. I thought it was difficult to redraw those bars, but it seems easy to do.