Download MetaTrader 5

WindowFind() returns -1 if custom indicator searches itself when init() function works. ??? - page 2

To add comments, please log in or register
Ray 2009.11.11 20:58  

Seems to work in some code, not work in others. I haven't figured it out either.

When it refuses to work i put an extern for the window number to specify the window.

JPS1 2010.11.23 11:28  

Was this problem ever resolved? For the life of me I can't get WindowFind to work correctly. Always returns as -1. Yet I am positive I am inputting the name correctly.

Any ideas?

I know this an old thread, but an answer was never given, so I'll post here for others that come across the same problems.

After running some extensive testing to locate the reason, it appears that WindowFind() can only locate indicators inside the sub chart window.

If the indicator you are looking for is on your main chart window, it seems to always return a value of -1.

JPS1 2010.11.23 11:35  

I think the reasoning is there is no text on the chart and that is what MT4 is searching for - indicator short name.

A possible solution may be to have the indicator draw a hidden object (place it outside the chart boundaries).

Then use ObjectFind("hidden object") to know your indicator is attached.

AZRUL AZMI 2013.06.09 10:13  

Hi Guys,

I hope this would help...

Simon Gniadkowski
Simon Gniadkowski 2013.06.09 10:16  

Hi Guys,

I hope this would help...

You waited 5 years to post that ?  Please do not dredge up old thread unless you have a very, very good reason,  you don't.


Thread start date:   2008.02.09

LukeB 2016.02.02 03:25  

You waited 5 years to post that ?  Please do not dredge up old thread unless you have a very, very good reason,  you don't.


Thread start date:   2008.02.09

Thread is old, but surprisingly, I found no actual commentary that helped on Saturday, Jan 30, 2016.
I made the attached tool to learn what is going on.  This is what I think I have learned:

1) WindowFind does not work on the weekend.  It seemed to return -1 no matter what I did all day Saturday, and apparently started working Sunday night.  I'll check again this coming Saturday. 

2) WindowFind is not just another version of ObjectFind.  ObjectFind will not find the indicator short name, and WindowFind will not find objects in the objects list.

Here is a utility / experimental / indicator I made to show what is going on.  I hope it helps anyone else looking to understand what is going on get the answers a little easier. Click on the yellow text.

imdb 2016.11.12 19:39  

Here's a working function that I dug up


 int GetIndicatorSubWindowNumber(long chartID=0,string short_name="")


   int window=-1;



      //--- the function is called from the indicator, name is not required





      //--- the function is called from an Expert Advisor or script


      if(window==-1) Print(__FUNCTION__+"(): Error = ",GetLastError());






To use just  put this in init


int window;


int init() {

  window =  window=GetIndicatorSubWindowNumber(0,WindowExpertName());

  if(window==0) return;

  // Rest of the code to create your objects 



If you're simply looking for indicator's own window, just call  ChartWindowFind();  without any parameters. If you try to use it to find it self by passing the name, it doesn't work. 

To add comments, please log in or register