How to count number of opened chart?

 

I have 100 symbols in market watch, I want to check which chart is currently active on tab or opened

What function i can look for 


thanks

 
Arpit T :

I have 100 symbols in market watch , I want to check which chart is currently active on tab or opened

What function i can look for 


thanks

You need to create two arrays: one will contain the names of all symbols, the second - the names of the charts.

Then it remains to go through the arrays and perform the comparison.

Example:

//+------------------------------------------------------------------+
//|                                   ChartNext and SymbolsTotal.mq5 |
//|                              Copyright © 2022, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2022, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.000"
#property description ""
#property script_show_inputs
//--- input parameters
input bool     InpPrint = true;  // Print result
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   string symbols[],charts[];
//---
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
   while(i<limit)                      // we have certainly not more than 100 open charts
     {
      currChart=ChartNext(prevChart);  // get the new chart ID by using the previous chart ID
      if(currChart<0)
         break;                        // have reached the end of the chart list
      string chart_symbol=ChartSymbol(currChart);
      //---
      int size_charts=ArraySize(charts);
      ArrayResize(charts,size_charts+1,9);
      charts[size_charts]=chart_symbol;
      //---
      Print(i,ChartSymbol(currChart)," ID =",currChart);
      prevChart=currChart;             // let's save the current chart ID for the ChartNext()
      i++;                             // do not forget to increase the counter
     }
//---
   int total=SymbolsTotal(true);
   for(int j=0; j<total; j++)
     {
      string symbol_name=SymbolName(j,true);
      int size_symbols=ArraySize(symbols);
      ArrayResize(symbols,size_symbols+1,9);
      symbols[size_symbols]=symbol_name;
     }
//---
   int size_charts=ArraySize(charts);
   int size_symbols=ArraySize(symbols);
   for(int j=0; j<size_charts; j++)
     {
      for(int k=0; k<size_symbols; k++)
        {
         if(symbols[k]==charts[j])
           {
            Print(charts[j]);
            continue;
           }
        }
     }
  }
//+------------------------------------------------------------------+

You just have to insert the counter in this code

 
Vladimir Karputov #:

You need to create two arrays: one will contain the names of all symbols, the second - the names of the charts.

Then it remains to go through the arrays and perform the comparison.

Example:

You just have to insert the counter in this code

thanks so much,

Reason: