They added the enum data type to the base data types and also made a more precise definition of the integer types. In this way, they added:
char , short , long , uchar , ushort , uint , ulongThis time the structures appear too:
The introduction of the operators new si delete which are used for the creation and destruction of objects. These two operators apply to object-oriented programming.
These are functions that execute when an event happens:
OnStart(), OnInit(), OnDeinit(), OnTick(), OnTimer(), OnTrade(), OnBookEvent(), OnChartEvent().
We can mention new event types:
- OnTimer() : The function is called when a timer event is triggered, which is set up by EventSetTimer();
- OnTrade() : The function is called whenever the list of orders or position changes ; that means it is called whenever an order is posted or gets executed;
- OnBookEvent() : Function is called whenever the price change for any symbol registered by MarketBookAdd() si-a schimbat pretul. In a way it is a generalized form of OnTick().
- OnChartEvent() : Function is called whenever the chart receives an event, be it given by the keyboard, mouse, or moving a graphics object by mouse.
OnInit() basically takes over from MQL4’s init();
OnStart() reduces from the role that start() had in MQL4, remaining as main block for scripts;
OnTick() takes over the role as incoming tick event, from the start() function from MQL4;
OnDeinit() takes over old MQL4’s deinit();
Object Oriented Programming
One of the novelties of MQL5 is the Object Oriented Programming, which makes code to be easier to write, read and use. The basic OOP features are : encapsulation, inheritance, polymorphism, function overload and virtual functions.
New graphics objects
MetaQuotes comes with new graphics elements .Below is the list with the new graphics objects featured by MQL5:
OBJ_ELLIOTWAVE5 , OBJ_ELLIOTWAVE3 , OBJ_ARROW_THUMB_UP , OBJ_ARROW_THUMB_DOWN, OBJ_ARROW_UP , OBJ_ARROW_DOWN , OBJ_ARROW_STOP , OBJ_ARROW_CHECK ,OBJ_ARROW_LEFT_PRICE, OBJ_ARROW_RIGHT_PRICE ,OBJ_BUTTON , OBJ_CHART , OBJ_BITMAP , OBJ_BITMAP_LABEL , OBJ_EDIT.Our opinion would be that OBJ_EDIT,OBJ_BUTTON si OBJ_CHART are the most important graphics objects. Once with OBJ_CHART comes the possibility to have chart in chart feature (to see inside a chart a different other charts). These objects are fully packed with properties, which leads to a better graphics object management.
Special variables for debugging
To simplify debugging four variables have been introduced : __LINE__ , __FILE__ ,__FUNCTION__ , __MQL5BUILD__ , which can be used to log info about current line, file , function or the MQL5 build ; these come handy in debugging as there were no such infos in MQL4 and possible errors that were generated by functions were traceable with extra logging and considerable programming effort.
The position based system that replaces the order based system
This is an MT5 feature rather than a MQL5 feature. However, since it changes the trading activity, it leaves marks over MQL5. The order selection mechanism is modified, and also a new position selection mechanism has been added
With functions SymbolSelect() and SymbolTotal() can be made easily the list of all symbols offered by broker. Even more, with SymbolInfoInteger() a lot of symbol information can be retrieved, including the profit calculus and the margin calculus mode that tells about the symbol nature.
This existed also in MQL4’s MarketInfo(), however the symbol list was not retrievable. The symbol nature information, combined with the list, is a powerful tool in knowing which symbols are forex, which are futures, stocks or stock exchange indexes. This will have implications later in retrieving option chains by knowing the underlying.
A new way of reading/writing properties
The functions working with properties are now divided on data types, according to the data type they work with.
For instance MQL4’s MarketInfo() is now divided in SymbolInfoInteger(), SymbolInfoDouble(), SymbolInfoString() ; also SymbolInfoTick() for current prices;
The functions working with the account, which were one per solicited element in MQL4, are organized in a similar manner: AccountInfoInteger(), AccountInfoDouble(), AccountInfoString() (there were 16 account functions in MQL4, for comparison);
For the running program, MQL5InfoInteger(), MQL5InfoString() (similar functions were not existant in MQL4);
For data series : SeriesInfoInteger();
For charts : ChartGetDouble(), ChartGetInteger(),ChartGetString() , with their writing complements ChartSetDouble(), ChartSetString(), ChartSetSymbolPeriod() , near a series of functions inherited from MQL4’s window functions;
For indicators : IndicatorSetDouble(), IndicatorSetInteger(), IndicatorSetString();
To establish indicator plotting parameters: PlotIndexGetInteger(), PlotIndexSetDouble(), PlotIndexSetInteger(), PlotIndexSetString;
For graphics objects : ObjectGetDouble(), ObjectGetInteger(), ObjectGetString() , also the newer ObjectGetTimeByValue(), ObjectGetValueByTime ; also for writing : ObjectSetDouble(), ObjectSetInteger(), ObjectSetString().
A new way to address data series
Gone are functions like iHigh(), iHighest(), iLow(), iLowest(), iOpen(), iClose(), iBars(), iBarShift() from MQL4.
I said that appeared the function SeriesInfoInteger(). But this one returns only general properties.
To return data from data series now the function being used is CopyRates().
Un new way to construct and address indicators
This subject is too complicated for the present article. However, all indicators, including custom indicators, have the addressing manner changed. This time, functions don’t return values anymore, but handlers. It is recommendable that a new handler to be created for every indicator called with some parameters, one time. Then data can be extracted , datele pot fi extrase, pentru orice bara, cu ajutorul functiei CopyBuffer() , that can use same handler over and over again.
Sure we can’t cover in an article all the new relevant stuff brought by MQL5.
But these will appear in time, with the development of trading strategies written in MQL5.