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);
}

1 comment: