PlotIndexSetXXX throw 4014 error

 
//+------------------------------------------------------------------+
//|                                                       Test01.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Arrows
#property indicator_label1  "Arrows"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrGreen
#property indicator_width1  1
//--- indicator buffers
double         ArrowsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ArrowsBuffer,INDICATOR_DATA);
//--- Define the symbol code for drawing in PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,159);
//--- Set the vertical shift of arrows in pixels
   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,5);
//--- Set as an empty value 0
   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[])
  {
//---
   int errorNumber = GetLastError();
   
   if (errorNumber != 0)
      Print(errorNumber);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Hi

Consider simple code above, put a break point at line 49 Print(errorNumber);

Run debug, errorNumber will be 4014.

If comment the three PlotIndexSet calls, all works whithout errors

I wrong something or is there a bug?

Thanks

F.

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Files:
Test01.mq4  3 kb
 
My advice to you: ALWAYS write the name of the indicator and its extension in the indicator header, and also attach the file using the button Attach file...
 
Before you use GetLastError, you need to call ResetLastError.

Then you do your function call and after that you check the error code.

Do not assume the error variable is yours if your execution path is coming from the terminal.

The terminal might have been using it.

Always wrap your own calls with ResetLastError and GetLastError.

Else results are undefined.
 
MrWolfPST:

Hi

Consider simple code above, put a break point at line 49 Print(errorNumber);

Run debug, errorNumber will be 4014.

If comment the three PlotIndexSet calls, all works whithout errors

I wrong something or is there a bug?

Thanks

F.

The code is for MT5 and works fine. The functions PlotSet... does not exist on MT4, it shouldn't even compile.
Reason: