Advise on MQL4 vs MQL5 - page 2

 

Mql5 is basically an OOP version of Mql4 just as C++ is to C.

As with C++, theres no-need to use OOP_Paradigm. You can write your codes in Procedural_Paradigm. Intermediate->Advanced Mql4 programmers will have no problem writing in Mql5 Procedural ( using just the Documentations ). If however, someone wants to write OOP then that person would find better learning explanations through C++ materials for example.

I wouldn't use OOP unless I need an Object Data Type. If there's no benefit to creating two-or-more instances of a Class/Structure I would just use Procedural. I would use OOP for Data_Base heavy programs. Example, the Order_Object which needs (String, Integer and Double) packaged into one User Defined Data Type / Object. This should help mql4 create more complex programs for those wanting to built such programs.

Those are my opinions anyway.

 

RaptorUK


Some things in mql5 are very, very different, for example Order handling . . . you cannot have multiple open Orders on the same symbol, they combine to make a single position. You can do multi-symbol testing in the Strategy Tester, but you cannot use your own data so testing with real tick data is not possible.

Metaquotes say theyve improved the synthetic tick generation algorithm in MQL5...but its still not real tick data. If that is the case, then its a factor against switching to MQL5, although the debugger sounds good, not to mention new testing modes. Decisions, decisions....
 

Ignoring OOP specifically, One thing the old MQL4 really lacked (which it has now) was some kind of compound datatype (aka Structures / Records etc). Even C had these, they have been around a LONG time in programming because they are so fundamentally useful. (Probably since the late 70s maybe earlier).

So if anyone plans to stick with MQL4 but has no interest in OOP features, they might want to look at structures(records) as a bare minimum...


Having them it really changes the expressiveness of the language, and people might miss this being scared off by the additional OOP features.

Eg imagine writing code to manage the trading sessions in old MQL.

In procedural languages there are two general approaches:

1. Write a procedure/function you call each time you want to know when a session starts, and ends.

2. As above but also cache the information to avoid recalculating. Make it data centric rather than calculation centric.

One might decide on the latter approach to make for much faster code. So in old MQL4 you might find yourself defining arrays to hold information for each session eg:

//the following is just a on the fly example they might be better ways
string sesName[]; // to store 'New York','London','Tokyo' etc.

int sesStartHour[];

int sesEndHour[];

bool sesIsOnHoliday[]; // tru of session is on holiday

datetime sesHolidays[][20]; // list of holidays for each session (up to 20) a year. used to set bool sesOnHoliday[]

bool sesInDST[]; // true if session is currently in daylight savings

// Following used to compute

int sesDaylightSavingsWeekStart[];

int sesDaylightSavingsMonthStart[];

int sesDaylightSavingsWeekEnd[];

int sesDaylightSavingsMonthEnd[];


// Code to initialise ....


// Code to use

if  (sesInDST[NEW_YORK]) {...
}

You have to manage each session as a bit of information from each of the arrays. Luckily Sessions are faily static so its not too bad, but if it were something that could change whilst EA is running (eg storing historical Pivot Points S2,S1,PP,R1,R2 ) the code becomes a lot more difficult to manage...

However in new MQL4 you can start off using structures ...

// Daylight Savings

struct DSTDef {

    int startWeek; // -1=last week
    int startMonth;
    int endWeek; //-1=last week
    int endMonth;
};

struct Session {

    string name;
    int startHour;
    int endHour;
    bool isOnHoliday;
    bool isInDST;
    datetime holidays[]; // This is now the required size for each session. not just a massive array..
    DSTDef dst; // Another structure that holds info to compute DST for that session

};

enum ENUM_SES { SES_LONDON ,  SES_NEWYORK , SES_TOKYO }

Session sessions[3];

// code to initialise session

// code to use session
if (sessions[SES_NEWYORK].isOnHoliday) {
   ...
}

(and eventually replace then with classes ) once you start learning OO.

Once you get the hang of structures, classes become a fairly simple next step.. (ie instead of having global functions to manipulate your structures,

SessionCalculateDST(session[NEWYORK)) 

have the functions only accesible with the related data...

session[NEWYORK].calculateDST();

Then slowly learn about more advance OOP concepts if needed...

 
ydrol:

Ignoring OOP specifically, One thing the old MQL4 really lacked (which it has now) was some kind of compound datatype (aka Structures / Records etc). Even C had these, they have been around a LONG time in programming because they are so fundamentally useful. (Probably since the late 70s maybe earlier).

So if anyone plans to stick with MQL4 but has no interest in OOP features, they might want to look at structures(records) as a bare minimum...

Having them it really changes the expressiveness of the language, and people might miss this being scared off by the additional OOP features.

Eg imagine writing code to manage the trading sessions in old MQL.

In procedural languages there are two general approaches:

1. Write a procedure/function you call each time you want to know when a session starts, and ends.

2. As above but also cache the information to avoid recalculating. Make it data centric rather than calculation centric.

One might decide on the latter approach to make for much faster code. So in old MQL4 you might find yourself defining arrays to hold information for each session eg:

You have to manage each session as a bit of information from each of the arrays. Luckily Sessions are faily static so its not too bad, but if it were something that could change whilst EA is running (eg storing historical Pivot Points S2,S1,PP,R1,R2 ) the code becomes a lot more difficult to manage...

However in new MQL4 you can start off using structures ...

(and eventually replace then with classes ) once you start learning OO.

Once you get the hang of structures, classes become a fairly simple next step.. (ie instead of having global functions to manipulate your structures,

have the functions only accesible with the related data...

Then slowly learn about more advance OOP concepts if needed...


 

When I reply I get the same box as the prior post so I am replying here.

I programmed OOP back in the 90's and found there was way too much overhead.

I went back to C. I am glad for the structures and, hopefully, pointers so I can do data structures like btrees and neural nets but OOP is not really needed.

My biggest concern is what bugs will appear when more OOP is used.

I already got an error, not a warning, about overwritiing a function in the language and this is supported in Visual C++.

I am very capable at coding in C and just wish MQ would start with a compiler that works in the basic language before adding MT4 stuff.

Robert

 
MrPip:

When I reply I get the same box as the prior post so I am replying here.


add <br> to the end of the html
 
SDC: add <br> to the end of the html
Or click HTML click past the end of the html and press a key. Click VISUAL and there's your character after the quotes.
 

Hello, will old MQL4 be soon deprecated ? like start(), ini(), deinit() ? tey say they are still here for compatibility, sounds like they will be removed soon.


Actually I like OOP more than procedural, I try to learn MQL5 to code in MT4 but unfortunately there are some differences between them too even until now.... like there is no MqlTradeRequest Struct in MQL4 but weirdly there is MqlTicjk in the new MT4 Language... also why didn't MQL4 just make the new overloaded OrderSend function that accepts MqlTradeRequest and MqlTradeResult like in MQL5 beside the old one with many arguments.


So this makes things harder for us, they say they fully import the MQL5 Abilities so I thought we can just learn MQL5 if we want to code in the new MQL4 but actually they didn't...

 

MQL5 gives a "very poor OOP" and only makes the code confusing and hard to make simple things, you can spent easily 2 or 3 times more time writing the same thing for MQL5 when in MQL4 was very straigth forward to do, and normally a simple indicator can fastly be transformed in little big monster of code on MQL5.

MQL5 doesn't not give real benefits that justify transform 1 line of code in 6 or 7 to do the same thing... 

Nowadays I can't see a real reason that justify this kind of "evolution" way actually is exactly the opposite.

Performance is not the only thing in the world that matters, that's why there's a lot of languages that abstract this, maintainability is too very, or more, important. I'm not say that we can't do things in a low level to achieve some deserved perfomance numbers, but it not must be exclusive.

I think one of the big things that was made the MQL4 so popular, or the most popular language that where was made thousans of robots and indicators, it's exactly the asnwer for why MQL5 is so little used in community.

 
AndreLima:

MQL5 gives a "very poor OOP" and only makes the code confusing and hard to make simple things, you can spent easily 2 or 3 times more time writing the same thing for MQL5 when in MQL4 was very straigth forward to do, and normally a simple indicator can fastly be transformed in little big monster of code on MQL5.

MQL5 doesn't not give real benefits that justify transform 1 line of code in 6 or 7 to do the same thing... 

Nowadays I can't see a real reason that justify this kind of "evolution" way actually is exactly the opposite.

Performance is not the only thing in the world that matters, that's why there's a lot of languages that abstract this, maintainability is too very, or more, important. I'm not say that we can't do things in a low level to achieve some deserved perfomance numbers, but it not must be exclusive.

I think one of the big things that was made the MQL4 so popular, or the most popular language that where was made thousans of robots and indicators, it's exactly the asnwer for why MQL5 is so little used in community.

MQL5 is really designed to make use of (standard library) classes. By using class instances instead of constantly rewriting procedural algorithms you won't only keep your text files to a similar amount of lines, but you can also make programs with a much higher level of complexity (and error handling) with less hassels. IMHO, if you're not coding projects faster with MQL5 then you aren't making good use of the available OOP libraries.  
Reason: