Code to redraw chart bars

 

Hi, I am not sure if this question is in the correct space or not (please advise if not).

Is it possible to accept the price feed in MQL5 and redraw the bars? I would like to remove the pipette data and have the pricing rounded to pips. This will make the bars a little more blocky but the aim is to remove some of the noise created by point movement.

Thanks

 
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots   1
//--- plot Open
#property indicator_label1  "Open;High;Low;Close"
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  clrRoyalBlue,clrFireBrick,clrYellow
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         OpenBuffer[];
double         HighBuffer[];
double         LowBuffer[];
double         CloseBuffer[];
double         ColorBuffer[];
//---
int digits;
double muldiv;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorSetInteger(INDICATOR_DIGITS,digits=_Digits-1);
//--- indicator buffers mapping
   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,HighBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,CloseBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,ColorBuffer,INDICATOR_COLOR_INDEX);
//---
   ChartSetInteger(ChartID(),CHART_COLOR_CHART_LINE,clrNONE);
//---
   muldiv=MathPow(10,digits);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int begin=(rates_total!=prev_calculated)?prev_calculated:prev_calculated-1;
   if(!prev_calculated)
      OpenBuffer[0]=HighBuffer[0]=LowBuffer[0]=CloseBuffer[0]=MathFloor((high[begin=1]+low[1])/2*muldiv)/muldiv;;
//---
   for(int i=begin;i<rates_total && !_StopFlag;i++)
     {
      if(rates_total!=prev_calculated)
         OpenBuffer[i]=CloseBuffer[i-1];
//---
      CloseBuffer[i]=(close[i]>OpenBuffer[i])?MathFloor(close[i]*muldiv)/muldiv:MathCeil(close[i]*muldiv)/muldiv;
      HighBuffer[i]=MathMax(OpenBuffer[i],MathMax(CloseBuffer[i],MathFloor(high[i]*muldiv)/muldiv));
      LowBuffer[i]=MathMin(OpenBuffer[i],MathMin(CloseBuffer[i],MathCeil(low[i]*muldiv)/muldiv));
//---
      ColorBuffer[i]=CloseBuffer[i]>CloseBuffer[i-1]?0:CloseBuffer[i]<CloseBuffer[i-1]?1:2;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Ernst Van Der Merwe:

Amazing. 


Thank you very much - appreciated. That is precisely what I was looking for.

 
Ernst Van Der Merwe:

Thank you, I found it while reading the foruns and I like your code.