280 lines
8.8 KiB
MQL5
280 lines
8.8 KiB
MQL5
|
#ifndef LIB_MQLPLUS_MQL4_COMPATIBILITY_ORDER_MQH_INCLUDED
|
||
|
#define LIB_MQLPLUS_MQL4_COMPATIBILITY_ORDER_MQH_INCLUDED
|
||
|
#property version "1.0";
|
||
|
#property strict
|
||
|
/**********************************************************************************
|
||
|
* Copyright (C) 2010-2022 Dominik Egert <info@freie-netze.de>
|
||
|
*
|
||
|
* This file is the MQL4 backward compatibility include file.
|
||
|
*
|
||
|
* MQLplus, including this file may not be copied and/or distributed
|
||
|
* without explecit permit by the author.
|
||
|
* Author Dominik Egert / Freie Netze UG.
|
||
|
**********************************************************************************
|
||
|
*
|
||
|
* Version: 1.0
|
||
|
* State: development
|
||
|
*
|
||
|
* File information
|
||
|
* ================
|
||
|
*
|
||
|
*
|
||
|
*
|
||
|
*/
|
||
|
#ifdef DBG_MSG_TRACE_FILE_LOADER
|
||
|
DBG_MSG_TRACE_FILE_LOADER;
|
||
|
|
||
|
#endif
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//*********************************************************************************************************************************************************/
|
||
|
//
|
||
|
// BEGIN MQL4 compatibility additions
|
||
|
//
|
||
|
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Add required MQL5 enumerations
|
||
|
//
|
||
|
enum MT5_ENUM_ORDER_PROPERTY_INTEGER
|
||
|
{
|
||
|
MT5_ORDER_TICKET,
|
||
|
MT5_ORDER_TIME_SETUP,
|
||
|
MT5_ORDER_TYPE,
|
||
|
MT5_ORDER_STATE,
|
||
|
MT5_ORDER_TIME_EXPIRATION,
|
||
|
MT5_ORDER_TIME_DONE,
|
||
|
MT5_ORDER_TIME_SETUP_MSC,
|
||
|
MT5_ORDER_TIME_DONE_MSC,
|
||
|
MT5_ORDER_TYPE_FILLING,
|
||
|
MT5_ORDER_TYPE_TIME,
|
||
|
MT5_ORDER_MAGIC,
|
||
|
MT5_ORDER_REASON,
|
||
|
MT5_ORDER_POSITION_ID,
|
||
|
MT5_ORDER_POSITION_BY_ID
|
||
|
};
|
||
|
|
||
|
|
||
|
enum MT5_ENUM_ORDER_PROPERTY_STRING
|
||
|
{
|
||
|
MT5_ORDER_SYMBOL,
|
||
|
MT5_ORDER_COMMENT,
|
||
|
MT5_ORDER_EXTERNAL_ID
|
||
|
};
|
||
|
|
||
|
|
||
|
enum ENUM_ORDER_REASON
|
||
|
{
|
||
|
ORDER_REASON_CLIENT,
|
||
|
ORDER_REASON_MOBILE,
|
||
|
ORDER_REASON_WEB,
|
||
|
ORDER_REASON_EXPERT,
|
||
|
ORDER_REASON_SL,
|
||
|
ORDER_REASON_TP,
|
||
|
ORDER_REASON_SO
|
||
|
};
|
||
|
|
||
|
|
||
|
//
|
||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
|
||
|
|
||
|
//+------------------------------------------------------------------+
|
||
|
//| MQL4: MQL5-compatible _OrdersTotal() |
|
||
|
//+------------------------------------------------------------------+
|
||
|
const int _OrdersTotal()
|
||
|
{
|
||
|
int ptr = OrdersTotal();
|
||
|
int cnt = NULL;
|
||
|
while( (ptr >= NULL)
|
||
|
&& (!_StopFlag) )
|
||
|
{ cnt += (OrderSelect(ptr, SELECT_BY_POS, MODE_TRADES)) && (OrderType() > OP_SELL); }
|
||
|
|
||
|
// Return
|
||
|
return(cnt);
|
||
|
}
|
||
|
#define OrdersTotal _OrdersTotal
|
||
|
|
||
|
|
||
|
|
||
|
//+------------------------------------------------------------------+
|
||
|
//| MQL4: MQL5-compatible OrderGetTicket() |
|
||
|
//+------------------------------------------------------------------+
|
||
|
#define OrderGetTicket(x) (OrderSelect(x, SELECT_BY_POS, MODE_TRADES) && (OrderType() > OP_SELL) ? (ulong)OrderTicket() : (ulong)0)
|
||
|
|
||
|
|
||
|
|
||
|
//+------------------------------------------------------------------+
|
||
|
//| MQL4: MQL5-compatible OrderSelect() |
|
||
|
//+------------------------------------------------------------------+
|
||
|
const bool mt4_OrderSelect(const int index, const int select, const int pool = MODE_TRADES)
|
||
|
{ return(OrderSelect(index, select, pool)); }
|
||
|
#define OrderSelect(x) mt4_OrderSelect(x, SELECT_BY_TICKET, MODE_TRADES)
|
||
|
|
||
|
|
||
|
/*
|
||
|
//+------------------------------------------------------------------+
|
||
|
//| MQL4: MQL5-compatible OrderGetDouble() |
|
||
|
//+------------------------------------------------------------------+
|
||
|
const bool _OrderGetDouble(const ENUM_ORDER_PROPERTY_DOUBLE property_id, double& double_var)
|
||
|
{
|
||
|
double_var = _OrderGetDouble(property_id);
|
||
|
return(double_var != DBL_MIN);
|
||
|
}
|
||
|
|
||
|
const double _OrderGetDouble(const ENUM_ORDER_PROPERTY_DOUBLE property_id)
|
||
|
{
|
||
|
switch(property_id)
|
||
|
{
|
||
|
case ORDER_VOLUME_INITIAL:
|
||
|
case ORDER_VOLUME_CURRENT:
|
||
|
case ORDER_PRICE_OPEN:
|
||
|
case ORDER_SL:
|
||
|
case ORDER_TP:
|
||
|
case ORDER_PRICE_CURRENT:
|
||
|
case ORDER_PRICE_STOPLIMIT:
|
||
|
return(OrderGetDouble(property_id));
|
||
|
}
|
||
|
|
||
|
// Return
|
||
|
return(DBL_MIN);
|
||
|
}
|
||
|
//#define OrderGetDouble _OrderGetDouble
|
||
|
*/
|
||
|
|
||
|
|
||
|
//+------------------------------------------------------------------+
|
||
|
//| MQL4: MQL5-compatible OrderGetInteger() |
|
||
|
//+------------------------------------------------------------------+
|
||
|
const bool mt5_OrderGetInteger(const MT5_ENUM_ORDER_PROPERTY_INTEGER property_id, long& long_var)
|
||
|
{
|
||
|
long_var = mt5_OrderGetInteger(property_id);
|
||
|
return(long_var != LONG_MIN);
|
||
|
}
|
||
|
|
||
|
const long mt5_OrderGetInteger(const MT5_ENUM_ORDER_PROPERTY_INTEGER property_id)
|
||
|
{
|
||
|
switch(property_id)
|
||
|
{
|
||
|
// MQL4 supported
|
||
|
case MT5_ORDER_TIME_SETUP:
|
||
|
return(OrderGetInteger(ORDER_TIME_SETUP));
|
||
|
|
||
|
case MT5_ORDER_TYPE:
|
||
|
return(OrderGetInteger(ORDER_TYPE));
|
||
|
|
||
|
case MT5_ORDER_STATE:
|
||
|
return(OrderGetInteger(ORDER_STATE));
|
||
|
|
||
|
case MT5_ORDER_TIME_EXPIRATION:
|
||
|
return(OrderGetInteger(ORDER_TIME_EXPIRATION));
|
||
|
|
||
|
case MT5_ORDER_TIME_DONE:
|
||
|
return(OrderGetInteger(ORDER_TIME_DONE));
|
||
|
|
||
|
case MT5_ORDER_TIME_SETUP_MSC:
|
||
|
return(OrderGetInteger(ORDER_TIME_SETUP_MSC));
|
||
|
|
||
|
case MT5_ORDER_TIME_DONE_MSC:
|
||
|
return(OrderGetInteger(ORDER_TIME_DONE_MSC));
|
||
|
|
||
|
case MT5_ORDER_TYPE_FILLING:
|
||
|
return(OrderGetInteger(ORDER_TYPE_FILLING));
|
||
|
|
||
|
case MT5_ORDER_TYPE_TIME:
|
||
|
return(OrderGetInteger(ORDER_TYPE_TIME));
|
||
|
|
||
|
case MT5_ORDER_MAGIC:
|
||
|
return(OrderGetInteger(ORDER_MAGIC));
|
||
|
|
||
|
// MQL5 specific
|
||
|
case MT5_ORDER_TICKET:
|
||
|
return((OrderType() > OP_SELL) ? (long)OrderTicket() : LONG_MIN);
|
||
|
|
||
|
case MT5_ORDER_REASON:
|
||
|
if(OrderMagicNumber() != 0)
|
||
|
{ return((long)ORDER_REASON_EXPERT); }
|
||
|
|
||
|
case MT5_ORDER_POSITION_ID:
|
||
|
case MT5_ORDER_POSITION_BY_ID:
|
||
|
#ifdef _DEBUG
|
||
|
printf("Feature not supported in MQL4: %s; %s", __FUNCTION__, EnumToString(property_id));
|
||
|
|
||
|
#else
|
||
|
break;
|
||
|
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
// Return
|
||
|
return(LONG_MIN);
|
||
|
}
|
||
|
#define OrderGetInteger mt5_OrderGetInteger
|
||
|
#define ENUM_ORDER_PROPERTY_INTEGER MT5_ENUM_ORDER_PROPERTY_INTEGER
|
||
|
#define ORDER_TICKET MT5_ORDER_TICKET
|
||
|
#define ORDER_TIME_SETUP MT5_ORDER_TIME_SETUP
|
||
|
#define ORDER_TYPE MT5_ORDER_TYPE
|
||
|
#define ORDER_STATE MT5_ORDER_STATE
|
||
|
#define ORDER_TIME_EXPIRATION MT5_ORDER_TIME_EXPIRATION
|
||
|
#define ORDER_TIME_DONE MT5_ORDER_TIME_DONE
|
||
|
#define ORDER_TIME_SETUP_MSC MT5_ORDER_TIME_SETUP_MSC
|
||
|
#define ORDER_TIME_DONE_MSC MT5_ORDER_TIME_DONE_MSC
|
||
|
#define ORDER_TYPE_FILLING MT5_ORDER_TYPE_FILLING
|
||
|
#define ORDER_TYPE_TIME MT5_ORDER_TYPE_TIME
|
||
|
#define ORDER_MAGIC MT5_ORDER_MAGIC
|
||
|
#define ORDER_REASON MT5_ORDER_REASON
|
||
|
#define ORDER_POSITION_ID MT5_ORDER_POSITION_ID
|
||
|
#define ORDER_POSITION_BY_ID MT5_ORDER_POSITION_BY_ID
|
||
|
|
||
|
|
||
|
|
||
|
//+------------------------------------------------------------------+
|
||
|
//| MQL4: MQL5-compatible OrderGetString() |
|
||
|
//+------------------------------------------------------------------+
|
||
|
const bool mt5_OrderGetString(const MT5_ENUM_ORDER_PROPERTY_STRING property_id, string& string_var)
|
||
|
{
|
||
|
string_var = mt5_OrderGetString(property_id);
|
||
|
return(string_var != "");
|
||
|
}
|
||
|
|
||
|
const string mt5_OrderGetString(const MT5_ENUM_ORDER_PROPERTY_STRING property_id)
|
||
|
{
|
||
|
switch(property_id)
|
||
|
{
|
||
|
// MQL4 supported
|
||
|
case MT5_ORDER_SYMBOL:
|
||
|
return(OrderGetString(ORDER_SYMBOL));
|
||
|
|
||
|
case MT5_ORDER_COMMENT:
|
||
|
return(OrderGetString(ORDER_COMMENT));
|
||
|
|
||
|
// MQL5 specific
|
||
|
case MT5_ORDER_EXTERNAL_ID:
|
||
|
#ifdef _DEBUG
|
||
|
printf("Feature not supported in MQL4: %s; %s", __FUNCTION__, EnumToString(property_id));
|
||
|
|
||
|
#else
|
||
|
break;
|
||
|
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
// Return
|
||
|
return("");
|
||
|
}
|
||
|
#define OrderGetString mt5_OrderGetString
|
||
|
#define ENUM_ORDER_PROPERTY_STRING MT5_ENUM_ORDER_PROPERTY_STRING
|
||
|
#define ORDER_SYMBOL MT5_ORDER_SYMBOL
|
||
|
#define ORDER_COMMENT MT5_ORDER_COMMENT
|
||
|
#define ORDER_EXTERNAL_ID MT5_ORDER_EXTERNAL_ID
|
||
|
|
||
|
|
||
|
//
|
||
|
// END MQL compatibility */
|
||
|
//*********************************************************************************************************************************************************/
|
||
|
#endif // LIB_MQLPLUS_MQL4_COMPATIBILITY_ORDER_MQH_INCLUDED
|