Close a chart running a specific EA...

To add comments, please log in or register
locactus
41
locactus  

Hi folks,


Scratching my head on how to do this. 

I have about 90 charts open, all running different EAs. I'd like to loop through the charts and check what EA is running. If the EA matches a string then close the chart. I can't seem to find the right function to do this. 

long chartID=ChartFirst();

   while(chartID >= 0){

      Print(chartID);

      chartID = ChartNext(chartID);

   }


Thanks in advance.

Juvenille Emperor Limited
Moderator
10220
Eleni Anna Branou  

Use the </> button to insert your code.


Petr Nosek
3023
Petr Nosek  
locactus:

Hi folks,

Scratching my head on how to do this. 

I have about 90 charts open, all running different EAs. I'd like to loop through the charts and check what EA is running. If the EA matches a string then close the chart. I can't seem to find the right function to do this. 

Thanks in advance.

You can loop through the charts but you can't find out the EA's names (see below code). If you can edit your EAs then you can send broadcast and every EA can remove itself and close its chart.

void OnStart()
  {
   string nameEA="SomeName";
   string nameSymbol="SomeSymbol"; // e.g EURUSD
   long chartToCloce=1; // If you know the ChartID
   
   long chartID=ChartFirst();
   while(chartID >= 0)
     {
      ChartSetInteger(chartID,CHART_BRING_TO_TOP,0,true);
      ChartRedraw(chartID);
      string winEA=MQLInfoString(MQL_PROGRAM_NAME); // The name is still the same (name of this script)
      printf("Chart ID: %I64d ; Expert name: %s ; Symbol: %s",chartID,winEA,Symbol()); // Symbol is still same too (it belong to chart whitch the script was run from)
      Sleep(2000); // Wait for 2s
      // You can't get the right EA name
      //if(nameEA==winEA)
      // If you know the ChartID you can handle with ChartID
      //if(chartID==chartToCloce)
      // You can handle with Symbol
      if(ChartSymbol(chartID)==nameSymbol)
        {
         //ExpertRemove(); // You don't want to quit this script
         ChartClose(chartID);
        }
      chartID=ChartNext(chartID);
     }
  }
Alain Verleyen
38674
Alain Verleyen  
Petr Nosek:

You can loop through the charts but you can't find out the EA's names (see below code). If you can edit your EAs then you can send broadcast and every EA can remove itself and close its chart.

You can but not trivial.

Forum on trading, automated trading systems and testing trading strategies

How can I detect by my Indicator code if an Expert is placed on the chart?

Alain Verleyen, 2018.01.23 01:25

There is no easy way under mql4.

  • If it's your EA, you can use a Global Variable of the Terminal.
  • Otherwise, you have to save a template in MQL4\\Files, see ChartSaveTemplate(). Then open it and check the presence of <expert> string in the template.

You can't.


Petr Nosek
3023
Petr Nosek  
Alain Verleyen:

You can but not trivial.


Thank you so much Alain. This is simple and useful.
locactus
41
locactus  

Thanks guys for your different approaches. In a way I'm glad wasn't an easy fix. I've come up with a different way of doing it as I dynamically build a script in Java to Open the charts and assign the EAs so all I do now is save the chart Id and EA name to file so I have a record of it and use that file as a lookup table to find and close the correct chart.


Thanks again for your help.

To add comments, please log in or register