Are the "Caps lock" or "Shift" keys broken on your keyboard ?
Please write correctly on this forum.
is here something wrong?
Don't forget to use the code in the main event handler:
+------------------------------------------------------------------+ | Script program start function | +------------------------------------------------------------------+ void OnStart() { --- int window=GetIndicatorSubWindowNumber(0,shortName); if(window!=-1) Print("indicator "+shortName+" located in window #"+(string)window); else Print("indicator "+shortName+" is not found. window = "+(string)window); }
Without that, there's no reference to the input string:
input string shortName="MACD(12,26,9)";
Note that the documentation is giving a full illustration of both variants of ChartWindowFind(). Your code need not be so convoluted if you already know the window number and short name of the indicator before you call it. For example:
ChartWindowFind(0, "EA_Buttons");
there is no short-name needed to pass
this is going to work fine without parameters:
int GetIndicatorSubWindowNumber() { int window=-1; if((ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL_PROGRAM_TYPE)==PROGRAM_INDICATOR) { window=ChartWindowFind(); } return(window); }
From what I saw before, the actual window number cannot be debugged from this function, but the program can successfully identify which indicator is in a different window with ChartWindowFind().
From what I saw before, the actual window number cannot be returned, but the program can identify which indicator is in a different window with ChartWindowFind().
In that case, you can loop through ChartIndicatorsTotal(), and extract the window number and indicator short name:
Forum on trading, automated trading systems and testing trading strategies
MT5 - Is there a way to find the number of sub_windows on a chart?
Anthony Garot, 2018.06.19 20:57
That's it, exactly. Thank you!
My revised code (for posterity).
// CHART_WINDOWS_TOTAL // The total number of chart windows, including indicator subwindows long num_windows=-1; ChartGetInteger(chartID,CHART_WINDOWS_TOTAL,0,num_windows); PrintFormat("Total Num windows [%d]",num_windows); for ( int sub_window = (int) num_windows - 1; sub_window>0; sub_window-- ) { // See if there are any indicators on this sub_window int numIndicators = ChartIndicatorsTotal(chartID,sub_window); PrintFormat("sub_window [%d] has [%d] indicators", sub_window, numIndicators); // Close all the indicators on this sub_window for(int index=0; index<numIndicators; index++) { // we don't want to remove ourselves . . . we just got loaded! string name = ChartIndicatorName(chartID,sub_window,index); if ( name == SHORT_NAME ) { PrintFormat("Leaving indicator [%d] (%s) of [%d] on sub_window [%d] of underlying chart", index, name, numIndicators, sub_window); } else { PrintFormat("Closing indicator [%d] (%s) of [%d] on sub_window [%d] of underlying chart", index, name, numIndicators, sub_window); if ( ! ChartIndicatorDelete(chartID,sub_window,name) ) { PrintFormat("Could not delete indicator [%s]", name); return(INIT_FAILED); } } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i've tried to find a chart window according the documentation
https://www.mql5.com/de/docs/chart_operations/chartwindowfind
then the compiler says you must modifiy the parameters to
what is not the big deal,
but i get als result always -1
the indicator is just for testing with following code
and i use following call
is here something wrong?
regards
amando