Why not put the input parameters in the structure?

 

I mean the EA-in-class approach. There is a problem with passing input parameters to an EA whose class is in a separate .mqh file. I use two methods

  1. The input parameters are copied into the fields of the EA class by one or more initialization functions. This is the most universal approach, but in case of a large number of variables, it is the most time consuming.
  2. The class is defined after the input variables, so they are visible from the EA. The disadvantage - less flexibility when using multiple instances of the class. Plus - minimum amount of writing.

input double LotSize = 0.1;
// другие input переменные...

#include <MyLib\MyClassEA.mqh>
CMyClassEA MyEA;

And what if we make an MQL extension and put input variables in the structure? It's not compatible with C++ and C anyway, because of pointers imitation. So why not go further?

struct InputVars
{
    input double Lot   = 0.1;
    input int    Magik = 100;
} ivars;

Then you could pass the variable ivars to the algorithm class, copy etc.

Take the idea on a brainstorming level ))

 

I have long had to deal with the need to work with a lot of configuration parameters. Whenever possible, I solve this problem by creating a special dialog box through a DLL in which the parameters are tabbed. After the initialization this window is hidden and then the program runs as usual.

If only it were something like that in MQL, so that it wouldn't have to look through a huge list of parameters. The very idea of how to implement it is interesting. Only the syntax should be slightly different:

input struct VolumeParams                              // Здесь название вкладки
{
    // Содержимое вкладки
    double Lot1 = 0.01;
    double Lot2 = 0.02;
    double LotRatio = 1.5;
};
 
Ihor Herasko:

I have long had to deal with the need to work with a lot of configuration parameters. Whenever possible, I solve this problem by creating a special dialog box through a DLL in which the parameters are tabbed. After the initialization this window is hidden and then the program runs as usual.

If only it were something like that in MQL, so that it wouldn't have to look through a huge list of parameters. The very idea of how to implement it is interesting. Only the syntax should be slightly different:


Right, it's shorter ) and with dll it won't work in Market, alas.

and using the dialog box will not let you optimize the parameters in the tester

 

then it's better this way:

struct VolumeParams                              
{
    double lot;         //название параметра
    double LotRatio;    //название параметра
    int tp;             //название параметра
    int sl;             //название параметра
    int orders;         //название параметра
};
VolumeParams ParamBuf[5];

input ParamBuf[0];         // Здесь название вкладки
input ParamBuf[1];         // Здесь название вкладки
input ParamBuf[2];         // Здесь название вкладки
input ParamBuf[3];         // Здесь название вкладки
input ParamBuf[4];         // Здесь название вкладки
 

Imho, great idea, consistent with the concept of OOP. So far I see 2 options:

1)FrameInputs style.

parameters

[out] String array with description of parameter names and values

parameters_count

[out] The number of elements in theparameters[] array.

2) InMqlParams style.

 

I always use the first approach.

When an Expert Advisor is placed in a trade (either on a demo or on a real account) - the parameters are fixed - and only one parameter - the risk percentage - is passed to the class of the Expert Advisor. All other parameters are written in the same structure and are defined inside the Expert Advisor - either in the constructor or in a special function.

 
Alexey Volchanskiy:

I mean the "Expert Advisor in a class" approach. There is a problem with passing the input parameters to the Expert Advisor whose class is located in a separate .mqh file.

Didn't feel the problem. To prescribe a template in the class constructor and that's it.

 
fxsaber:

Didn't feel the problem. You have to prescribe a template in the class constructor and that's it.


well, you haven't talked to customers)

...here the customer wants 10 inputs, and each step has its own tp/sl/lot/trall/signal to input

and that all this is optimized in the tester)

 
Taras Slobodyanik:

well, you haven't talked to customers)

...so the customer wants 10 inputs, and each step has its own tp/sl/lot/trall/signal to input

and that all this is optimized in the tester)

So, how does this relate to the topic of the branch?

 
fxsaber:

So how does this relate to the topic of the thread?


The discussion itself has indeed deviated slightly from the thread title. Now it's more about the second part of TC's post:

Alexey Volchanskiy

What if we make an extension of MQL language and put input variables in the structure? It's not compatible with C++ and C anyway, because of the pointer imitation. So why not go further?

Then you could pass the variable ivars to the algorithm class, copy, etc.

 
fxsaber:

So how does this relate to the topic of the thread?


So it does, to write this whole heap of parameters, it would be enough to define the structure and put it in the input parameters.