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); } //+------------------------------------------------------------------+
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.
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;
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.
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);
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Why as I getting this error?
Is it because:
But I have:
and
So I am using: