Preventing Expert Advisor from opening new charts MQL5

 

So I created an expert advisor to load custom charts and it works perfectly, what I'm wondering right now is: is there anyway to prevent OnTick event to open the chart for the desired Symbol everytime a new tick arrives?

To do so my simple question is: is there anyway to count opened charts? Something like this: 

if(ChartOfDesiredSybol == 0)
ChartOpen(ChartID,Period);
else
Print("Chart for ", DesiredSymbol, " is already opened.");
 
Antonio Bartolucci:

So I created an expert advisor to load custom charts and it works perfectly, what I'm wondering right now is: is there anyway to prevent OnTick event to open the chart for the desired Symbol everytime a new tick arrives?

To do so my simple question is: is there anyway to count opened charts? Something like this: 

Try this 

input string CustomChartName="GBPUSD";//Custom Chart Name
input ENUM_TIMEFRAMES CustomChartTimeframe=PERIOD_H4;//Custom Chart Timeframe
input bool MaintainOpen=false;//Maintain chart opened
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
  ThisChartID=ChartID();
  ChartOpened=false;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  if(ChartOpened){ChartClose(CustomChartID);ChartOpened=false;} 
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
long ThisChartID,CustomChartID;
bool ChartOpened;
void OnTick()
  {
//---
  if(MaintainOpen&&ChartOpened)
  {
  if(ChartSymbol(CustomChartID)=="") ChartOpened=false;
  }
  //if chart not opened 
  if(!ChartOpened)
  {
  CustomChartID=ChartOpen(CustomChartName,CustomChartTimeframe);
  ChartOpened=true;
  } 
  
  }
 
Lorentzos Roussos:

Try this 

ok but this would work if the EA is opened on new chart, I mean to do this from one EA attached to one chart (some forex pair go benefit of the wide amounts of ticks).