How to get symbol names for active charts?

 

Seems a simple request, but alas i concede defeat after searching for ages so thought i'd ask the hive-mind for help.

I want to get the symbols for charts that are active in MT4, so if the terminal only has only two charts open - EURUSD and GBPUSD, i want to use only these symbols in code.

If you press ALT+W, that's what i need, a list of currently opened charts in the terminal.

Last resort, i could use WinAPI file functions to read the profile from profiles/lastprofile.ini and then read the profileName/order.wnd file, but this would mean the terminal needs to be closed to write to the file if the user adds a chart.

Im MT5 there's functions called ChartFirst() and ChartNext(), is there any way to replicate this in MQ4?

Any help would be appreciated, i'm stuck and this is a show-stopper...grrr.

Thanks in advance.

Note: WindowsHandle() doesn't work; i looped through all symbols and all timeframes to see if WindowsHandle finds a match, but it's hit and miss.


 
FlatFap:

Seems a simple request, but alas i concede defeat after searching for ages so thought i'd ask the hive-mind for help.

I want to get the symbols for charts that are active in MT4, so if the terminal only has only two charts open - EURUSD and GBPUSD, i want to use only these symbols in code.

If you press ALT+W, that's what i need, a list of currently opened charts in the terminal.

Last resort, i could use WinAPI file functions to read the profile from profiles/lastprofile.ini and then read the profileName/order.wnd file, but this would mean the terminal needs to be closed to write to the file if the user adds a chart.

Im MT5 there's functions called ChartFirst() and ChartNext(), is there any way to replicate this in MQ4?

Any help would be appreciated, i'm stuck and this is a show-stopper...grrr.

Thanks in advance.

Note: WindowsHandle() doesn't work; i looped through all symbols and all timeframes to see if WindowsHandle finds a match, but it's hit and miss.


Symbol()
 
FlatFap:

Seems a simple request, but alas i concede defeat after searching for ages so thought i'd ask the hive-mind for help.

I want to get the symbols for charts that are active in MT4, so if the terminal only has only two charts open - EURUSD and GBPUSD, i want to use only these symbols in code.

If you press ALT+W, that's what i need, a list of currently opened charts in the terminal.

Last resort, i could use WinAPI file functions to read the profile from profiles/lastprofile.ini and then read the profileName/order.wnd file, but this would mean the terminal needs to be closed to write to the file if the user adds a chart.

Im MT5 there's functions called ChartFirst() and ChartNext(), is there any way to replicate this in MQ4?

No,  there is nothing like that in MT4,  WinAPI is your best/only option.
 
  1. I don't know why you want to know what other charts are open. The EA on the current chart shouldn't care about any other.
  2. Have each EA leave a Global Variable (with an expiration time) and each can find all the others.
    string   active.chart;
    int init(){
       int      chrt.tf[]={ 0, PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30,
                               PERIOD_H1, PERIOD_H4, PERIOD_D1,  PERIOD_W1        };
       string   text.tf[]={ "n/a",   "M1",      "M5",      "M15",      "M30",
                                     "H1",      "H4",      "D1",       "W1"       };
       if(Chart.iTF == 0)   while(period.chart > chrt.tf[Chart.iTF])  Chart.iTF++;
       period.market  = chrt.tf[Chart.iTF];
       active.prefix  = WindowExpertName() +"_";
       active.chart   = active.prefix +symbol.chart +"_" +text.tf[Chart.iTF];
       if(!GlobalVariableCheck(active.chart)){
          if(!GlobalVariableSet(active.chart, EMPTY))  Alert(
                "GlobalVariableSet(", active.chart,")[1] Failed: ", GetLastError());
       }
    }
    int start(){
    :
             datetime timeOut = timeCur.srv + 60;   
             if(!GlobalVariableSet(active.chart, timeOut))   Alert(
                "GlobalVariableSet(",active.chart,")[2] Failed: ", GetLastError());
    :
       for(int iPos=GlobalVariablesTotal(); iPos >=0; iPos--){
          string   gvn = GlobalVariableName(iPos);
          if(StringFind(gvn, active.prefix) != 0)      continue;   // Wrong prefix.
          if(gvn == active.chart)                      continue;   // Myself counted
          datetime active = GlobalVariableGet(gvn); if(active == 0.){ Alert(
             "GlobalVariableGet(",gvn,") Failed: ", GetLastError());  continue;   }
          if(timeCur.srv - active > 30)                continue;   // Expired.
    // Found another symbol

 

@WHRoeder: thanks for the suggestion, but that's a redundant approach, i don't want to place an indy/script on each chart, especially if i have more than 20 charts open. Some demo servers pull in 90+ symbols, and i don't want code running against all these, only the ones that are open. It's better to have a master script that can 'poll' other chart data all in one place.

Found a solution that seems to be working:

#import "user32.dll"
   int  GetParent(int hWnd);
#import

void GetActiveCharts()
{
   //loop through all broker symbols found from server
   //then loop through all timeframes to see if a handle is found
   //when handle found, write symbol to new array

   int timeframeList[] = {1,5,15,30,60,240,1440,10080,43200};
   int totalSymbols = ArraySize(symbolList); //symbolList contains all the broker symbols
   string activeCharts[totalSymbols]; //new array to hold only active chart symbols opened in terminal
   int counter = 0;
   
   for(int symbolID = 0; symbolID < totalSymbols ; symbolID++) //loop through all symbols from server
   {
      string symbol = symbolList[symbolID];

      for(int timeframe = 0; timeframe < ArraySize(timeframeList); timeframe++) //now loop through each timeframe
      {    
         int tf = timeframeList[timeframe];
         int Parent = GetParent(WindowHandle(symbol,tf));
         if(Parent!=0) 
         {  
            activeCharts[counter] = symbol;
            counter++;
         }
      }
   }
   ArrayResize(activeCharts,counter);

return;
}
 
FlatFap: i don't want code running against all these, only the ones that are open.

Code can't run unless it's on an open chart. I never said to open more, just on the charts that are running an EA.

Your code is brute force, but that just tells you what charts are open. Not what EA's are running on which charts including wither it's 'active' or just 'idle'.

 

I only need to know which symbols are currently open in the terminal. I don't have any other indies/scripts on other charts, they are blank. I just need the symbols loaded in the terminal so i can extract data all from one indy on one chart.

hth

Reason: