Drawing a Histogram on the Chart

 

I was wondering how we can draw a histogram on the chart or rather cover the candles with a specific colour. For example I'm trying to cover white candles with green when the white candle is longer than 15 pips. Here is the code I've written and I don't know what's wrong with it. Any ideas?

//+------------------------------------------------------------------+
//|                                                 Colour_White.mq4 |
//+------------------------------------------------------------------+
#property copyright "Alireza Parsai"
#property link      "http://www.cadpanel.com"
 
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Green
//---- input parameters
extern double       Span=15.0;
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 2, Green);
   SetIndexBuffer(0,ExtMapBuffer1);
   
   //SetIndexDrawBegin(0,10);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   if (counted_bars<0)
      return(-1);
      else counted_bars--;
      
   int i=Bars-counted_bars;
   
   while (i>=0)
   {
      double _close, _open, _difference;
      
      _close=Close[i];
      _open=Open[i];
      _difference=_close-_open;
      
      if ((_difference>0)&&(_difference>Span*Point))
         {
            ExtMapBuffer1[i]=_open;
            Comment("Bar Lenght:",ExtMapBuffer1[i]);
         }
         else ExtMapBuffer1[i]=0.0;
        
      i--;
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+


Thanks in advance
 

You need for 2 indicator buffers to draw histogram on the main chart.

First buffer for open, second buffer for close prices

 
stringo wrote:

You need for 2 indicator buffers to draw histogram on the main chart.

First buffer for open, second buffer for close prices

Thanks very much. It worked.
 
stringo wrote:

You need for 2 indicator buffers to draw histogram on the main chart.

First buffer for open, second buffer for close prices


How to set 2 buffer(start buffer and end buffer)??

I need drew 2 histogram on each bar.
 

See Heiken Ashi custom indicator. 'Heiken Ashi' 2 histograms are drawn.

 
You may want to see this : https://www.mql5.com/en/forum/102203 and https://www.mql5.com/en/articles/1497 . Hey, cool first name, Alireza.
 
Slava:

You need for 2indicator buffers to draw histogram on the main chart.

First buffer for open, second buffer for close prices

Hello Brother, is it the same way to use it when its on expert advisor not indicator?

 
chipNdale: is it the same way to use it when its on expert advisor not indicator?
  1. Don't resurrect old threads without a very good reason. A lot has changed since Build 600 and Higher. 2014.02.03

  2. EAs do not have buffers. You'll have to create individual objects of OBJ_TREND
 
William Roeder:
  1. Don't resurrect old threads without a very good reason. A lot has changed since Build 600 and Higher. 2014.02.03

  2. EAs do not have buffers. You'll have to create individual objects of OBJ_TREND

Thanks WIlliam so sorry about point number one.

 
William Roeder:
  1. Don't resurrect old threads without a very good reason. A lot has changed since Build 600 and Higher. 2014.02.03

  2. EAs do not have buffers. You'll have to create individual objects of OBJ_TREND
I have the same quesitno as OP, what changed since 2014 ?
 
Enau: I have the same quesitno as OP, what changed since 2014 ?

A lot. For example:

  1. Can't have dots in variable names

  2. Data Structure in MetaTrader 4 Build 600 and Higher - MQL4 Articles 2014.02.03

  3. New/delete/class/char/etc. are keywords since build 600 and Higher — 2014.02.03

  4. There has been zero proof that any ex4/5 can be decompiled since Build 600+ 2014.02.03
              Upcoming MetaTrader 4 and MQL4 Upgrades - Big Changes Are Underway (MetaQuotes Software Corp.) - MQL4 programming forum 2013.07.24
              Code Protection: New MQL4 language(Build 600+) decompilation protection and other crack techniques. (Macos Silva) - MQL4 programming forum - Page 2 2014.02.19

Reason: