Download MetaTrader 5

Advise on MQL4 vs MQL5 - page 2

To add comments, please log in or register
Ubzen
5394
Ubzen  

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.

HarriMQL5
349
HarriMQL5  

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....
ydrol
593
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:

//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...

mrpip
37
mrpip  
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...


mrpip
37
mrpip  

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

Ian Venner
2584
Ian Venner  
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
whroeder1
15351
whroeder1  
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.
Mideel
74
Mideel  

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...

12
To add comments, please log in or register