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

 
Vladimir Simakov:

A pointer to an object.

No offence, but it's too early for you with macros like this, you'll get bogged down. First of all, understand why I did it this way:

And what to do with it with this pointer to object inside class where to pass it.

And as for macros, they are much easier to work with.

 
Seric29:

And what to do with this pointer to an object inside the class, where to pass it to.

As for macros, they are much easier to work with.

You can use it to refer to an object created anywhere. In my example the pointer to the object created globally is passed to the constructor, but this class can itself be nested in another one (in which the object is created).

Here's an example of the use of your macro:

#define  foor1(a,b,v,g) \
for(;Funkziya(a,b,v)&&g;b++)

...

foor(a,b,c,isSomething?a>b:b>c){
    DoSomething();
}
...

See what it unfolds into, I'm adding parentheses for clarity:

for(;( Funkziya(a,b,c)&&isSomething)?a>b:b>c;b++){
    DoSomething();
}

As a result, you've got absolutely valid code for the compiler, but the behaviour of the program is categorically different from what was intended. And now you don't actually notice the error, the code works, and then you'll just stare into the terminal and wonder why the robot logged in with the whole deposit and lost your account? )))))

I'm very good at macros, but that's why and why I dislike them so much (developers, once again please constexpr and SFINAE at the same time). So, my advice to you is don't use them to reduce letters in your code. It's actually, even in a stripped down mql-version, a powerful tool, but requires a very disciplined approach.

 

Developers, add possibility to use unlimited number of arguments inside macros and functions. I'm tired of this static nonsense. What is 8 arguments for a macro and if you need 108 what then, make it at least 10. And also make it possible to overload macros so you don't have to multiply new names with macros. It would also be cool if you could make

#define  Znah 0
#define  PrmI int    Peremen=6;
#define  PrmD double Peremen=3.345;

#if  Znah//если больше 0 то появится переменная int Peremen
   PrmI
#else
    PrmD//иначе появится переменная double Peremen
#endif

macro#if

 
Vladimir Simakov:

But the behaviour of the programme is categorically different from what was intended. And now it's not a fact that you will notice the error, the code works, and then you'll be stupidly looking in the terminal and wondering why the robot entered with the whole deposit and lost the account? )))))

I am very good at macros, but that's why I don't like them so much (developers, once again I ask for constexpr and SFINAE at the same time). So, my advice to you is don't use them to reduce letters in your code. It is, in fact, even in a stripped down mql-version, a powerful tool, but requires a very disciplined approach.

I'm not going to guess anything, I'm doing my job reliably.

CDataManager*  m_data;

What are you doing with the m_data pointer? Are you accessing elementm_data? What do you get out of it? I understand it happens here.

   CNewBar(CDataManager* data=NULL):m_data(!data?new CDataManager:data),cIsDelData(!data){}
   CNewBar(string symbol,ENUM_TIMEFRAMES frame):m_data(new CDataManager(symbol,frame)),cIsDelData(true){}

It's just not clear (very complicated) what are you trying to achieve?

What would happen if this line

CDataManager*  m_data;

would be written in public.

Classes are a mystery to me. After 2 years I still don't know how to handle them.

 

There is a need to write test results statistics to a database table,

The DB is created beforehand, the passes of interest are written by including the sinput variable in the EA settings

DATABASE:

CREATE TABLE "TesterStatistics" (
        "id"    INTEGER,
        "MD5"   TEXT,
        "STAT_PROFIT"   REAL,
        "STAT_GROSS_PROFIT"     REAL,
        "STAT_GROSS_LOSS"       REAL,
        "STAT_MAX_PROFITTRADE"  REAL,
        "STAT_MAX_LOSSTRADE"    REAL,
        "STAT_CONPROFITMAX"     REAL,
        "STAT_CONPROFITMAX_TRADES"      INTEGER,
        "STAT_MAX_CONWINS"      REAL,
        "STAT_MAX_CONPROFIT_TRADES"     INTEGER,
        "STAT_CONLOSSMAX"       REAL,
        "STAT_CONLOSSMAX_TRADES"        INTEGER,
        "STAT_MAX_CONLOSSES"    REAL,
        "STAT_MAX_CONLOSS_TRADES"       INTEGER,
        "STAT_BALANCEMIN"       REAL,
        "STAT_BALANCE_DD"       REAL,
        "STAT_BALANCEDD_PERCENT"        REAL,
        "STAT_BALANCE_DDREL_PERCENT"    REAL,
        "STAT_BALANCE_DD_RELATIVE"      REAL,
        "STAT_EQUITYMIN"        REAL,
        "STAT_EQUITY_DD"        REAL,
        "STAT_EQUITYDD_PERCENT" REAL,
        "STAT_EQUITY_DDREL_PERCENT"     REAL,
        "STAT_EQUITY_DD_RELATIVE"       REAL,
        "STAT_EXPECTED_PAYOFF"  REAL,
        "STAT_PROFIT_FACTOR"    REAL,
        "STAT_RECOVERY_FACTOR"  REAL,
        "STAT_SHARPE_RATIO"     REAL,
        "STAT_MIN_MARGINLEVEL"  REAL,
        "STAT_CUSTOM_ONTESTER"  REAL,
        "STAT_DEALS"    INTEGER,
        "STAT_TRADES"   INTEGER,
        "STAT_PROFIT_TRADES"    INTEGER,
        "STAT_LOSS_TRADES"      INTEGER,
        "STAT_SHORT_TRADES"     INTEGER,
        "STAT_LONG_TRADES"      INTEGER,
        "STAT_PROFIT_SHORTTRADES"       INTEGER,
        "STAT_PROFIT_LONGTRADES"        INTEGER,
        "STAT_PROFITTRADES_AVGCON"      INTEGER,
        "STAT_LOSSTRADES_AVGCON"        INTEGER,
        PRIMARY KEY("id" AUTOINCREMENT)
)

I write to this table with this code:

DatabaseExecute(handleDB, StringFormat("INSERT INTO \"TesterStatistics\" "
                                             "VALUES (NULL, \'%s\',%G, %G, %G, %G, %G, %G, %d, %G, %d, %G, %d, %G, %d, "
                                             "%G, %G, %G, %G, %G, %G, %G, %G, %G, %G, %G, %G, %G, %G, %G, %G, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d);",
                                             md5txt, TesterStatistics(STAT_PROFIT),             TesterStatistics(STAT_GROSS_PROFIT),
                                             TesterStatistics(STAT_GROSS_LOSS),                 TesterStatistics(STAT_MAX_PROFITTRADE),
                                             TesterStatistics(STAT_MAX_LOSSTRADE),              TesterStatistics(STAT_CONPROFITMAX),
                                             (int)TesterStatistics(STAT_CONPROFITMAX_TRADES),   TesterStatistics(STAT_MAX_CONWINS),
                                             (int)TesterStatistics(STAT_MAX_CONPROFIT_TRADES),  TesterStatistics(STAT_CONLOSSMAX),
                                             (int)TesterStatistics(STAT_CONLOSSMAX_TRADES),     TesterStatistics(STAT_MAX_CONLOSSES),
                                             (int)TesterStatistics(STAT_MAX_CONLOSS_TRADES),    TesterStatistics(STAT_BALANCEMIN),
                                             TesterStatistics(STAT_BALANCE_DD),                 TesterStatistics(STAT_BALANCEDD_PERCENT),
                                             TesterStatistics(STAT_BALANCE_DDREL_PERCENT),      TesterStatistics(STAT_BALANCE_DD_RELATIVE),
                                             TesterStatistics(STAT_EQUITYMIN),                  TesterStatistics(STAT_EQUITY_DD),
                                             TesterStatistics(STAT_EQUITYDD_PERCENT),           TesterStatistics(STAT_EQUITY_DDREL_PERCENT),
                                             TesterStatistics(STAT_EQUITY_DD_RELATIVE),         TesterStatistics(STAT_EXPECTED_PAYOFF),
                                             TesterStatistics(STAT_PROFIT_FACTOR),              TesterStatistics(STAT_RECOVERY_FACTOR),
                                             TesterStatistics(STAT_SHARPE_RATIO),               TesterStatistics(STAT_MIN_MARGINLEVEL),
                                             TesterStatistics(STAT_CUSTOM_ONTESTER),            (int)TesterStatistics(STAT_DEALS),
                                             (int)TesterStatistics(STAT_TRADES),                (int)TesterStatistics(STAT_PROFIT_TRADES),
                                             (int)TesterStatistics(STAT_LOSS_TRADES),           (int)TesterStatistics(STAT_SHORT_TRADES),
                                             (int)TesterStatistics(STAT_LONG_TRADES),           (int)TesterStatistics(STAT_PROFIT_SHORTTRADES),
                                             (int)TesterStatistics(STAT_PROFIT_LONGTRADES),     (int)TesterStatistics(STAT_PROFITTRADES_AVGCON),
                                             (int)TesterStatistics(STAT_LOSSTRADES_AVGCON)));


ENUM_STATISTICS enumeration has an order as in help, script to check:

void OnStart()
{
   for(int i = 0; i <= (int)STAT_LOSSTRADES_AVGCON; i++)
      printf("%d ^ %s", i, EnumToString(( ENUM_STATISTICS)i));
}


everything works,BUT the code text is quite voluminous, high probability of a typo, how to get this query to the database in a more reliable way - the main problem is howto getintoStringFormat

 
Igor Makanu:

There is a need to write test results statistics to a database table,

The DB is created beforehand, the passes of interest are written by including the sinput variable in the EA settings

DATABASE:

I write to this table with this code:


ENUM_STATISTICS enumeration has an order as in help, script to check:


everything works,BUT the code text is quite voluminous, high probability of a typo, how to get this query to the database in a more reliable way - the main problem is howto getintoStringFormat

Define!!! (although a normal overload will do here)

And what's the point of this StringFormat?

It's no faster than a normal add.... (I've done dozens of gigabytes of text files =....) even a normal add-on is faster, that's the way it is...


If you want to do it through this regular function, I don't understand the problem either ))

 
Alexandr Andreev:

And what's the point of this string format?

It's never faster than a normal add.... (I've done dozens of gigabytes of text files =....) even a normal add-on is faster, that's the thing...

I don't know.

i read the help and the article and created a database query using the examples

It seems to work, but I suspect that if I use part of this code, I may make some typos

All in all this may look strange, so I'm asking how to make it more compact without screwing up )))

 
Igor Makanu:

There is a need to write test results statistics to a database table,

The DB is created beforehand, the passes of interest are written by including the sinput variable in the EA settings

DATABASE:

I write to this table with this code:


ENUM_STATISTICS enumeration has an order as in help, script to check:


all works,but the text of the code is quite vast, there is a high probability of a typo, how to get this query to the database in a more reliable way - the main problem is howto get StringFormat

Remember, first, field types are optional in SQLite and you don't have to bother with typing and casting. It is "Lite" for a reason.

a long query may be divided into 3-4-5 parts :-)

BEGIN TRANSACTION

INSERT INTO myTable VALUES (...); --- тут можно получить PrimaryKey

UPDATE myTable .... ; --- обновить по Primary

UPDATE myTable ...  ; --- ещё...

COMMIT ; --- это если все запросы удачны.. иначе ROLLBACK

this is from old memory, i.e. you should check with the help

 
Igor Makanu:

I don't know.

i read the help and the article, created a database query using the examples

It seems to work, but I suspect that if I partially use this code, I may make misprints

I would like to ask how to make it more compact without screwing up ))))

Your task should be solved like this:

string MakeRequest(string md5txt){
   static ENUM_STATISTICS intIndex[]={STAT_CONPROFITMAX_TRADES,
                                      STAT_MAX_CONPROFIT_TRADES,
                                      STAT_CONLOSSMAX_TRADES,
                                      STAT_MAX_CONLOSS_TRADES,
                                      STAT_DEALS,
                                      STAT_TRADES,
                                      STAT_PROFIT_TRADES,
                                      STAT_LOSS_TRADES,
                                      STAT_SHORT_TRADES,
                                      STAT_LONG_TRADES,
                                      STAT_PROFIT_SHORTTRADES,
                                      STAT_PROFIT_LONGTRADES,
                                      STAT_PROFITTRADES_AVGCON,
                                      STAT_LOSSTRADES_AVGCON};
   string ret="INSERT INTO \"TesterStatistics\" VALUES (NULL,"+md5txt;
   for (int i=0,ii=0;i<=STAT_LOSSTRADES_AVGCON;++i){
      ret+=",";
      if (i==intIndex[ii]){
         ret+=StringFormat("%d",(int)TesterStatistics((ENUM_STATISTICS)i));
         ++ii;}
      else ret+=StringFormat("%G",TesterStatistics((ENUM_STATISTICS)i));}
   return ret;}
   
DatabaseExecute(handleDB, MakeRequest("md5txt"));
 
Vladimir Simakov:

Your particular problem should be solved like this:

Shit!

Right! Arrays!

THANK YOU!!!!!

Reason: