Libraries: Expert - page 6

 
fxsaber:

The author of an EA will never advocate trading his EA where the results in the tester are lousy.

He will not, but these are not signals - Expert Advisors are sold regardless of the brokerage centre. Then it should be obligatory to specify the seller, where he gets such results, and this is kind of an advertisement of the DC....

 
Aleksey Vyazmikin:

I will not agitate, but these are not signals - advisors are sold regardless of the DC. Then it should be obligatory to specify the seller, where he gets such results, and this is kind of an advertisement of the DC....

Probably, theoretical reasoning is sometimes good. But still interested in the practice related to this post. It was written in this thread for a reason.

I propose to stop fludding from all sides.

 
fxsaber:

In the Market I have seen many times that authors attach set-files of their TCs for each character. Accordingly, buyers use them.


I propose to use the following logic for Market TCs

  • One input parameter is added
  • If this folder is specified by the user, the Expert Advisor automatically picks up all sets from this folder and runs its corresponding versions.
  • The user only needs to place the set-file in the folder and specify the path to this folder when starting the Expert Advisor (the author of the Expert Advisor can insert this path at once).
  • If the user makes a mistake and runs it twice, it can be automatically prevented from doing so.

This approach is also convenient for launching your own TS with one click.

Of course, the solution can be universal for both platforms. Roughly speaking, only one line will need to be added to the source code of any Expert Advisor.


Most likely, this is how I will launch EAs from now on. If anyone sees a flaw in this method or an improvement option, let me know.

Running in the tester will be different from online (folders are different, after all), to match a particular copy of the EA to a set you need to do something extra.

Well, and just managing this herd of EAs without its own visualisation seems difficult.

Plus, changing the set of sets will be accompanied by restarting all EAs.


Individual MT charts serve as "transparent files", which are filed in the "hard folder" of the profile. This allows you to put the necessary information in each file or easily pull out/replace the necessary file. And you can switch to another "hard folder" by changing the profile. Kind of convenient.

I have faced the need to replace one parameter in all EAs (for example, risk). I did it by mass replacement in template files or through a special master variable. It would be convenient to wrap this into a convenient function.

 
Andrey Khatimlianskii:

Running in the tester will be different from online (the folders are different), to match a specific copy of the EA to the set you need to do something extra.

There will be no difference.

Well, and simply managing this herd of EAs without its own visualisation seems difficult.

No more complicated than it is now.

Plus set changes will be accompanied by a restart of all advisors.

The EA will be started normally. Only if you want, you can specify a folder with the sets.

Individual MT charts serve as "transparent files", which are filed in the "hard folder" of the profile. This allows you to put the necessary information in each file or easily pull out/replace the necessary file. And you can switch to another "hard folder" by changing the profile. Kind of convenient.

Of course, you can even automatically read/write profiles in MQL5\Profiles\Charts\.... But profiles are quite different.

I have encountered the need to replace one parameter in all EAs (for example, risk). I did it by mass replacement in template files or through a special master variable. It would be convenient to wrap it into a convenient function.

Such functionality is among the examples to the library.


However, you should distinguish between changing input parameters by restart method and via F7 by hand. The first one is a full-fledged restart, the second one is not. There are times when you need the second one. But this cannot be implemented in MQL.

 
fxsaber:

There will be no difference.

How? By selecting the one set you want?


fxsaber:

No more complicated than it is now.

Right now, each running EA has its own set.

But how will the "manager", running 10 Expert Advisors, behave if some of them change parameters manually? And what will happen after restarting the manager? Will the original sets be launched?

 
Andrey Khatimlianskii:

How? By selecting one necessary set?

MQL_TESTER.

Now each running Expert Advisor has its own set.

But how will a "manager" running 10 Expert Advisors behave if some of them have their parameters changed manually? And what will happen after restarting the manager? Will the original sets be launched?

The manager is not supposed to be used. Apparently, only by code I will be able to show what I meant. Thanks for your participation.

 
fxsaber:

MQL_TESTER.

Can you give a slightly more detailed answer?

It is possible to determine that the startup is in the tester, of course. But there is no access to the sets folder (or there is if you have access to the kamon folder), and there is no point in reading these sets - you need to test only one of them.

And after the test you need to match it with the running Expert Advisor (for example, to stop it or change some parameter). To do this, do I have to go to the folder with the sets, find the necessary one and edit it?


Then trading on all sets from one EA looks more reasonable. With the possibility to choose one or several strategies (sets).

 
Andrey Khatimlianskii:

Can I get a slightly more detailed answer?

It is possible to determine that the startup is in the tester, of course. But there is no access to the sets folder (or there is, if kamon), and there is no point in reading these sets - you need to test only one of them.

And after the test you need to match it with the running Expert Advisor (for example, to stop it or change some parameter). To do this, do I have to go to the folder with sets, find the necessary one and edit it?

A custom opt-file is used for the Tester. From it any set is launched with one click. It's super-convenient.

If you don't have an opt-file, you work the old-fashioned way. That is, nothing is complicated at all.

Then trading on all sets from one EA looks more reasonable. With the possibility to choose one or several strategies (sets).

Such a choice is always available in the Tester - load a set.

 
I would recommend building such a check into your EAs
// Cross-platform example of protection against erroneous launching of EA clone.

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

string GetExpertData( const ulong Chart = 0 ) 
{ 
  string Str = NULL; 

  MqlParam Parameters[]; 
  string Names[]; 

  if (EXPERT::Parameters(Chart, Parameters, Names)) 
  { 
    Str += "\n" + ::ChartSymbol(Chart) + " " + ::EnumToString(::ChartPeriod(Chart)) + " " + Parameters[0].string_value + "\n"; 

    const int Amount = ::ArraySize(Names); 

    for (int i = 0; i < Amount; i++) 
      Str += (string)i + ": "+ Names[i] + " = " + Parameters[i + 1].string_value + "\n"; 
  } 

  return(Str); 
} 

// Is the same advisor running?
long IsRunning( void )
{ 
  long Res = 0;
  const string Str = GetExpertData();
  long Chart = ::ChartFirst(); 

  while (!Res && (Chart != -1)) 
    if ((Chart != ::ChartID()) && EXPERT::Is() && (Str == GetExpertData(Chart)))
      Res = Chart;
    else
      Chart = ::ChartNext(Chart); 

  return(Res); 
}

input int Range1 = 1;
input int Range2 = 1;

int OnInit()
{
  return(!MQLInfoInteger(MQL_TESTER) && IsRunning() &&
         (MessageBox("This EA is already running." +
                     GetExpertData() + "\nRun?", MQLInfoString(MQL_PROGRAM_NAME), MB_YESNO) == IDNO) ?
         INIT_FAILED : INIT_SUCCEEDED);
}
 

// MT4-advisor shows in which Long/Short mode it was run.

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

int GetLongShortFlag( const int Chart_ID = 0 )
{
  MqlParam Params[];
  string Names[];
  
  const int Res = EXPERT::Parameters(Chart_ID, Params, Names);
  
  return(((Res & 3) << 1) + (Res & 1));
}

string LongShortToString( const int Chart_ID = 0 )
{
  const int Flag = GetLongShortFlag(Chart_ID);
  string Str = NULL;
  
  if ((bool)(Flag & SYMBOL_TRADE_MODE_LONGONLY) && (bool)(Flag & SYMBOL_TRADE_MODE_SHORTONLY))
    Str = "Long & Short";
  else if ((bool)(Flag & SYMBOL_TRADE_MODE_LONGONLY))
    Str = "Only Long";
  else if ((bool)(Flag & SYMBOL_TRADE_MODE_SHORTONLY))
    Str = "Only Short";
    
  return(Str);
}

int OnInit()
{
  Alert(LongShortToString());
  
  return(INIT_FAILED);
}