ChartWindowFind() returns -1 for indicator in mql5

 

Hi Guys,

I tried to migrate code from mql4 to mql5 using info in https://www.mql5.com/en/articles/81. I replaced
"int WindowFind(string name)" with "int WindowFindMQL4(string name)" .

int WindowFindMQL4(string name)
  {
   int window=-1;
   if((ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     {
      window=ChartWindowFind();
     }
   else
     {
      window=ChartWindowFind(0,name);
      if(window==-1) Print(__FUNCTION__+"(): Error = ",GetLastError());
     }
   return(window);
  }

 Execution of line "window=ChartWindowFind();" return -1 for indicator. In the documentation: "It returns the number of the subwindow where the indicator is working." but I get value -1. https://docs.mql4.com/chart_operations/chartwindowfind


How I can fix it or is it bug in mql5 ?

 

Topic about mql5 doesn't have to be posted in mql4 section.

Is there an error number ?

How do call it and where is this code executed ? OnInit() ?

 
 The error code was 4113 and appeared during debugging on historical data. When I run the indicator on real data - it worked correctly (no error).
 Thank you, Alain Verleyen for your help.
 
Elo:
 The error code was 4113 and appeared during debugging on historical data. When I run the indicator on real data - it worked correctly (no error).
 Thank you, Alain Verleyen for your help.

Use

      window=ChartWindowFind(ChartID(),name);
 
Alain Verleyen:

Use

window=ChartWindowFind(ChartID(),name);

When use debug on history data, the code (in indicator):

   int window=-1;
   if((ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     {
      window=ChartWindowFind();
      if(window<0) Print("Error executing ChartWindowFind :",GetLastError());
      
      int window2=ChartWindowFind(0,name);
      if(window2<0) Print("Error executing ChartWindowFind :",GetLastError());
      
     }
returns window = -1 and window2 = -1 . When use in script on real data code :
window=ChartWindowFind(ChartID(),name);

returns correct sub window number.

 

I can confirm that you will encounter this error when backtesting a MQL5 indicator with it on a separate window, whether or not you are using 

ChartWindowFind(ChartID(),name);

Or

ChartWindowFind();

This code will only work in MQL4. 

Seems like this is a problem that can be raised to service support.

Need a moderator to confirm this. Thanks.

Reason: