MT5所有二次封装交易信息描述函数集合

博客可能围绕MT5和MQL5展开,重点涉及交易函数相关内容,在信息技术领域,MT5常用于金融交易软件,MQL5是其配套编程语言,交易函数是实现交易操作的关键代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
// 公用函数
void   SetTransactionBelong(const ENUM_TRADE_TRANSACTION_TYPE type,bool &request_flag,bool &order_flag,bool &deal_flag,bool &position_flag)
string TradeTransactionTypeDescription(const ENUM_TRADE_TRANSACTION_TYPE transaction, const bool ext_descr=false)
string RetcodeDescription(const uint retcode,bool ext_descr=false)
string OrderTypeDescription(const ENUM_ORDER_TYPE type, const bool ext_descr=false)
string OrderTypeFillingDescription(const ENUM_ORDER_TYPE_FILLING type_filling, const bool ext_descr=false)
string OrderStateDescription(const ENUM_ORDER_STATE state, const bool ext_descr=false)
string DealTypeDescription(const ENUM_DEAL_TYPE type, const bool ext_descr=false)
string OrderTypeTimeDescription(const ENUM_ORDER_TYPE_TIME type_time, const bool ext_descr=false)
// MqlTradeTransaction 相关函数
string MqlTradeTransactionDeal(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
string MqlTradeTransactionOrder(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
string MqlTradeTransactionSymbol(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
string MqlTradeTransactionType(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
string MqlTradeTransactionOrderType(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
string MqlTradeTransactionOrderState(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
string MqlTradeTransactionDealType(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
string MqlTradeTransactionTimeType(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
string MqlTradeTransactionTimeExpiration(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
string MqlTradeTransactionPrice(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
string MqlTradeTransactionPriceTrigger(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
string MqlTradeTransactionPriceSL(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
string MqlTradeTransactionPriceTP(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
string MqlTradeTransactionVolume(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
string MqlTradeTransactionPosition(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
string MqlTradeTransactionPositionBy(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)

// MqlTradeRequest 相关函数
string MqlTradeRequestAction(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
string MqlTradeRequestMagic(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestOrder(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestSymbol(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestVolume(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestPrice(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestStopLimit(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestStopLoss(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestTakeProfit(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestDeviation(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestType(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0,bool ext_descr=false)
string MqlTradeRequestTypeFilling(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0,bool ext_descr=false)
string MqlTradeRequestTypeTime(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0,bool ext_descr=false)
string MqlTradeRequestExpiration(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestComment(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestPosition(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
string MqlTradeRequestPositionBy(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)

// MqlTradeCheckResult 相关函数
string MqlTradeCheckResultRetcode(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
string MqlTradeCheckResultBalance(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeCheckResultEquity(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeCheckResultProfit(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeCheckResultMargin(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeCheckResultMarginFree(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeCheckResultMarginLevel(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeCheckResultComment(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
//
// MqlTradeResult 相关函数
string MqlTradeResultRetcode(const MqlTradeResult &result, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
string MqlTradeResultDeal(const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeResultOrder(const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeResultVolume(const string symbol, const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeResultPrice(const string symbol, const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeResultBid(const string symbol, const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeResultAsk(const string symbol, const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeResultComment(const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeResultRequestID(const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
string MqlTradeResultRetcodeExternal(const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
 * */

//+------------------------------------------------------------------+
//| Define and set transaction affiliation values                    |
//+------------------------------------------------------------------+
void SetTransactionBelong(const ENUM_TRADE_TRANSACTION_TYPE type,bool &request_flag,bool &order_flag,bool &deal_flag,bool &position_flag)
{
    switch(type)
    {
        //--- Request
        case TRADE_TRANSACTION_REQUEST         : request_flag=true; order_flag=false; deal_flag=false; position_flag=false; break;
                                                 //--- Order
        case TRADE_TRANSACTION_ORDER_ADD       :
        case TRADE_TRANSACTION_ORDER_UPDATE    :
        case TRADE_TRANSACTION_ORDER_DELETE    :
        case TRADE_TRANSACTION_HISTORY_ADD     :
        case TRADE_TRANSACTION_HISTORY_UPDATE  :
        case TRADE_TRANSACTION_HISTORY_DELETE  : request_flag=false; order_flag=true; deal_flag=false; position_flag=false; break;
                                                 //--- Deal
        case TRADE_TRANSACTION_DEAL_ADD        :
        case TRADE_TRANSACTION_DEAL_UPDATE     :
        case TRADE_TRANSACTION_DEAL_DELETE     : request_flag=false; order_flag=false; deal_flag=true; position_flag=false; break;
                                                 //--- Position
        case TRADE_TRANSACTION_POSITION        : request_flag=false; order_flag=false; deal_flag=false; position_flag=true; break;
                                                 //---
        default: break;
    }
}
//+------------------------------------------------------------------+
//| Return a description of the trade transaction type               |
//+------------------------------------------------------------------+
string TradeTransactionTypeDescription(const ENUM_TRADE_TRANSACTION_TYPE transaction, const bool ext_descr=false)
{
    //--- "Cut out" the transaction type from the string obtained from enum
    string res=StringSubstr(EnumToString(transaction),18);
    //--- Convert all obtained symbols to lower case and replace the first letter from small to capital
    if(res.Lower())
        res.SetChar(0,ushort(res.GetChar(0)-0x20));
    //--- Replace all underscore characters with space in the resulting line
    StringReplace(res,"_"," ");
    string descr="";
    switch(transaction)
    {
        case TRADE_TRANSACTION_ORDER_ADD       :  descr=" (Adding a new open order)";                                                                   break;
        case TRADE_TRANSACTION_ORDER_UPDATE    :  descr=" (Updating an open order)";                                                                    break;
        case TRADE_TRANSACTION_ORDER_DELETE    :  descr=" (Removing an order from the list of the open ones)";                                          break;
        case TRADE_TRANSACTION_DEAL_ADD        :  descr=" (Adding a deal to the history)";                                                              break;
        case TRADE_TRANSACTION_DEAL_UPDATE     :  descr=" (Updating a deal in the history)";                                                            break;
        case TRADE_TRANSACTION_DEAL_DELETE     :  descr=" (Deleting a deal from the history)";                                                          break;
        case TRADE_TRANSACTION_HISTORY_ADD     :  descr=" (Adding an order to the history as a result of execution or cancellation)";                   break;
        case TRADE_TRANSACTION_HISTORY_UPDATE  :  descr=" (Changing an order located in the orders history)";                                           break;
        case TRADE_TRANSACTION_HISTORY_DELETE  :  descr=" (Deleting an order from the orders history)";                                                 break;
        case TRADE_TRANSACTION_POSITION        :  descr=" (Changing a position not related to a deal execution)";                                       break;
        case TRADE_TRANSACTION_REQUEST         :  descr=" (The trade request has been processed by a server and processing result has been received)";  break;
        default: break;
    }
    return res+(!ext_descr ? "" : descr);
    /* Sample output:
       Order add (Adding a new open order)
     */
}
//+------------------------------------------------------------------+
//| Return a description of the trade server return code             |
//+------------------------------------------------------------------+
string RetcodeDescription(const uint retcode,bool ext_descr=false)
{
    switch(retcode)
    {
        //--- Done
        case 0                                 :  return "OK (0)";
                                                  //--- Requote
        case TRADE_RETCODE_REQUOTE             :  return "10004 REQUOTE"+(ext_descr ? " (Requote)" : "");
                                                  //--- Request rejected
        case TRADE_RETCODE_REJECT              :  return "10006 REJECT"+(ext_descr ? " (Request rejected)" : "");
                                                  //--- Request canceled by a trader
        case TRADE_RETCODE_CANCEL              :  return "10007 CANCEL"+(ext_descr ? " (Request canceled by trader)" : "");
                                                  //--- Order placed
        case TRADE_RETCODE_PLACED              :  return "10008 PLACED"+(ext_descr ? " (Order placed)" : "");
                                                  //--- Request executed
        case TRADE_RETCODE_DONE                :  return "10009 DONE"+(ext_descr ? " (Request completed)" : "");
                                                  //--- Request executed partially
        case TRADE_RETCODE_DONE_PARTIAL        :  return "10010 DONE_PARTIAL"+(ext_descr ? " (Only part of the request was completed)" : "");
                                                  //--- Request handling error
        case TRADE_RETCODE_ERROR               :  return "10011 ERROR"+(ext_descr ? " (Request processing error)" : "");
                                                  //--- Request expired
        case TRADE_RETCODE_TIMEOUT             :  return "10012 TIMEOUT"+(ext_descr ? " (Request canceled by timeout)" : "");
                                                  //--- Invalid request
        case TRADE_RETCODE_INVALID             :  return "10013 INVALID"+(ext_descr ? " (Invalid request)" : "");
                                                  //--- Invalid request volume
        case TRADE_RETCODE_INVALID_VOLUME      :  return "10014 INVALID_VOLUME"+(ext_descr ? " (Invalid volume in the request)" : "");
                                                  //--- Invalid request price
        case TRADE_RETCODE_INVALID_PRICE       :  return "10015 INVALID_PRICE"+(ext_descr ? " (Invalid price in the request)" : "");
                                                  //--- Invalid request stop levels
        case TRADE_RETCODE_INVALID_STOPS       :  return "10016 INVALID_STOPS"+(ext_descr ? " (Invalid stops in the request)" : "");
                                                  //--- Trading disabled
        case TRADE_RETCODE_TRADE_DISABLED      :  return "10017 TRADE_DISABLED"+(ext_descr ? " (Trade is disabled)" : "");
                                                  //--- Market closed
        case TRADE_RETCODE_MARKET_CLOSED       :  return "10018 MARKET_CLOSED"+(ext_descr ? " (Market is closed)" : "");
                                                  //--- Insufficient funds for request execution
        case TRADE_RETCODE_NO_MONEY            :  return "10019 NO_MONEY"+(ext_descr ? " (There is not enough money to complete the request)" : "");
                                                  //--- Prices changed
        case TRADE_RETCODE_PRICE_CHANGED       :  return "10020 PRICE_CHANGED"+(ext_descr ? " (Prices changed)" : "");
                                                  //--- No quotes to handle the request
        case TRADE_RETCODE_PRICE_OFF           :  return "10021 PRICE_OFF"+(ext_descr ? " (There are no quotes to process the request)" : "");
                                                  //--- Invalid order expiration in a request
        case TRADE_RETCODE_INVALID_EXPIRATION  :  return "10022 INVALID_EXPIRATION"+(ext_descr ? " (Invalid order expiration date in the request)" : "");
                                                  //--- Order status changed
        case TRADE_RETCODE_ORDER_CHANGED       :  return "10023 ORDER_CHANGED"+(ext_descr ? " (Order state changed)" : "");
                                                  //--- Too frequent requests
        case TRADE_RETCODE_TOO_MANY_REQUESTS   :  return "10024 TOO_MANY_REQUESTS"+(ext_descr ? " (Too frequent requests)" : "");
                                                  //--- Request unchanged
        case TRADE_RETCODE_NO_CHANGES          :  return "10025 NO_CHANGES"+(ext_descr ? " (No changes in request)" : "");
                                                  //--- Auto trading disabled by the server
        case TRADE_RETCODE_SERVER_DISABLES_AT  :  return "10026 SERVER_DISABLES_AT"+(ext_descr ? " (Autotrading disabled by server)" : "");
                                                  //--- Auto trading disabled by the client terminal
        case TRADE_RETCODE_CLIENT_DISABLES_AT  :  return "10027 CLIENT_DISABLES_AT"+(ext_descr ? " (Autotrading disabled by client terminal)" : "");
                                                  //--- Request blocked for handling
        case TRADE_RETCODE_LOCKED              :  return "10028 LOCKED"+(ext_descr ? " (Request locked for processing)" : "");
                                                  //--- An order or a position is frozen
        case TRADE_RETCODE_FROZEN              :  return "10029 FROZEN"+(ext_descr ? " (Order or position frozen)" : "");
                                                  //--- The specified type of order execution by residue is not supported
        case TRADE_RETCODE_INVALID_FILL        :  return "10030 INVALID_FILL"+(ext_descr ? " (Invalid order filling type)" : "");
                                                  //--- No connection to the trade server
        case TRADE_RETCODE_CONNECTION          :  return "10031 CONNECTION"+(ext_descr ? " (No connection with the trade server)" : "");
                                                  //--- Transaction is allowed for live accounts only
        case TRADE_RETCODE_ONLY_REAL           :  return "10032 ONLY_REAL"+(ext_descr ? " (Operation is allowed only for live accounts)" : "");
                                                  //--- The maximum number of pending orders is reached
        case TRADE_RETCODE_LIMIT_ORDERS        :  return "10033 LIMIT_ORDERS"+(ext_descr ? " (The number of pending orders has reached the limit)" : "");
                                                  //--- Reached the maximum order and position volume for this symbol
        case TRADE_RETCODE_LIMIT_VOLUME        :  return "10034 LIMIT_VOLUME"+(ext_descr ? " (The volume of orders and positions for the symbol has reached the limit)" : "");
                                                  //--- Invalid or prohibited order type
        case TRADE_RETCODE_INVALID_ORDER       :  return "10035 INVALID_ORDER"+(ext_descr ? " (Incorrect or prohibited order type)" : "");
                                                  //--- Position with specified POSITION_IDENTIFIER already closed
        case TRADE_RETCODE_POSITION_CLOSED     :  return "10036 POSITION_CLOSED"+(ext_descr ? " (Position with the specified POSITION_IDENTIFIER has already been closed)" : "");
                                                  //--- Closed volume exceeds the current position volume
        case TRADE_RETCODE_INVALID_CLOSE_VOLUME:  return "10038 INVALID_CLOSE_VOLUME"+(ext_descr ? " (A close volume exceeds the current position volume)" : "");
                                                  //--- A close order is already present for a specified position
        case TRADE_RETCODE_CLOSE_ORDER_EXIST   :  return "10039 CLOSE_ORDER_EXIST"+(ext_descr ? " (A close order already exists for a specified position)" : "");
                                                  //--- Number of positions reached the limit
        case TRADE_RETCODE_LIMIT_POSITIONS     :  return "10040 LIMIT_POSITIONS"+(ext_descr ? " (The number of positions has reached the limit)" : "");
                                                  //--- Request to activate a pending order is rejected, the order is canceled
        case TRADE_RETCODE_REJECT_CANCEL       :  return "10041 REJECT_CANCEL"+(ext_descr ? " (The pending order activation request is rejected, the order is canceled)" : "");
                                                  //--- Request rejected, only long positions are allowed on symbol
        case TRADE_RETCODE_LONG_ONLY           :  return "10042 LONG_ONLY"+(ext_descr ? " (Only long positions are allowed)" : "");
                                                  //--- Request rejected, only short positions are allowed on symbol
        case TRADE_RETCODE_SHORT_ONLY          :  return "10043 SHORT_ONLY"+(ext_descr ? " (Only short positions are allowed)" : "");
                                                  //--- Request rejected, only position closing is allowed on symbol
        case TRADE_RETCODE_CLOSE_ONLY          :  return "10044 CLOSE_ONLY"+(ext_descr ? " (Only position closing is allowed)" : "");
                                                  //--- Request rejected, position closing for trading account is allowed only by FIFO rule
        case TRADE_RETCODE_FIFO_CLOSE          :  return "10045 FIFO_CLOSE"+(ext_descr ? " (Position closing is allowed only by FIFO rule)" : "");
                                                  //--- Request rejected, opposite positions on a single symbol are disabled for trading account
        case TRADE_RETCODE_HEDGE_PROHIBITED    :  return "10046 HEDGE_PROHIBITED"+(ext_descr ? " (Opposite positions on a single symbol are disabled)" : "");
                                                  //--- Unknown return code
        default                                :  return "Undefined ("+(string)retcode+")";
    }
}
//+------------------------------------------------------------------+
//| Return the order type description                                |
//+------------------------------------------------------------------+
string OrderTypeDescription(const ENUM_ORDER_TYPE type, const bool ext_descr=false)
{
    //--- "Cut out" the order type from the string obtained from enum
    string res=StringSubstr(EnumToString(type),11);
    //--- Convert all received characters to lowercase and
    if(res.Lower())
    {
        //--- replace the first letter from small to capital
        res.SetChar(0,ushort(res.GetChar(0)-0x20));
        int total=(int)res.Length();  // Text length
        int index=0;                  // index to start searching for "_" in a text
                                      //--- Search for underscores in a loop through all characters
        for(int i=0;i<total;i++)
        {
            int pos=StringFind(res,"_",index);
            //--- If an underscore is found,
            if(pos>0)
            {
                //--- replace it with space and convert the next letter to uppercase
                res.SetChar(pos,' ');
                res.SetChar(pos+1,ushort(res.GetChar(pos+1)-0x20));
                //--- Set a new index for starting the search for "_"
                index=pos;
            }
        }
    }
    string descr="";
    switch(type)
    {
        case ORDER_TYPE_BUY              :  descr=" (Market Buy order)";                                                                          break;
        case ORDER_TYPE_SELL             :  descr=" (Market Sell order)";                                                                         break;
        case ORDER_TYPE_BUY_LIMIT        :  descr=" (Buy Limit pending order)";                                                                   break;
        case ORDER_TYPE_SELL_LIMIT       :  descr=" (Sell Limit pending order)";                                                                  break;
        case ORDER_TYPE_BUY_STOP         :  descr=" (Buy Stop pending order)";                                                                    break;
        case ORDER_TYPE_SELL_STOP        :  descr=" (Sell Stop pending order)";                                                                   break;
        case ORDER_TYPE_BUY_STOP_LIMIT   :  descr=" (Upon reaching the order price, a pending Buy Limit order is placed at the StopLimit price)"; break;
        case ORDER_TYPE_SELL_STOP_LIMIT  :  descr=" (Upon reaching the order price, a pending Sell Limit order is placed at the StopLimit price)";break;
        case ORDER_TYPE_CLOSE_BY         :  descr=" (Order to close a position by an opposite one)";                                              break;
        default: break;
    }
    return res+(!ext_descr ? "" : descr);
    /* Sample output:
       Sell Limit (Sell Limit pending order)
     */
}
//+------------------------------------------------------------------+
//| Return the order type description by execution                   |
//+------------------------------------------------------------------+
string OrderTypeFillingDescription(const ENUM_ORDER_TYPE_FILLING type_filling, const bool ext_descr=false)
{
    string res=StringSubstr(EnumToString(type_filling),14);
    //--- Convert all obtained symbols to lower case and replace the first letter from small to capital (for ORDER_FILLING_RETURN)
    if(type_filling==ORDER_FILLING_RETURN && res.Lower())
        res.SetChar(0,ushort(res.GetChar(0)-0x20));
    string descr="";
    switch(type_filling)
    {
        case ORDER_FILLING_FOK     :  descr=" (Fill or Kill. An order can be executed in the specified volume only)";                                               break;
        case ORDER_FILLING_IOC     :  descr=" (Immediate or Cancel. A deal with the volume maximally available in the market within that indicated in the order)";  break;
        case ORDER_FILLING_BOC     :  descr=" (Passive (Book or Cancel). The order can only be placed in the Depth of Market and cannot be immediately executed)";  break;
        case ORDER_FILLING_RETURN  :  descr=" (In case of partial filling, an order with remaining volume is not canceled but processed further)";                  break;
        default: break;
    }
    return res+(!ext_descr ? "" : descr);
    /* Sample output:
       Return (In case of partial filling, an order with remaining volume is not canceled but processed further)
     */
}
//+------------------------------------------------------------------+
//| Return an order state description                                |
//+------------------------------------------------------------------+
string OrderStateDescription(const ENUM_ORDER_STATE state, const bool ext_descr=false)
{
    //--- "Cut out" the order status from the string obtained from enum
    string res=StringSubstr(EnumToString(state),12);
    //--- Convert all obtained symbols to lower case and replace the first letter from small to capital
    if(res.Lower())
        res.SetChar(0,ushort(res.GetChar(0)-0x20));
    //--- Replace all underscore characters with space in the resulting line
    StringReplace(res,"_"," ");
    string descr="";
    switch(state)
    {
        case ORDER_STATE_STARTED         :  descr=" (Order checked, but not yet accepted by broker)";            break;
        case ORDER_STATE_PLACED          :  descr=" (Order accepted)";                                           break;
        case ORDER_STATE_CANCELED        :  descr=" (Order canceled by client)";                                 break;
        case ORDER_STATE_PARTIAL         :  descr=" (Order partially executed)";                                 break;
        case ORDER_STATE_FILLED          :  descr=" (Order fully executed)";                                     break;
        case ORDER_STATE_REJECTED        :  descr=" (Order rejected)";                                           break;
        case ORDER_STATE_EXPIRED         :  descr=" (Order expired)";                                            break;
        case ORDER_STATE_REQUEST_ADD     :  descr=" (Order is being registered (placing to the trading system))";break;
        case ORDER_STATE_REQUEST_MODIFY  :  descr=" (Order is being modified (changing its parameters))";        break;
        case ORDER_STATE_REQUEST_CANCEL  :  descr=" (Order is being deleted (deleting from the trading system))";break;
        default: break;
    }
    return res+(!ext_descr ? "" : descr);
    /* Sample output:
       Placed (Order accepted)
     */
}
//+------------------------------------------------------------------+
//| Return the deal type description                                 |
//+------------------------------------------------------------------+
string DealTypeDescription(const ENUM_DEAL_TYPE type, const bool ext_descr=false)
{
    //--- "Cut out" the deal type from the string obtained from enum
    string res=StringSubstr(EnumToString(type),(type==DEAL_DIVIDEND || type==DEAL_DIVIDEND_FRANKED || type==DEAL_TAX ? 5 : 10));
    //--- Convert all obtained symbols to lower case and replace the first letter from small to capital
    if(res.Lower())
        res.SetChar(0,ushort(res.GetChar(0)-0x20));
    //--- Replace all underscore characters with space in the resulting line
    StringReplace(res,"_"," ");
    string descr="";
    //--- Extended descriptions are added only to the deals whose description obtained from enum does not match the extended one
    switch(type)
    {
        case DEAL_TYPE_CHARGE                  : descr=" (Additional charge)";                          break;
        case DEAL_TYPE_COMMISSION              : descr=" (Additional commission)";                      break;
        case DEAL_TYPE_COMMISSION_DAILY        : descr=" (Daily commission)";                           break;
        case DEAL_TYPE_COMMISSION_MONTHLY      : descr=" (Monthly commission)";                         break;
        case DEAL_TYPE_COMMISSION_AGENT_DAILY  : descr=" (Daily agent commission)";                     break;
        case DEAL_TYPE_COMMISSION_AGENT_MONTHLY: descr=" (Monthly agent commission)";                   break;
        case DEAL_TYPE_INTEREST                : descr=" (Interest rate)";                              break;
        case DEAL_TYPE_BUY_CANCELED            : descr=" (Canceled buy deal)";                          break;
        case DEAL_TYPE_SELL_CANCELED           : descr=" (Canceled sell deal)";                         break;
        case DEAL_DIVIDEND                     : descr=" (Dividend operations)";                        break;
        case DEAL_DIVIDEND_FRANKED             : descr=" (Franked (non-taxable) dividend operations)";  break;
        case DEAL_TAX                          : descr=" (Tax charges)";                                break;
        default: break;
    }
    return res+(!ext_descr ? "" : descr);
    /* Sample output:
       Comission (Additional commission)
     */
}
//+------------------------------------------------------------------+
//| Return an order type description by expiration                   |
//+------------------------------------------------------------------+
string OrderTypeTimeDescription(const ENUM_ORDER_TYPE_TIME type_time, const bool ext_descr=false)
{
    //--- "Cut out" the order type by expiration from the string obtained from enum
    string res=StringSubstr(EnumToString(type_time),6);
    //--- If the type by expiration is ORDER_TIME_GTC, add "Time GTC" to res
    if(type_time==ORDER_TIME_GTC)
        res="Time GTC";
    //--- Otherwise, convert all obtained symbols to lower case and replace the first letter from small to capital
    else
    {
        if(res.Lower())
            res.SetChar(0,ushort(res.GetChar(0)-0x20));
        //--- Replace all underscore characters with space in the resulting line
        StringReplace(res,"_"," ");
    }
    string descr="";
    switch(type_time)
    {
        case ORDER_TIME_GTC           : descr=" (Good till cancel order)";                                          break;
        case ORDER_TIME_DAY           : descr=" (Good till current trade day order)";                               break;
        case ORDER_TIME_SPECIFIED     : descr=" (Good till expired order)";                                         break;
        case ORDER_TIME_SPECIFIED_DAY : descr=" (The order will be effective till 23:59:59 of the specified day)";  break;
        default: break;
    }
    return res+(!ext_descr ? "" : descr);
    /* Sample output:
       Time GTC (Good till cancel order)
     */
}
//+------------------------------------------------------------------+
//| Return the deal ticket as a string                               |
//+------------------------------------------------------------------+
string MqlTradeTransactionDeal(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Deal:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,trans.deal);
    /* Sample output:
Deal: 0
     */
}
//+------------------------------------------------------------------+
//| Return the order ticket as a string                              |
//+------------------------------------------------------------------+
string MqlTradeTransactionOrder(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Order:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,trans.order);
    /* Sample output:
Order: 1825990224
     */
}
//+------------------------------------------------------------------+
//| Return an order symbol as a string                               |
//+------------------------------------------------------------------+
string MqlTradeTransactionSymbol(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Symbol:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,trans.symbol);
    /* Sample output:
Symbol: EURUSD
     */
}
//+------------------------------------------------------------------+
//| Return the trading transaction type as a string                  |
//+------------------------------------------------------------------+
string MqlTradeTransactionType(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Type:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,TradeTransactionTypeDescription(trans.type,ext_descr));
    /* Sample output:
Type: Order delete (Removing an order from the list of the open ones)
     */
}
//+------------------------------------------------------------------+
//| Return the order type as a string                                |
//+------------------------------------------------------------------+
string MqlTradeTransactionOrderType(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
{
    //--- Declare variables to indicate transaction affiliation
    bool trans_req=false;   // Request
    bool trans_order=false; // Order
    bool trans_deal=false;  // Deal
    bool trans_pos=false;   // Position
                            //--- Set transaction affiliation
    SetTransactionBelong(trans.type,trans_req,trans_order,trans_deal,trans_pos);
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Order type:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,(trans_order ? OrderTypeDescription(trans.order_type,ext_descr) : "0"));
    /* Sample output:
       Order type: Sell Limit (Sell Limit pending order)
     */
}
//+------------------------------------------------------------------+
//| Return the order status as a string                              |
//+------------------------------------------------------------------+
string MqlTradeTransactionOrderState(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
{
    //--- Declare variables to indicate transaction affiliation
    bool trans_req=false;   // Request
    bool trans_order=false; // Order
    bool trans_deal=false;  // Deal
    bool trans_pos=false;   // Position
                            //--- Set transaction affiliation
    SetTransactionBelong(trans.type,trans_req,trans_order,trans_deal,trans_pos);
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Order state:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,(trans_order ? OrderStateDescription(trans.order_state,ext_descr) : "0"));
    /* Sample output:
       Order state: Started (Order checked, but not yet accepted by broker)
     */
}
//+------------------------------------------------------------------+
//| Return the deal type as a string                                 |
//+------------------------------------------------------------------+
string MqlTradeTransactionDealType(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
{
    //--- Declare variables to indicate transaction affiliation
    bool trans_req=false;   // Request
    bool trans_order=false; // Order
    bool trans_deal=false;  // Deal
    bool trans_pos=false;   // Position
                            //--- Set transaction affiliation
    SetTransactionBelong(trans.type,trans_req,trans_order,trans_deal,trans_pos);
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Deal type:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,(trans_deal || trans_pos ? DealTypeDescription(trans.deal_type,ext_descr) : "0"));
    /* Sample output:
       Deal type: Buy
     */
}
//+------------------------------------------------------------------+
//| Return the order type by expiration time as a string             |
//+------------------------------------------------------------------+
string MqlTradeTransactionTimeType(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
{
    //--- Declare variables to indicate transaction affiliation
    bool trans_req=false;   // Request
    bool trans_order=false; // Order
    bool trans_deal=false;  // Deal
    bool trans_pos=false;   // Position
                            //--- Set transaction affiliation
    SetTransactionBelong(trans.type,trans_req,trans_order,trans_deal,trans_pos);
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Time type:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,(trans_order ? OrderTypeTimeDescription(trans.time_type,ext_descr) : "0"));
    /* Sample output:
       Order type time: Time GTC (Good till cancel order)
     */
}
//+------------------------------------------------------------------+
//| Return the order expiration time as a string                     |
//+------------------------------------------------------------------+
string MqlTradeTransactionTimeExpiration(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Time expiration:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Set the expiration time as a string. If 0, then set 0
    string tm=(trans.time_expiration==0 ? "0" : (string)trans.time_expiration);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,tm);
    /* Sample output:
       Time expiration: 0
     */
}
//+------------------------------------------------------------------+
//| Return the order/deal/position price as a string                 |
//+------------------------------------------------------------------+
string MqlTradeTransactionPrice(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Price:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Receive symbol's Digits. If the character is not specified, use 1
    int dg=(trans.symbol!="" ? (int)SymbolInfoInteger(trans.symbol,SYMBOL_DIGITS) : 1);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,trans.price);
    /* Sample output:
Price: 1.10331
     */
}
//+------------------------------------------------------------------+
//| Return the stop limit order trigger price as a string            |
//+------------------------------------------------------------------+
string MqlTradeTransactionPriceTrigger(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Price trigger:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Receive symbol's Digits. If a symbol is not specified or there is no stop price, use 1
    int dg=(trans.symbol!="" ? (int)SymbolInfoInteger(trans.symbol,SYMBOL_DIGITS) : 1);
    if(trans.price_trigger==0)
        dg=1;
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,trans.price_trigger);
    /* Sample output:
       Price trigger: 0.0
     */
}
//+------------------------------------------------------------------+
//| Return Stop Loss price as a string                               |
//+------------------------------------------------------------------+
string MqlTradeTransactionPriceSL(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Price SL:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Receive symbol's Digits. If a symbol is not specified or a Stop Loss price is absent, use 1
    int dg=(trans.symbol!="" ? (int)SymbolInfoInteger(trans.symbol,SYMBOL_DIGITS) : 1);
    if(trans.price_sl==0)
        dg=1;
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,trans.price_sl);
    /* Sample output:
       Price SL: 0.0
     */
}
//+------------------------------------------------------------------+
//| Return a Take Profit price as a string                           |
//+------------------------------------------------------------------+
string MqlTradeTransactionPriceTP(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Price TP:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Receive symbol's Digits. If a symbol is not specified or a Take Profit price is absent, use 1
    int dg=(trans.symbol!="" ? (int)SymbolInfoInteger(trans.symbol,SYMBOL_DIGITS) : 1);
    if(trans.price_tp==0)
        dg=1;
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,trans.price_tp);
    /* Sample output:
       Price TP: 0.0
     */
}
//+------------------------------------------------------------------+
//| Return volume in lots as a string                                |
//+------------------------------------------------------------------+
string MqlTradeTransactionVolume(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Volume:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the number of decimal places in the lot value. If the character is not specified, use 1
    int dg=(trans.symbol!="" ? (int)ceil(fabs(log10(SymbolInfoDouble(trans.symbol,SYMBOL_VOLUME_STEP)))) : 1);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,trans.volume);
    /* Sample output:
Volume: 0.10
     */
}
//+------------------------------------------------------------------+
//| Return the position ticket as a string                           |
//+------------------------------------------------------------------+
string MqlTradeTransactionPosition(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Position:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,trans.position);
    /* Sample output:
Position: 0
     */
}
//+------------------------------------------------------------------+
//| Return the opposite position ticket as a string                  |
//+------------------------------------------------------------------+
string MqlTradeTransactionPositionBy(const MqlTradeTransaction &trans, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Position by:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,trans.position_by);
    /* Sample output:
       Position by: 0
     */
}
//+------------------------------------------------------------------+
//| Return the trade request type description                        |
//+------------------------------------------------------------------+
string TradeActionDescription(const ENUM_TRADE_REQUEST_ACTIONS action, const bool ext_descr=false)
{
    //--- "Cut out" the operation type from the string obtained from enum
    string res=StringSubstr(EnumToString(action),13);
    //--- Convert all obtained symbols to lower case and replace the first letter from small to capital (except for TRADE_ACTION_SLTP)
    if(action!=TRADE_ACTION_SLTP && res.Lower())
        res.SetChar(0,ushort(res.GetChar(0)-0x20));
    string descr="";
    switch(action)
    {
        case TRADE_ACTION_DEAL     : descr=" (Place a trade order for an immediate execution with the specified parameters (market order))";break;
        case TRADE_ACTION_PENDING  : descr=" (Place a trade order for the execution under specified conditions (pending order))";           break;
        case TRADE_ACTION_SLTP     : descr=" (Modify Stop Loss and Take Profit values of an opened position)";                              break;
        case TRADE_ACTION_MODIFY   : descr=" (Modify the parameters of the order placed previously)";                                       break;
        case TRADE_ACTION_REMOVE   : descr=" (Delete the pending order placed previously)";                                                 break;
        case TRADE_ACTION_CLOSE_BY : descr=" (Close a position by an opposite one)";                                                        break;
        default: break;
    }
    return res+(!ext_descr ? "" : descr);
    /* Sample output:
       Pending (Place a trade order for the execution under specified conditions (pending order)):
     */
}
//+-------------------------------------------------------------------------------+
//|Functions for working with the structure of the MqlTradeRequest trading request|
//+-------------------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Return the type of a performed action as a string                |
//+------------------------------------------------------------------+
string MqlTradeRequestAction(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Action:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,TradeActionDescription(req.action,ext_descr));
    /* Sample output:
Action: Pending (Place a trade order for the execution under specified conditions (pending order)):
     */
}
//+------------------------------------------------------------------+
//| Return the EA stamp (magic number) as a string                   |
//+------------------------------------------------------------------+
string MqlTradeRequestMagic(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Magic:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,req.magic);
    /* Sample output:
Magic: 1024
     */
}
//+------------------------------------------------------------------+
//| Return the order ticket as a string                              |
//+------------------------------------------------------------------+
string MqlTradeRequestOrder(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Order:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,req.order);
    /* Sample output:
Order: 1835982676
     */
}
//+------------------------------------------------------------------+
//| Return a trading instrument name                                 |
//+------------------------------------------------------------------+
string MqlTradeRequestSymbol(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Symbol:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,req.symbol);
    /* Sample output:
Symbol: EURUSD
     */
}
//+------------------------------------------------------------------+
//| Return the requested volume of a deal in lots as a string        |
//+------------------------------------------------------------------+
string MqlTradeRequestVolume(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Volume:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the number of decimal places in the lot value. If the character is not specified, use 1
    int dg=(int)ceil(fabs(log10(SymbolInfoDouble(req.symbol,SYMBOL_VOLUME_STEP))));
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,req.volume);
    /* Sample output:
Volume: 0.10
     */
}
//+------------------------------------------------------------------+
//| Return the price as a string                                     |
//+------------------------------------------------------------------+
string MqlTradeRequestPrice(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Price:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the number of decimal places
    int dg=(req.price!=0 ? (int)SymbolInfoInteger(req.symbol,SYMBOL_DIGITS) : 1);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,req.price);
    /* Sample output:
Price: 1.09586
     */
}
//+------------------------------------------------------------------+
//| Return the StopLimit order level as a string                     |
//+------------------------------------------------------------------+
string MqlTradeRequestStopLimit(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="StopLimit:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the number of decimal places
    int dg=(req.stoplimit!=0 ? (int)SymbolInfoInteger(req.symbol,SYMBOL_DIGITS) : 1);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,req.stoplimit);
    /* Sample output:
StopLimit: 0.0
     */
}
//+------------------------------------------------------------------+
//| Return the Stop Loss order level as a string                     |
//+------------------------------------------------------------------+
string MqlTradeRequestStopLoss(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="SL:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the number of decimal places
    int dg=(req.sl!=0 ? (int)SymbolInfoInteger(req.symbol,SYMBOL_DIGITS) : 1);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,req.sl);
    /* Sample output:
SL: 0.0
     */
}
//+------------------------------------------------------------------+
//| Return the Take Profit order level as a string                   |
//+------------------------------------------------------------------+
string MqlTradeRequestTakeProfit(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="TP:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the number of decimal places
    int dg=(req.tp!=0 ? (int)SymbolInfoInteger(req.symbol,SYMBOL_DIGITS) : 1);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,req.tp);
    /* Sample output:
TP: 0.0
     */
}
//+------------------------------------------------------------------+
//| Return the maximum acceptable                                    |
//| deviation from the requested price                               |
//+------------------------------------------------------------------+
string MqlTradeRequestDeviation(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Deviation:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,req.deviation);
    /* Sample output:
Deviation: 5
     */
}
//+------------------------------------------------------------------+
//| Return the order type as a string                                |
//+------------------------------------------------------------------+
string MqlTradeRequestType(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0,bool ext_descr=false)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Type:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,OrderTypeDescription(req.type,ext_descr));
    /* Sample output:
Type: Buy Limit (Buy Limit pending order)
     */
}
//+------------------------------------------------------------------+
//| Return the order type by execution as a string                   |
//+------------------------------------------------------------------+
string MqlTradeRequestTypeFilling(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0,bool ext_descr=false)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Type filling:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,OrderTypeFillingDescription(req.type_filling,ext_descr));
    /* Sample output:
       Type filling: Return (In case of partial filling, an order with remaining volume is not canceled but processed further)
     */
}
//+------------------------------------------------------------------+
//| Return the order type by expiration time as a string             |
//+------------------------------------------------------------------+
string MqlTradeRequestTypeTime(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0,bool ext_descr=false)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Type time:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,OrderTypeTimeDescription(req.type_time,ext_descr));
    /* Sample output:
       Type time: Time GTC (Good till cancel order)
     */
}
//+------------------------------------------------------------------+
//| Return the order expiration time as a string                     |
//+------------------------------------------------------------------+
string MqlTradeRequestExpiration(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Expiration:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,(req.type_time==ORDER_TIME_SPECIFIED || req.type_time==ORDER_TIME_SPECIFIED_DAY ? (string)req.expiration : "0"));
    /* Sample output:
Expiration: 0
     */
}
//+------------------------------------------------------------------+
//| Return the order comment                                         |
//+------------------------------------------------------------------+
string MqlTradeRequestComment(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Comment:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,req.comment);
    /* Sample output:
Comment: TestMqlTradeTransaction
     */
}
//+------------------------------------------------------------------+
//| Return the position ticket as a string                           |
//+------------------------------------------------------------------+
string MqlTradeRequestPosition(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Position:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,req.position);
    /* Sample output:
Position: 1835982676
     */
}
//+------------------------------------------------------------------+
//| Return the opposite position ticket as a string                  |
//+------------------------------------------------------------------+
string MqlTradeRequestPositionBy(const MqlTradeRequest &req, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Position by:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,req.position_by);
    /* Sample output:
       Position by: 1835987626
     */
}
//+------------------------------------------------------------------+
//| Functions for working with the structure                         |
//| of the MqlTradeCheckResult trading request verification result   |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Return the response code as a string                             |
//+------------------------------------------------------------------+
string MqlTradeCheckResultRetcode(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Retcode:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,RetcodeDescription(result.retcode,ext_descr));
    /* Sample output:
Retcode: OK (0)
     */
}
//+--------------------------------------------------------------------+
//| Return the balance as a string after a trade operation is performed|
//+--------------------------------------------------------------------+
string MqlTradeCheckResultBalance(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Balance:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the account currency
    string currency=AccountInfoString(ACCOUNT_CURRENCY);
    //--- Get the number of decimal places
    int dg=(int)AccountInfoInteger(ACCOUNT_CURRENCY_DIGITS);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f %s",indent,"",w,header,dg,result.balance,currency);
    /* Sample output:
Balance: 10016.80 USD
     */
}
//+-------------------------------------------------------------------+
//| Return the equity as a string after a trade operation is performed|
//+-------------------------------------------------------------------+
string MqlTradeCheckResultEquity(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Equity:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the account currency
    string currency=AccountInfoString(ACCOUNT_CURRENCY);
    //--- Get the number of decimal places
    int dg=(int)AccountInfoInteger(ACCOUNT_CURRENCY_DIGITS);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f %s",indent,"",w,header,dg,result.equity,currency);
    /* Sample output:
Equity: 10016.80 USD
     */
}
//+---------------------------------------------------------------------------+
//|Return the floating profit as a string after a trade operation is performed|
//+---------------------------------------------------------------------------+
string MqlTradeCheckResultProfit(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Profit:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the account currency
    string currency=AccountInfoString(ACCOUNT_CURRENCY);
    //--- Get the number of decimal places
    int dg=(int)AccountInfoInteger(ACCOUNT_CURRENCY_DIGITS);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f %s",indent,"",w,header,dg,result.profit,currency);
    /* Sample output:
Profit: 0.00 USD
     */
}
//+------------------------------------------------------------------+
//| Return the margin,                                               |
//| required for the necessary trading operation, as a string        |
//+------------------------------------------------------------------+
string MqlTradeCheckResultMargin(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Margin:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the account currency
    string currency=AccountInfoString(ACCOUNT_CURRENCY);
    //--- Get the number of decimal places
    int dg=(int)AccountInfoInteger(ACCOUNT_CURRENCY_DIGITS);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f %s",indent,"",w,header,dg,result.margin,currency);
    /* Sample output:
Margin: 128.66 USD
     */
}
//+------------------------------------------------------------------+
//| Return the value of equity                                       |
//| to be left after conducting a trading operation as a string      |
//+------------------------------------------------------------------+
string MqlTradeCheckResultMarginFree(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Margin free:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the account currency
    string currency=AccountInfoString(ACCOUNT_CURRENCY);
    //--- Get the number of decimal places
    int dg=(int)AccountInfoInteger(ACCOUNT_CURRENCY_DIGITS);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f %s",indent,"",w,header,dg,result.margin_free,currency);
    /* Sample output:
       Margin free: 9888.14 USD
     */
}
//+-----------------------------------------------------------------------+
//| Return the margin level                                               |
//| to be set after completing the required trading operation as a string |
//+-----------------------------------------------------------------------+
string MqlTradeCheckResultMarginLevel(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Margin level:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.2f %%",indent,"",w,header,result.margin_level);
    /* Sample output:
       Margin level: 7785.48 %
     */
}
//+------------------------------------------------------------------+
//| Return comment on the response code, error description           |
//+------------------------------------------------------------------+
string MqlTradeCheckResultComment(const MqlTradeCheckResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Comment:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,result.comment);
    /* Sample output:
Comment: Done
     */
}
//+------------------------------------------------------------------+
//| Functions for working with the structure                         |
//| of the MqlTradeResult trading request result                     |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Return the operation result code as a string                     |
//+------------------------------------------------------------------+
string MqlTradeResultRetcode(const MqlTradeResult &result, const uint header_width=0, const uint indent=0, const bool ext_descr=false)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Retcode:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,RetcodeDescription(result.retcode,ext_descr));
    /* Sample output:
Retcode: 10009 DONE (Request completed)
     */
}
//+------------------------------------------------------------------+
//| Return the deal ticket if it is completed                        |
//+------------------------------------------------------------------+
string MqlTradeResultDeal(const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Deal:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,result.deal);
    /* Sample output:
Deal: 0
     */
}
//+------------------------------------------------------------------+
//| Return the order ticket as a string if the order is set          |
//+------------------------------------------------------------------+
string MqlTradeResultOrder(const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Order:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-llu",indent,"",w,header,result.order);
    /* Sample output:
Order: 1821552382
     */
}
//+------------------------------------------------------------------+
//| Return the deal volume confirmed by a broker as a string         |
//+------------------------------------------------------------------+
string MqlTradeResultVolume(const string symbol, const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Volume:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the number of decimal places in the lot value
    int dg=(int)ceil(fabs(log10(SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP))));
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,result.volume);
    /* Sample output:
Volume: 0.10
     */
}
//+------------------------------------------------------------------+
//| Return a deal price, confirmed by a broker, as a string          |
//+------------------------------------------------------------------+
string MqlTradeResultPrice(const string symbol, const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Price:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the number of decimal places
    int dg=(result.price!=0 ? (int)SymbolInfoInteger(symbol,SYMBOL_DIGITS) : 1);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,result.price);
    /* Sample output:
Price: 0.0
     */
}
//+------------------------------------------------------------------+
//| Return the current market Bid price as a string                  |
//+------------------------------------------------------------------+
string MqlTradeResultBid(const string symbol, const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Bid:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the number of decimal places
    int dg=(result.bid!=0 ? (int)SymbolInfoInteger(symbol,SYMBOL_DIGITS) : 1);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,result.bid);
    /* Sample output:
Bid: 0.0
     */
}
//+------------------------------------------------------------------+
//| Return the current market Ask price as a string                  |
//+------------------------------------------------------------------+
string MqlTradeResultAsk(const string symbol, const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Ask:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Get the number of decimal places
    int dg=(result.ask!=0 ? (int)SymbolInfoInteger(symbol,SYMBOL_DIGITS) : 1);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-.*f",indent,"",w,header,dg,result.ask);
    /* Sample output:
Ask: 0.0
     */
}
//+------------------------------------------------------------------+
//| Return broker's comment on a deal                                |
//+------------------------------------------------------------------+
string MqlTradeResultComment(const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Comment:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-s",indent,"",w,header,result.comment);
    /* Sample output:
Comment: Request executed
     */
}
//+------------------------------------------------------------------+
//| Return request ID as a string                                    |
//+------------------------------------------------------------------+
string MqlTradeResultRequestID(const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Request ID:";
    uint w=(header_width==0 ? header.Length()+1 : header_width);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%-lu",indent,"",w,header,result.request_id);
    /* Sample output:
       Request ID: 3768213261
     */
}
//+-------------------------------------------------------------------+
//| Return the response code of an external trading system as a string|
//+-------------------------------------------------------------------+
string MqlTradeResultRetcodeExternal(const MqlTradeResult &result, const uint header_width=0, const uint indent=0)
{
    //--- Define the header text and the width of the header field
    //--- If the header width is passed to the function equal to zero, then the width will be the size of the header line + 1
    string header="Retcode External:";
    uint w=(header_width==0 ? header.Length()+1 : header_width-1);
    //--- Return the property value with a header having the required width and indentation
    return StringFormat("%*s%-*s%- ld",indent,"",w,header,result.retcode_external);
    /* Sample output:
       Retcode External:  0
     */
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

迈达量化

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值