Logs a String to a File

Code in mql5:


//define parameter  
string filename; 
filename = _Symbol + "-" + IntegerToString(dt.mon) + "-" + IntegerToString(dt.day) + ".txt"; 

void Write(string str)
{
int handle;
handle = FileOpen(filename, FILE_READ|FILE_WRITE|FILE_CSV, "/t");
FileSeek(handle, 0, SEEK_END);
FileWrite(handle, str + " Time " + TimeToString(TimeCurrent(), TIME_DATE|TIME_SECONDS));
FileClose(handle);
}

check the trade request before sending with the function OrderCheck()

From class CTrade:

bool CTrade::PositionOpen(const string symbol,ENUM_ORDER_TYPE order_type,double volume,
double price,double sl,double tp,const string comment)
{
string action,result;
//---
ClearStructures();
//--- checking
if(order_type!=ORDER_TYPE_BUY && order_type!=ORDER_TYPE_SELL)
{
m_result.retcode=TRADE_RETCODE_INVALID;
m_result.comment="Invalid order type";
return(false);
}
//--- setting request
m_request.action =TRADE_ACTION_DEAL;
m_request.symbol =symbol;
m_request.magic =m_magic;
m_request.volume =volume;
m_request.type =order_type;
m_request.price =price;
m_request.sl =sl;
m_request.tp =tp;
m_request.deviation =m_deviation;
m_request.type_filling=m_type_filling;
m_request.comment =comment;
//--- order check
if(!OrderCheck(m_request,m_check_result))
{
m_result.retcode=m_check_result.retcode;
printf(__FUNCTION__+": %s [%s]",FormatRequest(action,m_request),FormatRequestResult(result,m_request,m_result));
//--- copy return code
return(false);
}
//--- order send
if(!OrderSend(m_request,m_result))
{
printf(__FUNCTION__+": %s [%s]",FormatRequest(action,m_request),FormatRequestResult(result,m_request,m_result));
return(false);
}
printf(__FUNCTION__+": %s [%s]",FormatRequest(action,m_request),FormatRequestResult(result,m_request,m_result));
//--- ok
return(true);
}

declare array with two data types string and double

Code in mql5:

struct string_double
{
string str_val;
double dbl_val;
}

string_double MyArray[SIZE];

//....

MyArray[0].str_val = "Hello, I'm string :)";
MyArray[0].dbl_val = 1;

Converting order select from mql4 to mql5

Sample code in mql4:
for (i=0;i<OrdersTotal();i++){
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if( OrderMagicNumber()==Magic){
   if(OrderType()==OP_BUYSTOP || OrderType()==OP_BUY) Bought++;
   if(OrderType()==OP_SELLSTOP || OrderType()==OP_SELL) Sold++;
     }
}

if( Bought==0 ){ //no buy order
Ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots, Long ,3, SLLong, 0,Text,Magic,TimeCurrent() + 119*60*60,Blue);
}


Sample code in mql5:

void OnStart()
{
datetime from=0;
datetime to=TimeCurrent();
//--- request the entire history
HistorySelect(from,to);
//--- variables for returning values from order properties
ulong ticket;
double open_price;
double initial_volume;
datetime time_setup;
string symbol;
string type;
long order_magic;
long positionID;
//--- number of current pending orders
uint total=OrdersTotal();
//--- go through orders in a loop
for(uint i=0;i<total;i++)
{
//--- return order ticket by its position in the list
if((ticket=OrderGetTicket(i))>0)
{
//--- return order properties
open_price= OrderGetDouble(ORDER_PRICE_OPEN);
time_setup= OrderGetInteger(ORDER_TIME_SETUP);
symbol= OrderGetString(ORDER_SYMBOL);
order_magic= OrderGetInteger(ORDER_MAGIC);
positionID = OrderGetInteger(ORDER_POSITION_ID);
initial_volume= OrderGetDouble(ORDER_VOLUME_INITIAL);
type=GetOrderType(OrderGetInteger(ORDER_TYPE));
//--- prepare and show information about the order
printf("#ticket %d %s %G %s at %G was set up at %s",
ticket, // order ticket
type, // type
initial_volume, // placed volume
symbol, // symbol
open_price, // specified open price
TimeToString(time_setup)// time of order placing
);
}
}
//---
}
//+------------------------------------------------------------------+
//| returns the string name of the order type |
//+------------------------------------------------------------------+
string GetOrderType(long type)
{
string str_type="unknown operation";
switch(type)
{
case (ORDER_TYPE_BUY): return("buy");
case (ORDER_TYPE_SELL): return("sell");
case (ORDER_TYPE_BUY_LIMIT): return("buy limit");
case (ORDER_TYPE_SELL_LIMIT): return("sell limit");
case (ORDER_TYPE_BUY_STOP): return("buy stop");
case (ORDER_TYPE_SELL_STOP): return("sell stop");
case (ORDER_TYPE_BUY_STOP_LIMIT): return("buy stop limit");
case (ORDER_TYPE_SELL_STOP_LIMIT):return("sell stop limit");
}
return(str_type);
}

Converting iHighest iLowest from MQL4 to MQL5

Code in MQL4:

double High4=iHigh(Symbol(),PERIOD_H1,iHighest(Symbol(),PERIOD_H1,MODE_HIGH,4,1));
double Low4=iLow(Symbol(),PERIOD_H1,iLowest(Symbol(),PERIOD_H1,MODE_LOW,4,1));
double Med4=(High4+Low4)/2;
bool orderBuy=Ask>Med4;
bool orderSell=Bid<Med4;

etc…


 Code in MQL5:

double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index)
{
double high=0;
ArraySetAsSeries(High,true);
int copied=CopyHigh(symbol,timeframe,0,TotalBars,High);
if(copied>0 && index<copied) high=High[index];
return(high);
}

int iHighest(string symbol,ENUM_TIMEFRAMES tf,int count=WHOLE_ARRAY,int start=0)
{
double High[];
ArraySetAsSeries(High,true);
CopyHigh(symbol,tf,start,count,High);
return(ArrayMaximum(High,0,count)+start);
return(0);
}

double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index)
{
double low=0;
ArraySetAsSeries(Low,true);
int copied=CopyLow(symbol,timeframe,0,TotalBars,Low);
if(copied>0 && index<copied) low=Low[index];
return(low);
}

int iLowest(string symbol,ENUM_TIMEFRAMES tf,int count=WHOLE_ARRAY,int start=0)
{
double Low[];
ArraySetAsSeries(Low,true);
CopyLow(symbol,tf,start,count,Low);
return(ArrayMinimum(Low,0,count)+start);
return(0);
}

can mql5 EA coded with no OOP features?

MQL5 can be written with just global functions, ie without any OO constructs. But the advantage of OO encapsulation is that you can very easily use proven classes written by someone else - take a look at the CTrade class in include\trade\trade.mqh to use in your EA

CTrade is what is often termed a "wrapper", in order words it is a simple packaging of like functions into the one class, with a few checks. The documentation at the top of each method is sufficient to work out how the class is used.

To do the actions that you suggest using CTrade, I would write it like this.

CTrade trade;
MqlTick CurrentTick;
SymbolInfoTick(_Symbol,CurrentTick);

// open new position
double sl,tp; // set these to appropriate distance from CurrentTick.ask
if (!trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,0.1,CurrentTick.ask,sl,tp,"comment"))
{
Print("Problem with CTrade::PositionOpen");
return;
}

// change sl and tp to new values
// sl=??????;
// tp=??????;
if (!trade.PositionModify(_Symbol,sl,tp))
{
Print("Problem with CTrade::PositionModify");
return;
}

Detecting new bar / candle

Take a look at the MQL5=>MQL4 conversion functions listed here. Time[0] doesn't exist, but iTime() is listed in mt4timeseries_2

I've always used Bars rather than Time[0], but the principle is exactly the same. The following code in OnTick() will set m_bNewBar true for one tick. This assumes that the code is in a class method and m_bNewBar and m_nLastBars are class members. Alternatively, they could be declared globally, C-fashion.

int nBars=Bars(Symbol(),PERIOD_CURRENT);
if(m_nLastBars!=nBars){m_nLastBars=nBars;m_bNewBar=true;}
else
{m_bNewBar=false;}

When are we use POSITION_MAGIC, ORDER_MAGIC, DEAL_MAGIC?

OrderSend() sequence.

1. OrderSend() call initiates an Order.
2. The Order then initiates a Deal and then Order is closed.
3 On acceptance of Deal by Broker's server, a Symbol Position is opened and then Deal is closed.

ORDER_MAGIC and DEAL_MAGIC would be used in HistorySelect as part of closed Order or Deal selection process.

HistorySelect() Example:
double LastDealPrice() // Last Deal open price for chart symbol
{
uint total=0;
long ticket;
string symbol;
long magic;

HistorySelect(0,TimeCurrent());
total=HistoryDealsTotal();

for(uint i=0;i <total; i++)
{
ticket=HistoryDealGetTicket(i);
symbol=HistoryDealGetString(ticket,DEAL_SYMBOL);
magic=HistoryDealGetInteger(ticket,DEAL_MAGIC);
if( symbol==Symbol() && magic==MagicNumber)
{
Lprice=HistoryDealGetDouble(ticket,DEAL_PRICE);
}
}

return(Lprice);
}



POSITION_MAGIC is used in current open Position selection process.

PositionSelect() example:

int CurPosLots() // total lots in current symbol position
{
int total=PositionsTotal();
double lots=0;
for (int cnt=0; cnt<total; cnt++)
{
if(PositionSelect(Sysbol()) )
{
if(PositionGetInteger(POSITION_MAGIC)==MagicNumber)
{
lots=PositionGetDouble(POSITION_VOLUME);
}
}
}

return(lots);
}

New feature of MT5 and MQL5

This article just a brief description of some moments.

Fig. 1. It's not Photoshop - it's MQL5.


Almost all that interested me and others in MQL5 and MT5 is implemented on a very high level.

The basic change in MQL5 is the appearance of the object oriented programming. I won't go deep into OOP - it's just that experienced programmers get more possibilities. For those who liked MQL4 and don't know about OOP developers left the possibility to write in MQL5 using the style of MQL4 without OOP. The difference is in the functionality that should be learned again.
Let's take a simple example: the Ask and Bid variables do not exist anymore. In order to get the Bid values the below function should be called:
SymbolInfoDouble(Symbol(),SYMBOL_BID);
There are no frequently used Low[0] or iLow ( Symbol(), PERIOD_D1, 0 ), but you can easily re-construct them. The new functions working with history data give possibilities to read into memory the history data from one point till another one, from a certain bar till another certain bar or from the selected time till the other selected time. Earlier reading of a data series the whole visible range was loaded into memory. Whether you needed it or not, but it was read; and if you needed to read M1, it was read from 1999 (in case there was available history) till the current date, hour and minute.
Now only the necessary range can be read, which considerably saves time and memory.
   MqlRates rates_arrayG[];
   Int Bar=30; // read only 30 bars stating from the zero one
   iCopBar=CopyRates(Symbol(),PERIOD_M1,0,Bar,rates_arrayG);
This feature saves both time and memory.
Such a change in functionality doesn't frighten. We'll simply need time to learn new functions-analogs.

Some functional innovations that I waited from MQL:

  • OnTimer() - function to process the timer events (now you don't need to loop the Expert Advisor to make it work with a certain periodicity independent of the incoming tick);
  • OnTrade() - function to process trade events - trade position opening, closing or volume change;
  • OnChartEvent() - processing events by teh mouse or keyboard.

Let's dwell a little on them.
The OnTimer() function is called if the timer is pre-initialized in the OnInit preset function (processor of EA initialization events).
Example:
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1); //each second we'll refer to OnTimer()
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit()
  {
   EventKillTimer(); // canceling of timer reference must be called at exit
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer()
  {
   MqlDateTime str1;
   TimeGMT(str1); // new function to get GMT time
   Comment(str1.hour
           ,str1.min
           ,str1.sec
           ,str1.day
           ,str1.mon
           ,str1.year
           ,str1.day_of_year
           ,OrdersTotal()
           ,PositionsTotal()
           );
  }
So, control can be obtained not only at tick receipt as it was earlier, but also from the timer which allows writing real-time manageable programs. With this possibility more elaborate systems can be created.
I liked the OnTrade() function. This function is called at the moment when any of the following trade events triggers: order placing, activation of StopLoss or TakeProfit, change of StopLoss or TakeProfit levels, placing/deletion of a pending order.
Now it's much easier to monitor events connected with trade operations. Now there is no need in loops checking the state of orders at ticks or bars. Such loops are used in MQL4, which considerably reduces the program's performance so important in optimization.
Let's dwell on the OnChartEvent() function. The function call is performed for several events. I didn't manage to test each of them, but the list is impressive:
  • CHARTEVENT_KEYDOWN — key pressing event;
  • CHARTEVENT_OBJECT_CLICK — event of a mouse click on a graphical object belonging to a chart;
  • CHARTEVENT_OBJECT_DRAG — event of a graphical object moving performed by a mouse;
  • CHARTEVENT_OBJECT_ENDEDIT — event of text editing end;
  • CHARTEVENT_CUSTOM+n — identifier of a custom event;
  • CHARTEVENT_CUSTOM_LAST — the last one.

The possibility to manage trading and graphics on a new functional level - this is what the developers have promised.

New graphical objects, buttons, entry field appeared. Chart management has become fantastic, one can even insert pictures from files - this option offers a lot of possibilities for those who like special design. This is not Photoshop, this is the result of MQL5 and MetaTrader 5 possibilities. Among new features is that you can create your own buttons and entry fields adding, for example, a button to close all the open orders, or the button of quick Buy and Sell with preset stop and take parameters.
Fig. 2. Graphical objects allow creating an informational panel.
There is one unpleasant fact: objects cannot be created from indicators. This was made intentionally to quicken the performance of indicators. The good news is that they understand it and, probably, will implement the possibility to start several Expert Advisors in one chart. Thus we'll be able to create EA-indicators with objects and without trading. Such indicators can be created now - they will operate like indicators. Now the task is solved by starting a trading EA in one chart and the EA creating objects in the second one, and then implement the exchange between them.
For example, I managed to transform my breakthrough indicator from MQL4 to MQL5 in several hours. The most time was taken by the function learning and debugging. In MQL5 the code has become shorter.
As for the terminal itself, I was impressed by the number of timeframes. In my opinion there's even the excess. Though, the abundance of minute timeframes can be useful for some traders. Well, now there is only one step to the creation of a freely set timeframe. All data are stored now only as a minute timeframe, so there are no problems with the synchronization of different timeframes - this is an important technological solution.

Now there are no files for different timeframes in the HISTORY catalog



Fig. 3. The whole history is stored in a single file.

Another pleasant introduction is that now we can clear logs.

Fig. 4. Use one button to clear the EA Journal, do delete all unnecessary messages.
This is just a brief review of MetaTrader 5. I can't describe all the system's new features for such a short time period - the testing started on 2009.09.09. This is a symbolical date, and I am sure it will be a lucky number. A few days have passed since I got the beta version of the MetaTrader 5 terminal and MQL5. I haven't managed to try all its features, but I am already impressed.
The magicians from MetaQuotes have created an amazing product. I am a developer with 25 years of experience, have seen the start of many projects and can state this for sure!

Example programming: mql4 vs mql5

MQL5 is the development of its predecessor - the MQL4 language, in which numerous indicators, scripts, and Expert Advisors were written. Despite the fact that the new programming language is maximally compatible with the previous-generation language, there are still some differences between these languages. And when transferring programs these differences should be noted.
This section contains information intended to facilitate the adaptation of codes to the new MQL5 language for programmers who know MQL4.
First it should be noted:
  • The new language does not contain functions start(), init() and deinit();
  • The number of indicator buffers is not limited;
  • dll is downloaded immediately after downloading an Expert Advisor (or any other mql5 program);
  • Check of logical conditions is shortened;
  • When limits of an array are exceeded, the current performance is terminated (critically - with the output of an errors);
  • Precedence of operators like in C + +;
  • The language offers the implicit type cast (even from string to a number);
  • Local variables are not initialized automatically (except for strings);
  • Common local arrays are automatically deleted.

Special Functions init, start and deinit

The MQL4 language contained only three predefined functions that could be used in the indicator, script or Expert Advisor (not taking into account the include files *.mqh and library files). In MQL5 there are no such functions, but there are their analogues. The table shows the approximate correspondence of functions.
MQL4
MQL5
init
OnInit
start
OnStart
deinit
OnDeinit
Functions OnInit and OnDeinit perform the same role as init and deinit in MQL4 - they are designed to locate the code, which must be performed during initialization and deinitialization of mql5 programs. You can either just rename these functions accordingly, or leave them as they are, but add calls of these functions in corresponding places.
Example:
void OnInit()
  {
//--- Functions is called to initialize
   init();
  }
void OnDeinit(const int reason)
  {
//--- Call the function with deinitialization
   deinit();
//---
  }
The start function is replaced by OnStart only in scripts. In Expert Advisors and indicators it should be renamed to OnTick and OnCalculate, respectively. The code that is to be executed during a mql5 program operation should be located in these three functions:
mql5-program
main function
OnStart
OnCalculate
OnTick
If the indicator or script code does not contain the main function, or the function name differs from the required one, the call of this function is not performed. It means, if the source code of a script doesn't contain OnStart, such a code will be compiled as an Expert Advisor.
If an indicator code doesn't contain the OnCalculate function, the compilation of such an indicator is impossible.

Predefined Variables

In MQL5 there are no such predefined variables as Ask, Bid, Bars. Variables Point and Digits have a slightly different spelling:
MQL4
MQL5
Digits
_Digits
Point
_Point

_LastError

_Period

_Symbol

_StopFlag

_UninitReason

Access to Timeseries

In MQL5 there are no such predefined timeseries as Open [], High [], Low [], Close [], Volume [] and Time []. The necessary depth of a timeseries can now be set using corresponding functions to access timeseries.

Expert Advisors

Expert Advisors in MQL5 do not require the obligatory presence of the function for handling the events of a new tick receipt - OnTick, as it was in MQL4 (the start function in MQL4 is executed when you receive a new tick), because in MQL5 Expert Advisors can contain pre-defined handler functions are several types of events:
  • OnChartEvent – events of input from the keyboard and mouse, events of a graphic object moving, event of a text editing completion in the entry field of the LabelEdit object;
  • OnBookEvent – event of Depth of Market status change.

Custom Indicators

In MQL4, the number of indicator buffers is limited and can't exceed 8. In MQL5 there are no such limitations, but it should be remembered that each indicator buffer requires allocation of a certain part of memory for its location in the terminal, so the new possibility should not be abused.
MQL4 offered only 6 types of custom indicator plotting; while MQL5 now offers 18 drawing styles. The names of drawing types haven't changed, but the ideology of the graphical representation of indicators has changed significantly.
The direction of indexing in indicator buffers also differs. By default, in MQL5 all the indicator buffers have the behavior of common arrays, i.e. 0 indexed element is the oldest one in the history, and as the index increases, we move from the oldest data to the most recent ones.
The only function for working with custom indicators that was preserved from MQL4 is SetIndexBuffer. But its call has changed; now you should specify type of data to be stored in an array, linked to the indicator buffer.
Properties of custom indicators also have changed and expanded. New functions for accessing timeseries have been added, so the total calculation algorithm must be reconsidered.

Graphical Objects

The number of graphical objects in has increased significantly MQL5. Besides, graphical objects can now be positioned in time with the accuracy of a second in a chart of any timeframe - now object anchor points are not rounded off to the bar opening time in the current price chart.
For objects Arrow, Text and Label now way of binding can be indicated, and for Label, Button, Chart, Bitmap Label and Edit chart corner, to which the object is anchored, can be set.

Programming of mql4 vs mql5

The MetaQuotes folks brang a lot of improvements to the new language MQL5 vs the old MQL4.

Data types
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 , ulong
This time the structures appear too:
struct, class

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

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

Notes:
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

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

Finding value of high & low

double High[],Low[];
//+------------------------------------------------------------------+
//| Get Low for specified bar index                                  |
//+------------------------------------------------------------------+
double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index)
  {
   double low=0;
   ArraySetAsSeries(Low,true);
   int copied=CopyLow(symbol,timeframe,0,Bars(symbol,timeframe),Low);
   if(copied>0 && index<copied) low=Low[index];
   return(low);
  }
//+------------------------------------------------------------------+
//| Get the High for specified bar index                             |
//+------------------------------------------------------------------+
double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index)
  {
   double high=0;
   ArraySetAsSeries(High,true);
   int copied=CopyHigh(symbol,timeframe,0,Bars(symbol,timeframe),High);
   if(copied>0 && index<copied) high=High[index];
   return(high);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- at each tick we output the High and Low values for the bar with index,
//--- equal of the tick second
   datetime t=TimeCurrent();
   int sec=t%60;
   printf("High[%d] = %G  Low[%d] = %G",
          sec,iHigh(Symbol(),0,sec),
          sec,iLow(Symbol(),0,sec));
  }

Calculate optimal lot size

Version 1
========== 
// setting parameter
input double MaximumRisk = 0.02; // Maximum Risk in percentage
input double DecreaseFactor = 3; // Descrease factor

//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double TradeSizeOptimized(void)
{
double price=1.0;
double margin=0.1;
//--- select lot size
if(!SymbolInfoDouble(_Symbol,SYMBOL_ASK,price)) return(0.0);
if(!OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1.0,price,margin)) return(0.0);
if(margin<=0.0) return(0.0);

double lot=NormalizeDouble(AccountInfoDouble(ACCOUNT_FREEMARGIN)*MaximumRisk/margin,2);
//--- calculate number of losses orders without a break
if(DecreaseFactor>0)
{
//--- select history for access
HistorySelect(0,TimeCurrent());
//---
int orders=HistoryDealsTotal(); // total history deals
int losses=0; // number of losses orders without a break

for(int i=orders-1;i>=0;i--)
{
ulong ticket=HistoryDealGetTicket(i);
if(ticket==0)
{
Print("HistoryDealGetTicket failed, no trade history");
break;
}
//--- check symbol
if(HistoryDealGetString(ticket,DEAL_SYMBOL)!=_Symbol) continue;
//--- check profit
double profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
if(profit>0.0) break;
if(profit<0.0) losses++;
}
//---
if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
}
//--- normalize and check limits
double stepvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
lot=stepvol*NormalizeDouble(lot/stepvol,0);

double minvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
if(lot<minvol) lot=minvol;

double maxvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
if(lot>maxvol) lot=maxvol;
//--- return trading volume
return(lot);
}

Version 2
==============

//+------------------------------------------------------------------+
//| Calculation of the lot |
//+------------------------------------------------------------------+
double Calculate_Lot(double lot_value,int type,ENUM_ORDER_TYPE direction)
//+------------------------------------------------------------------+
{
double acc_free_margin=AccountInfoDouble(ACCOUNT_FREEMARGIN);
double calc_margin;
double price=0;

if(direction == ORDER_TYPE_BUY) price = tick.ask;
if(direction == ORDER_TYPE_SELL) price = tick.bid;

switch(type)
{
case fixed:
{
//--- Correction of lot size
if(LOT_CORRECTION)
{
OrderCalcMargin(direction,_Symbol,lot_value,price,calc_margin);
//--- Lot size correction of up to 90% of free margin
if(acc_free_margin<calc_margin)
{
lot_value=lot_value*acc_free_margin*0.9/calc_margin;
printf("Adjusted value of the lot: %f",lot);
}
}
break;
}

case percent:
{
//--- value of free margin for open position
OrderCalcMargin(direction,_Symbol,1,price,calc_margin);
lot_value=acc_free_margin*0.01*LOT/calc_margin;
break;
}
}// end switch

return(NormalizeLot(lot_value));
}

//+------------------------------------------------------------------+
//| Normalization of the lot size |
//+------------------------------------------------------------------+
double NormalizeLot(double lot_value)
//+------------------------------------------------------------------+
{
double lot_min = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double lot_max = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
double lot_step = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
int norm;

if(lot_value <= lot_min ) lot_value = lot_min; // checking for minimum lot
else if(lot_value >= lot_max ) lot_value = lot_max; // checking the maximum lot
else(lot_value = MathFloor(lot_value/ lot_step) * lot_step); // rounding to the nearest

norm=(int)NormalizeDouble(MathCeil(MathLog10(1/lot_step)),0);// coefficient for NormalizeDouble
return(NormalizeDouble(lot_value,norm)); // normalization
}
//+------------------------------------------------------------------+