Is the documentation wrong?

 

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


int GetIndicatorSubWindowNumber(long chartID=0,string short_name="")
  {
   int window=-1;
//--- 
   if((ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     {
      //--- Funktion wird vom Indikator aufgerufen, der Name ist nicht erforderlich.  
      window=ChartWindowFind();
     }
   else
     {
      //--- Funktion wird vom Experten oder Script aufgerufen 
      window=ChartWindowFind(0,short_name);
      if(window==-1) Print(__FUNCTION__+"() : Error = ",GetLastError());
     }
//---
   return(window);
  }

what is not the big deal,

 but i get als result always -1


the indicator is just for testing with following code

#property indicator_separate_window
#property indicator_plots 0
#property indicator_buffers 0

int OnInit()
{
   // ShortName setzen
   IndicatorSetString(INDICATOR_SHORTNAME, "EA_Buttons");
   return INIT_SUCCEEDED;
}

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[])
{
   return rates_total;
}


and i use following call


int subwin = GetIndicatorSubWindowNumber(0,"EA_Buttons");


is here something wrong?


regards

amando

Dokumentation zu MQL5: ChartWindowFind / Operationen mit Charts
Dokumentation zu MQL5: ChartWindowFind / Operationen mit Charts
  • www.mql5.com
Gibt die Nummer des Subfensters zurück, in dem sich Indikator befindet. Es gibt zwei Varianten der Funktion. 1. Funktion sucht auf dem...
 

Are the "Caps lock" or "Shift" keys broken on your keyboard ?

Please write correctly on this forum. 

 
amando:
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().

 
Conor Mcnamara #:

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);
                        }
                }
        }
}