#define TICKET 1819621374 // ticket of any known order, for example, from the account history
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- select a historical order by the ticket specified in TICKET
if(!HistoryOrderSelect(TICKET))
{
PrintFormat("HistoryOrderSelect(%I64u) failed. Error %d", TICKET, GetLastError());
return;
}
//--- if an order is successfully selected, get its data and display the order description in the journal
ENUM_ORDER_TYPE order_type = (ENUM_ORDER_TYPE)HistoryOrderGetInteger(TICKET, ORDER_TYPE);
ENUM_ORDER_STATE order_state = (ENUM_ORDER_STATE)HistoryOrderGetInteger(TICKET, ORDER_STATE);
ENUM_ORDER_REASON order_reason= (ENUM_ORDER_REASON)HistoryOrderGetInteger(TICKET, ORDER_REASON);
long order_time = HistoryOrderGetInteger(TICKET, ORDER_TIME_SETUP_MSC);
string order_symbol=HistoryOrderGetString(TICKET, ORDER_SYMBOL);
double order_vol_init=HistoryOrderGetDouble(TICKET, ORDER_VOLUME_INITIAL);
double order_vol_curr=HistoryOrderGetDouble(TICKET, ORDER_VOLUME_CURRENT);
PrintFormat("%s Order %.2f/%s %s #%I64u %s by %s at %s",
order_symbol, order_vol_init, (order_vol_curr>0 ? DoubleToString(order_vol_curr,2) : "0"),
OrderTypeDescription(order_type), TICKET, OrderStateDescription(order_state),
OrderReasonDescription(order_reason), TimeMscToString(order_time));
/*
result for various specified tickets:
EURUSD Order 0.50/0.50 Buy Limit #2812894647 Canceled by Client at 2024.09.04 19:02:31.793
EURUSD Order 0.10/0 Sell #1753011743 Filled by Take Profit at 2023.06.12 17:04:20.353
GBPUSD Order 0.10/0 Buy #1819621374 Filled by Client at 2023.07.24 06:16:25.746
*/
}
//+------------------------------------------------------------------+
//| Return the order type description |
//+------------------------------------------------------------------+
string OrderTypeDescription(const ENUM_ORDER_TYPE type)
{
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");
default : return("Unknown order type: "+(string)type);
}
}
//+------------------------------------------------------------------+
//| Return the order status description |
//+------------------------------------------------------------------+
string OrderStateDescription(ENUM_ORDER_STATE state)
{
switch(state)
{
case ORDER_STATE_STARTED : return("Started");
case ORDER_STATE_PLACED : return("Placed");
case ORDER_STATE_CANCELED : return("Canceled");
case ORDER_STATE_PARTIAL : return("Partial");
case ORDER_STATE_FILLED : return("Filled");
case ORDER_STATE_REJECTED : return("Rejected");
case ORDER_STATE_EXPIRED : return("Expired");
case ORDER_STATE_REQUEST_ADD : return("Request Add");
case ORDER_STATE_REQUEST_MODIFY : return("Request Modify");
case ORDER_STATE_REQUEST_CANCEL : return("Request Cancel");
default : return("Unknown state: "+(string)state);
}
}
//+------------------------------------------------------------------+
//| Return the order placement reason description |
//+------------------------------------------------------------------+
string OrderReasonDescription(const ENUM_ORDER_REASON reason)
{
switch(reason)
{
case ORDER_REASON_CLIENT : return("Client");
case ORDER_REASON_MOBILE : return("Mobile");
case ORDER_REASON_WEB : return("Web");
case ORDER_REASON_EXPERT : return("Expert");
case ORDER_REASON_SL : return("Stop Loss");
case ORDER_REASON_TP : return("Take Profit");
case ORDER_REASON_SO : return("Stop Out");
default : return("Unknown reason: "+(string)reason);
}
}
//+------------------------------------------------------------------+
//| Return time with milliseconds |
//+------------------------------------------------------------------+
string TimeMscToString(const long time_msc, int flags=TIME_DATE|TIME_MINUTES|TIME_SECONDS)
{
return(TimeToString(time_msc/1000, flags) + "." + IntegerToString(time_msc %1000, 3, '0'));
}
|