Libraries: Expert - page 7

 

Unlike MT4, MT5 does not log the input parameters of Expert Advisors when they are launched or changed. Therefore, it is impossible to determine from the log what was launched in the Terminal.

A similar function can correct this situation.

#include <fxsaber\Expert.mqh> // https://www.mql5.com/en/code/19003

// Outputs the data of the running EA
string EAToString( const long Chart_ID = 0 )
{
  string Names[];
  MqlParam Params[];
  
  const int Flag = EXPERT::Parameters(Chart_ID, Params, Names);
  const int Size = ArraySize(Names);
  
  string Str = "Expert " + Params[0].string_value + ", expertmode = " + (string)Flag;
  
  for (int i = 0; i < Size; i++)
    Str += "\n" + Names[i] + " = " + Params[i + 1].string_value;
    
  return(Str);    
}


Application

input int inInput1 = 1;
input int inInput2 = 2;

int OnInit()
{
  Print(EAToString());
  
  return(INIT_FAILED);
}


Result

Test8 (EURUSD,M1)       Expert Experts\Test8.ex5, expertmode = 4
Test8 (EURUSD,M1)       inInput1 = 1
Test8 (EURUSD,M1)       inInput2 = 2


Unfortunately, it doesn't work for scripts. MT4 outputs input parameters of scripts by itself, MT5 does not.

 
I cannot run an EA that uses DLLs using this library. In the logs DLL loading is not allowed. Is there anything that can be done about it?
 
pivomoe:
I cannot run an EA that uses DLLs using this library. In the logs DLL loading is not allowed. Is there anything that can be done about it?
Params[0].string_value += "\nexpertmode=5"; // Permission to use DLL
 
fxsaber:

It's working.

 
I checked the library's work with input group. Everything is correct, I didn't need to change the code.
 

Something I have an apprehension about is the principle of using a constant as the name of a temporary template in a string:

#define  FILENAME (__FILE__ + ".tpl")

contains a potential bug related to multithreading. If one and the same programme running on different charts tries to use the library, there may be a collision with the template file - either an access error or two identical copies of the template will be quietly launched, although different ones were used.

You should generate a temporary name, preferably of the form (it was __FILE__, "strike" doesn't work in html here) MQL-program-name + timestamp + random.

It is also desirable to delete former files automatically by timeout at any next call, for example, in 1 day (by analysing part of timestamp), so that they don't litter folders.

PS. The case is even worse, because __FILE__ is a source file and is always equal to Expert.mqh - in all programmes using it! Corrected the sentence by name.
 
Stanislav Korotky:

This was done consciously, weighing all the pros and cons.

It makes sense to delete immediately after creating a template, not once a day. However, it is convenient to always have the last saved template to better analyse what is happening.

 
fxsaber:

It was done deliberately, weighing up the pros and cons.

It makes sense to delete immediately after creating a template, not once a day. However, it is convenient to always have the last saved template to better analyse what is happening.

I can't cite any pros for the current method. IMHO, I suggested a more correct one.

It makes sense to delete at once if Sync = true (which is the default), but it is not implemented that way now - the file remains.

 
Stanislav Korotky:

I can't think of a single "pro" for the current method. IMHO, suggested a more correct one.

The pros are practical application. I launched Terminal with previously launched Expert Advisors, which at the start immediately went into their templates. They worked perfectly. I am sure that it is possible to reproduce the theoretical collision. But it is far from practice in my case. If you decide to create a universal solution, share it here. I'll update the bible. I'm not ready to do it myself.

It makes sense to delete at once if Sync = true (which is the default), but it is not implemented that way now - the file remains.

Yes, I don't delete it on purpose.

 
fxsaber:

For - this is a practical application. I launched Terminal with previously launched Expert Advisors, which at the start immediately went into their templates. They worked perfectly. I am sure that it is possible to reproduce the theoretical collision. But it is far from practice in my case. If you decide to create a universal solution, share it here. I'll update the bible. I'm not ready to do it myself.

Yeah, I'm not deleting it on purpose.

I still don't understand why the constant name Expert.mqh.tpl is more "practical" (practical?) than templates named after the programme that generates them? Let's say there is a programme A.mq5 and B.mq5 that use bibla. If they generated templates with their own names it would be more practical, firstly, to have the last "fingerprint" of actions of _each_ programme, instead of overwriting one by the other. Secondly, you could immediately see who the generator is by name (especially useful if the programmes are foreign). Now you can't tell that from the Expert.mqh.tpl file until you get inside. The universal solution I have given is to take the name of the MQL-programme+timestamp+random. And I don't see the need to leave the file at sync=true. I think everything has been tested and debugged long ago. In case of errors and the need for debugging, there is an option sync=false. Then the file should be left. I think everything is logical. And the edits are simple.

I agree that in practice the collision may occur rarely, unless someone will use the biblio in parallel in several programmes. I don't have it, but I just had a quick look in the code, and my eye was caught by Expert.mqh.tpl in the Files folder. Everything is purely imho.