Libraries: Expert - page 11

 
If you know the names of inputs, the second option is better. It allows you not to think about the order of inputs in the Expert Advisor. And it is technically better implemented.
#include <fxsaber\Expert.mqh>

void OnStart()
{
  MqlParam Params[2];

  // Pathway to Counsellor
  Params[0].string_value = "Experts\\Test6.ex5";
  Params[0].string_value += "\nexpertmode=5";
  
  Params[1].type = TYPE_INT;
  Params[1].integer_value = 123423;
  EXPERT::AddInputName(Params[1], "inpFirst");

  EXPERT::Run(0, Params);
}


Despite the fact that inpFirst is the second in order, it can be set to anything (in this case it is set to be the first and the only one). Those that are not set will be default.

 
For experiments I needed to clone a robot for several charts. I did it through this function.
#include <fxsaber\Expert.mqh> // https://www.mql5.com/en/code/19003

// Copies the running Expert Advisor with current settings from one chart to the other
bool ExpertFromTo( const long ChartSource, const long ChartTarget )
{
  bool Res = false;
    
  MqlParam Params[];
  string Names[];

  const int ExpertMode = EXPERT::Parameters(ChartSource, Params, Names);  
  const int Size = ArraySize(Params);
  
  if (Size)
  {
    Params[0].string_value += "\nexpertmode=" + (string)ExpertMode;
    
    for (int i = 1; i < Size; i++)
      EXPERT::AddInputName(Params[i], (Names[i - 1] == NULL) ? " " : Names[i - 1]);

    Res = EXPERT::Run(ChartTarget, Params);
  }
  
  return(Res);
}


I used it like this.

#property script_show_inputs

input int inAmount = 5; // How many clones

void OnStart()
{
  const int Size = SymbolsTotal(true);
  
  if (Size > inAmount)
    for (int i = 0, Count = 0; i < Size; i++)
    {
      const string Symb = SymbolName(i, true);
      
      if (Symb != _Symbol)
      {
        ExpertFromTo(0, ChartOpen(Symb, PERIOD_CURRENT)); // Run the current EA on new charts-symbols.
        Count++;
        
        if (Count == inAmount)
          break;
      }
    }
}
 

The task of restarting a dozen different Expert Advisors on more than one Terminal arises. In general, a big routine.

For example, we corrected something. Then batch compilation in ME and restart. I use such a script for it.

// Reloads EAs on all charts.
input int inInterval = 5; // Interval in seconds between chart restarts

bool ReloadChart( const long Chart )
{
  return (ChartSaveTemplate(Chart, "\\Files\\" + __FILE__ + ".tpl") &&
          ChartApplyTemplate(Chart, "\\Files\\" + __FILE__ + ".tpl") && // Put the task in the chart queue.
          ChartGetInteger(Chart, CHART_WINDOW_HANDLE));                 // Make the queue move.
}

void OnStart()
{
  const long chartID = ::ChartID();

  for (long Chart = ChartFirst(); (Chart != -1) && !IsStopped(); Chart = ChartNext(Chart))
    if ((Chart != chartID) && (ChartGetString(Chart, CHART_EXPERT_NAME) != NULL) && (ReloadChart(Chart)))    
      Sleep(inInterval * 1000);
}

I have marked an important place in the code. Without it, the application of the template will not be until the end of the script. By analogy, you can solve the launch of Expert Advisors after reloading the Terminal, etc.

 
fxsaber:

The task of restarting a dozen different Expert Advisors on more than one Terminal arises. In general, a big chore.

For example, we corrected something. Then batch compilation in ME and restart. I use this script for it.

I have highlighted an important place in the code. Without it, the template will not be used until the end of the script. By analogy, you can solve the launch of Expert Advisors after reloading the Terminal, etc.

It will be a complete set if you can get the name of the EA on the specified chart. If it is not difficult for you, finish it.

 
Vladimir Pastushak:

It would be complete if you could get the name of the councillor on said chart. If you don't mind, please complete it.

ChartGetString(Chart, CHART_EXPERT_NAME)

This is MT5. If you need cross-platform or full path to the Expert Advisor, then via Expert.mqh.

 
fxsaber:

This is MT5. If you need cross-platform or full path to the Expert Advisor, then via Expert.mqh.

Need cross-platform...

 
Vladimir Pastushak:

Need a cros-platformer...

Forum on trading, automated trading systems and testing trading strategies.

Libraries: Expert

fxsaber, 2019.09.12 06:17 pm.

#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);    
}
 
// Makes the file input variable equal to the selected file.
bool FileDialogToInput( const string InputName, const long Chart = 0 )
{  
  string FileNames[];
  const bool Res = (FileSelectDialog(MQLInfoString(MQL_PROGRAM_NAME) + " " + _Symbol + " " + EnumToString(_Period) +
                    ": input string " + InputName + " = ",
                    NULL, NULL, FSD_FILE_MUST_EXIST, FileNames, NULL) > 0);
  if (Res)
  {    
    MqlParam Params[];
    string Names[];
  
    const int ExpertMode = EXPERT::Parameters(Chart, Params, Names);  
    const int Size = ArraySize(Params);
    
    if (Size)
    {
      Params[0].string_value += "\nexpertmode=" + (string)ExpertMode;
      
      for (int i = 1; i < Size; i++)
      {
        if (Names[i - 1] == InputName)
          Params[i].string_value = FileNames[0];
        
        EXPERT::AddInputName(Params[i], (Names[i - 1] == NULL) ? " " : Names[i - 1]);
      }
  
      EXPERT::Run(Chart, Params);
    }    
  }
  
  return(Res);
}

This function allows you to select a file as an input variable. This implementation.

input string inFileName = NULL; // Selected file

#define  TOSTRING(A) #A          

int OnInit()
{
  if (!FileIsExist(inFileName))
    return(FileDialogToInput(TOSTRING(inFileName)) || INIT_FAILED);
    
  // Code if a valid file is specified in the input variable.

  return(INIT_SUCCEEDED);
}


Startup.


Click OK and select.


Click Open and see the properties (F7) of the running EA.


The same will work with any number of files.

input string inFileName1 = NULL; // Selected file1
input string inFileName2 = NULL; // Selected file2

#define  TOSTRING(A) #A          

int OnInit()
{
  if (!FileIsExist(inFileName1))
    return(FileDialogToInput(TOSTRING(inFileName1)) || INIT_FAILED);

  if (!FileIsExist(inFileName2))
    return(FileDialogToInput(TOSTRING(inFileName2)) || INIT_FAILED);
    
  // Code if a valid file is specified in the input variable.

  return(INIT_SUCCEEDED);
}
 
And loading parameters from set-files is not supported yet, as I understand?
 
traveller00:
And loading parameters from set-files is not supported yet, as I understand?

I haven't. But it's very simple.