WindowFind() returns -1 if custom indicator searches itself when init() function works. ??? - page 2
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.
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.
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.
Hi Guys,
I hope this would help...
https://book.mql4.com/functions/charts
Hi Guys,
I hope this would help...
https://book.mql4.com/functions/charts
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
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.
Here's a working function that I dug up
int GetIndicatorSubWindowNumber(long chartID=0,string short_name="")
{
int window=-1;
if((ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL_PROGRAM_TYPE)==PROGRAM_INDICATOR)
{
//--- the function is called from the indicator, name is not required
window=ChartWindowFind();
}
else
{
//--- the function is called from an Expert Advisor or script
window=ChartWindowFind(0,short_name);
if(window==-1) Print(__FUNCTION__+"(): Error = ",GetLastError());
}
return(window);
}
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.