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

 
Save the chart as a template then parse the .tpl xml file to find the expert name
 
nicholishen:
Save the chart as a template then parse the .tpl xml file to find the expert name

Hi nicholishen,

As I already wrote to Alain, it's not a very good solution since the user can choose to attach/drop an Expert in any time, so I'll need always (onTimer) to save the template and check in it if any expert is on - this repeated actions will burden the system.

 
Sharon:

Hi nicholishen,

As I already wrote to Alain, it's not a very good solution since the user can choose to attach/drop an Expert in any time, so I'll need always (onTimer) to save the template and check in it if any expert is on - this repeated actions will burden the system.


There's no burden on system resources. The only thing is a minor introduction of about 3.5 ms latency per check. I would consider this a non-issue for most indicators. Try it for yourself. 

bool IsExpertOnChart()
{
   if(!ChartSaveTemplate(0,"../MQL4/Files/temp/temp.tpl"))
   {
      Print("Template save failed - ",ErrorDescription(_LastError));
      return true;
   }
   int h = FileOpen("temp/temp.tpl",FILE_TXT|FILE_READ);
   string res=NULL;
   if(h!=INVALID_HANDLE)
   {
      while(!FileIsEnding(h))
         res+=FileReadString(h);
      FileClose(h);
   }
   else
      return true;
 
   while(!IsStopped())
   {
      int start = StringFind(res,"<indicator>");
      if(start >= 0)
      {
         string tag = "</indicator>";
         int end   = StringFind(res,tag)+StringLen(tag);
         string left = StringSubstr(res,0,start);
         string right= StringSubstr(res,end);
         res = left+right;
      }
      else break;
   }
   return (StringFind(res,"<expert>") >= 0);
}
 
nicholishen:

There's no burden on system resources. The only thing is a minor introduction of about 3.5 ms latency per check. I would consider this a non-issue for most indicators. Try it for yourself. 


Hi nicholishen,

I checked your code and it works well, thanks.

About the burden on system resources, well, as you mentioned it's not so heavy but my Indicator is run by default on every open Chart,

so it can be a little bit heavy if the user will open plenty of Charts.

But now I'm going to build a checking process that will run your code just from one of the opened Charts, so it's going to be a perfect solution.

So thank you nicholishen for your code,

and I thanks Alain and Chris too.

 
Sharon:

Hi nicholishen,

I checked your code and it works well, thanks.

About the burden on system resources, well, as you mentioned it's not so heavy but my Indicator is run by default on every open Chart,

so it can be a little bit heavy if the user will open plenty of Charts.

But now I'm going to build a checking process that will run your code just from one of the opened Charts, so it's going to be a perfect solution.

So thank you nicholishen for your code,

and I thanks Alain and Chris too.

Ohh I was wrong, I need to do this check on every open Chart so what I wrote about the checking process that will run from one opened Charts it's not correct (so ignore this comment)..
 
Let the expert make an object on the chart.
Then use ObjectFind (.......), if you find the object you will get a value greater than -1.
 
nicholishen:

if(!ChartSaveTemplate(0,"../MQL4/Files/temp/temp.tpl")) 

Interesting, I never knew the double dot was allowed in the paths commands anywhere in MQL.

 
Ex Ovo Omnia:

Interesting, I never knew the double dot was allowed in the paths commands anywhere in MQL.

// if(!ChartSaveTemplate(0,"../MQL4/Files/temp/temp.tpl"))
if(!ChartSaveTemplate(0,"\\Files\\temp\\temp.tpl"))
 
Alain Verleyen:

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.

Hi Alain,


but in the documentation of   ChartSaveTemplate()  it is written:

filename

[in]  The filename to save the template. The ".tpl" extension will be added to the filename automatically; there is no need to specify it. The template is saved in data_folder\templates\ and can be used for manual application in the terminal. If a template with the same filename already exists, the contents of this file will be overwritten.


How do I force it to save in data_folder\MQL4\Files ?


Thanks,

Lukasz

 
Luk Baj:

Hi Alain,


but in the documentation of   ChartSaveTemplate()  it is written:

filename

[in]  The filename to save the template. The ".tpl" extension will be added to the filename automatically; there is no need to specify it. The template is saved in data_folder\templates\ and can be used for manual application in the terminal. If a template with the same filename already exists, the contents of this file will be overwritten.


How do I force it to save in data_folder\MQL4\Files ?


Thanks,

Lukasz

I tried following:


StringConcatenate("..\MQL4\Files\CzyRusek", symbol, IntegerToString(tf), ".tpl");

StringConcatenate("MQL4\Files\CzyRusek", symbol, IntegerToString(tf), ".tpl");

StringConcatenate("CzyRusek", symbol, IntegerToString(tf), ".tpl");


only last one succeded and off course in the place where FileOpen cannot read it :(.


Please help.