PlotIndexSetInteger(PLOT_LINE_WIDTH) does not work as expected in MQL5

 

I want to implement a DRAW_HISTOGRAM2 indicator that can hide all bars.

I use the following API to change the width.

PlotIndexSetInteger(0, PLOT_LINE_WIDTH, g_width); // g_width is from 1 to 5

I found that it reacts with 1 and 2, and if g_width is more than 2, nothing changes.

As a result, the bars can not be completely hidden, as shown below.

failed to hide bars


In the MQL4 version, I use SetIndexStyle, which allows setting g_width to 3, and all bars are hidden perfectly.

SetIndexStyle(0, DRAW_HISTOGRAM, EMPTY, g_width);


Does anyone know the reason for this behavior or have any workaround?

Thank you in advance!

Here is the code.

#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window


#property indicator_buffers 2
#property indicator_plots   1

//--- plot Body0
#property indicator_label1  "BarCover"
#property indicator_type1   DRAW_HISTOGRAM2
#property indicator_color1  clrBlack
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

//--- indicator buffers
double         CandleHigh[];
double         CandleLow[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
      SetIndexBuffer(0, CandleHigh, INDICATOR_DATA);
      SetIndexBuffer(1, CandleLow, INDICATOR_DATA);
      PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); 
      
//---
      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[])
  { 
//--- return value of prev_calculated for next call
     for(int i=prev_calculated;i<rates_total;i++) 
     { 
      CandleHigh[i]=high[i]; 
      CandleLow[i]=low[i]; 
     } 
     
     ChartRedraw(0);
     
     return(rates_total);
  }
  
int g_width = 1;
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
      if (id == CHARTEVENT_KEYDOWN)
      {
         Print("g_width:", g_width);
         PlotIndexSetInteger(0, PLOT_LINE_WIDTH, g_width);
         //SetIndexStyle(0, DRAW_HISTOGRAM, EMPTY, g_width); <-- it works fine in mql4
         
         g_width++;  
         if (g_width > 5)
         {
            g_width = 1;
         }
         ChartRedraw(0);
      }
  }
 
Your topic has been moved to the section: Technical Indicators
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Fernando Carreiro #:
Your topic has been moved to the section: Technical Indicators
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Thank you. I am new here and will post in the appropriate section next time.
 
tachigi: In the MQL4 version, I use SetIndexStyle, which allows setting g_width to 3, and all bars are hidden perfectly.
That is (or was) false on MT4.
How to fill between buffers with solid color - MQL4 programming forum (20.08.08)