MT5 - Is there a way to find the number of sub_windows on a chart?

 

I want to close all sub_windows on a chart.

Thus, I want to know the count of the number of sub_windows.

I found a work-around that works. I can loop from 10 (arbitrary number) to 1, then see if there are any indicators in these sub_windows. (see code below)

But this is rather brute force and arbitrary. Is there a function I missed to get the count of sub_windows?

// Loop through up to 10 sub_windows. Does it really make sense to do more?
const int MAX_SUB_WINDOWS = 10;
for ( int sub_window = MAX_SUB_WINDOWS; 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++)
        {
                string name = ChartIndicatorName(chartID,sub_window,index);
                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);
                }
        }
}
 
If those are actual windows user32 functions should be able to list them.
 
Anthony Garot:

I want to close all sub_windows on a chart.

Thus, I want to know the count of the number of sub_windows.

I found a work-around that works. I can loop from 10 (arbitrary number) to 1, then see if there are any indicators in these sub_windows. (see code below)

But this is rather brute force and arbitrary. Is there a function I missed to get the count of sub_windows?

long total;
ChartGetInteger(ChartID(),CHART_WINDOWS_TOTAL,0,total);
int sub_window = (int)total-1;
maybe this is what you are asking.. ;-)
 
Lakshan Perera:
maybe this is what you are asking.. ;-)

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);
                        }
                }
        }
}
 
https://www.mql5.com/en/code/19117
SubWindow
SubWindow
  • votes: 25
  • 2017.11.03
  • fxsaber
  • www.mql5.com
All other files on this page provide examples/scenarios of library application; they are not needed for the operation of the library. Features Example The library use examples/scenarios are attached to the description. For a better understanding...
 
fxsaber:
https://www.mql5.com/en/code/19117
Nice!
Reason: