Compiler Warning "indicator buffers amount is less than needed"

 

Why as I getting this error?

Is it because:

#property indicator_buffers 6
#property indicator_plots   2

But I have:

#property indicator_type1   DRAW_COLOR_CANDLES

and

#property indicator_color1  clrRed, clrGreen


So I am using:

  • Plot 1
    • 4 buffers for the candles
    • 1 buffer for the colour index
  • Plot 2
    • 1 buffer for the 2nd line plot
There are a total of 6 buffers which are all utilised with 5 used for the 1st plot and 1 used for the 2nd plot.
 

Just a tip: create an indicator template using the 'MQL5 Wizard':


 

Step by step:

 ->   -> 


Result:

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_plots   2
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  clrRed,clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrLimeGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters
input int      Input1=9;
//--- indicator buffers
double         Label1Buffer1[];
double         Label1Buffer2[];
double         Label1Buffer3[];
double         Label1Buffer4[];
double         Label1Colors[];
double         Label2Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer1,INDICATOR_DATA);
   SetIndexBuffer(1,Label1Buffer2,INDICATOR_DATA);
   SetIndexBuffer(2,Label1Buffer3,INDICATOR_DATA);
   SetIndexBuffer(3,Label1Buffer4,INDICATOR_DATA);
   SetIndexBuffer(4,Label1Colors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(5,Label2Buffer,INDICATOR_DATA);
   
//---
   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
   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
Test.mq5  3 kb
 
Suminda Dharmasena: Why as I getting this error? Is it because: But I have: and So I am using: Plot 1: 4 buffers for the candles, 1 buffer for the colour index; Plot 2: 1 buffer for the 2nd line plot. There are a total of 6 buffers which are all utilised with 5 used for the 1st plot and 1 used for the 2nd plot.

You may say that, but your code could be doing something different. Unless you show you OnInit() code as well, we will not be able to confirm the reason.

 
Fernando Carreiro #:

You may say that, but your code could be doing something different. Unless you show you OnInit() code as well, we will not be able to confirm the reason.

The initialisation is a bit complex

//--- create HAPrice object
CHAPrice HAPrice(true);
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   Print(__FILE__, ": MQL Build - ", __MQLBUILD__, ", Date Time - ", __DATETIME__);
//---
//Define the number of color indexes, used for a graphic plot
   PlotIndexSetInteger(0, PLOT_COLOR_INDEXES, 2);
//Set color for each index
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, 0, clrRed); //Zeroth index -> Red
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, 1, clrGreen); //First index  -> Green
//---
   return(INIT_SUCCEEDED);
  }
   CBufferUtils      HAOpen;
   CBufferUtils      HAHigh;
   CBufferUtils      HALow;
   CBufferUtils      HAClose;
   CBufferUtils      dir;
   CBufferUtils      HAAvg;

                     CHAPrice(const bool visible = false):
                     HAOpen("HAOpen", visible ? INDICATOR_DATA : INDICATOR_CALCULATIONS),
                     HAHigh("HAHigh", visible ? INDICATOR_DATA : INDICATOR_CALCULATIONS),
                     HALow("HALow", visible ? INDICATOR_DATA : INDICATOR_CALCULATIONS),
                     HAClose("HAClose", visible ? INDICATOR_DATA : INDICATOR_CALCULATIONS),
                     dir("dir", INDICATOR_COLOR_INDEX),
                     HAAvg("HAAvg", visible ? INDICATOR_DATA : INDICATOR_CALCULATIONS)
     {
      Print(__FILE__, ": MQL Build - ", __MQLBUILD__, ", Date Time - ", __DATETIME__);
     };
private:
   static int        count;
public:
                     CBufferUtils(const string TheName, const ENUM_INDEXBUFFER_TYPE BufferType = INDICATOR_CALCULATIONS):
                     index(count),
                     name(TheName),
                     type(BufferType)
     {
      ArraySetAsSeries(buffer, false);
      SetIndexBuffer(count++, buffer, BufferType);
      Print("Index: ", index, ", Name: ", name, ", Type: ", EnumToString(type));
      Print(__FILE__, ": MQL Build - ", __MQLBUILD__, ", Date Time - ", __DATETIME__);
     }
int CBufferUtils::count = 0;
 
Suminda Dharmasena #: The initialisation is a bit complex

You don't seem to be declaring any buffers in your OnInit(), and the code snippets you provided are insufficient for as to analyse the issue.

If you are not comfortable posting your entire code, then you will have to use the debugger or prints to log, in order to see where the problem may be.

 
Suminda Dharmasena # :


Read my posts above - you should create an indicator template using the 'MQL5 Wizard' - in this case you will not have errors with declaring indicator styles and buffers.

 
Fernando Carreiro #:

You don't seem to be declaring any buffers in your OnInit(), and the code snippets you provided are insufficient for as to analyse the issue.

If you are not comfortable posting your entire code, then you will have to use the debugger or prints to log, in order to see where the problem may be.

The Buffers are initialised in the constructor of:

CHAPrice HAPrice(true);
 
Suminda Dharmasena #: The Buffers are initialised in the constructor of:
No, it cannot be in the constructors. It has to be done separately and the method called from the OnInit() and in the correct sequence.
Reason: