OOP, templates and macros in mql5, subtleties and uses - page 15

 
Vict:

I've overcomplicated things )).

So, let the first one be used, it's probably the best way.

It's not a problem to write TEST several times.

You can also do this, but only in reverse order everything will be called.

#define  LINE(dId) EA.AddDealsSettings(InDealType_##dId,InVolType_##dId,InVolume_##dId,InPrice_##dId,InVolCoeff_##dId,InClosePips_##dId,Mirror)

#define  BLOCK1 LINE(01)
#define  BLOCK2 LINE(02); BLOCK1
#define  BLOCK3 LINE(03); BLOCK2
#define  BLOCK4 LINE(04); BLOCK3
#define  BLOCK5 LINE(05); BLOCK4
#define  BLOCK6 LINE(06); BLOCK5
#define  BLOCK7 LINE(07); BLOCK6
#define  BLOCK8 LINE(08); BLOCK7
#define  BLOCK9 LINE(09); BLOCK8
#define  BLOCK10 LINE(10); BLOCK9

#define  SEND(dCount) do {BLOCK##dCount;} while(false)

void OnStart()
  {
   SEND(10);
  }
 

Hmm, thought I'd make it easier for myself to bang on the keyboard less, but now I'll have to deal with all the examples

@Vladimir Simakov cool!

@Vict thank you!

ZS: To be honest, I understand only the first example of macros, the rest are not even close to understand (((

 
Igor Makanu:

Hmm, thought I'd make it easier for myself to bang on the keyboard less, but now I'll have to deal with all the examples

@Vladimir Simakov cool!

@Vict thank you!

ZS: To be honest, only the first example of a macro I understand, the rest are not even close to understand (((

The magic of the preprocessor is called)))

 
Vladimir Simakov:

The magic of preprocessor is called)))

I know, I've never had any practice, that's why it's hard to learn (((

Can I turn this code into a macro?


//--- input parameters
input ENUM_DEALTYPE        InDealType_01=BUY;            //1.------------------------------ Order ------------------------------
input int                  InPrice_01        =  000;     //Start price
input double               InVolume_01       =  0.01;    //Start Volume
input ENUM_VOLUMERATIO     InVolType_01=MultiplyAlways;  //Next operation with volume coefficient
input double               InVolCoeff_01     =  1.5;     //Volume coefficient
input ENUM_DISTANCERATIO   InDistType_01     =  NotMove; //Next price type
input double               InDistCoeff_01    =  1.23;    //Coefficient next open price
input int                  InDistShift_01    =  150;     //Shift next open price
input int                  InClosePips_01    =  200;     //TakeProfit>0 or StopLoss<0

input ENUM_DEALTYPE        InDealType_02=BUY;            //2.------------------------------ Order ------------------------------
input int                  InPrice_02        =  000;     //Start price
input double               InVolume_02       =  0.01;    //Start Volume
input ENUM_VOLUMERATIO     InVolType_02=MultiplyAlways;  //Next operation with volume coefficient
input double               InVolCoeff_02     =  1.5;     //Volume coefficient
input ENUM_DISTANCERATIO   InDistType_02     =  NotMove; //Next price type
input double               InDistCoeff_02    =  1.23;    //Coefficient next open price
input int                  InDistShift_02    =  150;     //Shift next open price
input int                  InClosePips_02    =  200;     //TakeProfit>0 or StopLoss<0

And so 10 times?

I mean, there's still 8 times left... but i don't know, when i'll run it in optimizer maybe i'll add or remove parameters, i haven't finalized the code yet (comments are the same, but one digit is different - first line)

 
Igor Makanu:

I know, I've never had any practice, that's why it's hard to learn (((

Can this code be wrapped in a macro?


And so 10 times? And the comments are the same, but one digit is different

Yes, no problem, but just no comments. Yes, and replace them with /* ... */ will not work, the compiler, in this case, stops accepting it in the context of text description of external variables for settings table. Checked.

 
Vladimir Simakov:

Yes, no problem, but just no comments. Yes, and replace them with /* ... */ will not work, the compiler, in this case, stops accepting it in the context of text description of external variables for settings table. Checked.

then it's a problem, the comments will have to be corrected by hand.... It's fine for tests, it's faster anyway, I'm working on my code, it takes a lot of time to edit it, I can't get to the tester...

if you don't mind, make an example without comments



PS: maybe the idea is rubbish, but since morning I've been thinking in my head what I would like to see.... For now a grid of orders into the optimizer, but the final goal is different (instead of some fixed grid steps, I want to attach a polynomial to make the optimizer run the coefficients, then perhaps the same, but I would like to see Taylor's rows ;) ), but the grid first I need to see what the optimizer shows, a test polygon in general I prepare )))

 
Igor Makanu:

I know, I've never had any practice, that's why it's hard to learn (((

Can I turn this code into a macro?


And so 10 times?

I mean, there's still 8 times left... but i don't know, when i'll run it in optimizer maybe i'll add or remove parameters, i haven't written code yet (comments are the same, but one digit is different - first line)

You can write a small function that will generate this code (and save to a file or clipboard).

 
Andrey Khatimlianskii:

You could write a little function that would generate this code (and save it to a file or clipboard).

well, there you go and destroy all poetic spirit, in prose it's not hard, like that:

#property copyright "IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#include <Files\FileTxt.mqh>
CFileTxt FOut;

#define   COUNT 10


const string code0[]=
  {
   "input ENUM_DEALTYPE        InDealType_","=BUY;            //",".------------------------------ Order ------------------------------"
  };

const string code1[]=
  {
   "input int                  InPrice_","        =  000;     //Start price",
   "input double               InVolume_","       =  0.01;    //Start Volume",
   "input ENUM_VOLUMERATIO     InVolType_","=MultiplyAlways;  //Next operation with volume coefficient",
   "input double               InVolCoeff_","     =  1.5;     //Volume coefficient",
   "input ENUM_DISTANCERATIO   InDistType_","     =  NotMove; //Next price type",
   "input double               InDistCoeff_","    =  1.23;    //Coefficient next open price",
   "input int                  InDistShift_","    =  150;     //Shift next open price",
   "input int                  InClosePips_","    =  200;     //TakeProfit>0 or StopLoss<0"
  };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {

   if(FOut.Open(__FILE__+".txt",FILE_WRITE|FILE_COMMON)!=INVALID_HANDLE)
     {
      for(int i=0;i<COUNT;i++)
        {
         string N=IntegerToString(i,2,'0');
         FOut.WriteString(code0[0]+N+code0[1]+IntegerToString(i)+code0[2]+"\n");
         for(int j=0;j<8;j++)
           {
            FOut.WriteString(code1[j*2]+N+code1[j*2+1]+"\n");
           }
        }
      printf("Write to file %s",FOut.FileName());
     }
   else printf("Open file error № %i",GetLastError());
  }
//+------------------------------------------------------------------+

))))

But thanks for the advice anyway!

 
Vladimir Simakov:

Yes, no problem, but just no comments. Yes, and replace them with /* ... */ will not work, the compiler, in this case, stops accepting it in the context of the text description of external variables for the settings table. Checked.

Maybe you did something wrong? Or is the macros behaving differently?

input double d1=1.02,/*Первая переменная double*/ d2=3;/*Вторая переменная double*/
input double d3=3.07;/*Третья переменная double*/
input int i1=5,/*Первая переменная int*/ i2=7;/*Вторая переменная int*/
 
Alexey Viktorov:

Have you done something wrong? Or is the macros behaving differently?

Yes, it is different. It has to do with the fact that the preprocessor starts before the parser and stupidly collects the text, with comments inside the macro being discarded at the preprocessor's stage. At the same time, if you leave // in a macro, you may get a fierce bug through your own fault.
Reason: