Download MetaTrader 5

Request for help: HLC bars on MT5

To add comments, please log in or register
All activity of the MQL5.community members is displayed on a single page!
caillie
4
caillie 2011.04.10 15:19 

Hi, appreciate help on modification of this HLC bars

I have manage to modify this simple indicator that draws color bars  mt5 to draw HLC bars base on this criteria...

1:Draw only high, low & close but not the open.

2:color the bars only base on current close of bar to previous close price..instead of the usual open & close.

Current bug: as i only commented the open price in the code..the open price occasionally appears as artifacts on the screen.


My lack of programing knowledge can only go so far & appreciate of experience folks out there could help me to modify a little bit so as to;


1:Prevent the the open price from drawing (DRAW_NONE or something)

2:& to include a new color if close of previous bar is same level as current close.

Additionally (not essential);

is to include an option to draw for example last 100 bars...

Appreciate any help on this matter...

tks ahead.

below showing occasional open price artifacts...


//+------------------------------------------------------------------+
//|                                                    ColorBars.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots   1 
//---- plot ColorBars
#property indicator_label1  "ColorBars HLC" 
#property indicator_type1   DRAW_COLOR_BARS
#property indicator_color1  Blue,Red
#property indicator_label1  "High;Low;Close"
//--- indicator buffers
//double ExtOpenBuffer[];
double ExtHighBuffer[];
double ExtLowBuffer[];
double ExtCloseBuffer[];
double ExtColorsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicators
   //SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
//--- don't show indicator data in DataWindow
   PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
                
  {
//--- auxiliary variables
   int  i=0;
   bool close_up=true;
//--- set position for beginning
   if(i<prev_calculated) i=prev_calculated-1;
//--- start calculations
   while(i<rates_total)
     {
      //ExtOpenBuffer[i]=open[i]; --disable open price display--
      ExtHighBuffer[i]=high[i];
      ExtLowBuffer[i]=low[i];
      ExtCloseBuffer[i]=close[i];
      //--- define volume change
      if(i>0)
        {
         if(close[i]>close[i-1]) close_up=true;
         if(close[i]<close[i-1]) close_up=false;
        }
      //--- set color
      if(close_up) ExtColorsBuffer[i]=0.0;
      else       ExtColorsBuffer[i]=1.0;
     
      //---
      i++;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
To add comments, please log in or register