Deutsch 日本語
preview
MQL5 Trading Toolkit (Part 7): Expanding the History Management EX5 Library with the Last Canceled Pending Order Functions

MQL5 Trading Toolkit (Part 7): Expanding the History Management EX5 Library with the Last Canceled Pending Order Functions

MetaTrader 5Examples |
788 0
Wanateki Solutions LTD
Kelvin Muturi Muigua

Introduction

Throughout this article series, we have dedicated significant effort to building a comprehensive suite of trading EX5 libraries. These libraries are designed to streamline the development process for MQL5 applications, drastically reducing the time and effort required to handle trade operations and manage the historical data of orders, deals, and positions. By offering well-structured and intuitive functions, these libraries simplify complex tasks, allowing developers to seamlessly process trading history with precision and efficiency.

In this article, we will finalize the development of the last module in our History Management EX5 library, specifically designed to handle the retrieval and storage of properties associated with the most recently canceled pending order. This module addresses a key limitation in the MQL5 language, which lacks straightforward, single-line functions to access and manage such historical data. By bridging this gap, our library offers developers a streamlined solution to efficiently work with canceled pending order information.

The focus of this module is to provide a simple yet effective way to retrieve and store critical details of canceled pending orders, such as their symbol, opening price, pip-based stop loss, take profit, time-based durations, and other relevant attributes. By encapsulating this functionality into easy-to-use functions, the library allows developers to access the required data with minimal effort and complexity. This makes it an indispensable tool for anyone looking to build MQL5 applications that rely on precise and accessible trading history data. For those of you who are interested in analyzing trading performance, this module simplifies the process, enabling you to focus on the bigger picture.

To get started, open the HistoryManager.mq5 file from the previous article, where we developed functions for handling the most recently filled pending order. In this section, we will begin implementing the GetLastCanceledPendingOrderData() function, which is central to processing canceled pending orders. Before proceeding, ensure you have downloaded the HistoryManager.mq5 source file, which is attached at the end of the previous article.

Once the file is ready, locate the section where we concluded in the last article. Specifically, we will continue adding new code just below the LastFilledPendingOrderComment() function. This placement ensures that the new functionality is logically organized alongside related functions, making the library easier to navigate and extend in the future if the need arises.


Main Content

  1. Get The Last Canceled Pending Order Data
  2. Get The Last Canceled Pending Order Type
  3. Get The Last Canceled Pending Order Symbol
  4. Get The Last Canceled Pending Order Ticket
  5. Get The Last Canceled Pending Order Price Open
  6. Get The Last Canceled Pending Order Stop Loss Price
  7. Get The Last Canceled Pending Order Take Profit Price
  8. Get The Last Canceled Pending Order Stop Loss Pips
  9. Get The Last Canceled Pending Order Take Profit Pips
  10. Get The Last Canceled Pending Order Time Setup
  11. Get The Last Canceled Pending Order Time Done
  12. Get The Last Canceled Pending Order Expiration Time
  13. Get The Last Canceled Pending Order Position ID
  14. Get The Last Canceled Pending Order Magic
  15. Get The Last Canceled Pending Order Reason
  16. Get The Last Canceled Pending Order Type Filling
  17. Get The Last Canceled Pending Order Type Time
  18. Get The Last Canceled Pending Order Comment
  19. Conclusion



Get Last Canceled Pending Order Data Function

The GetLastCanceledPendingOrderData() function retrieves the details of the most recently canceled pending order and saves this information in the specified getLastCanceledPendingOrderData reference. It relies on the FetchHistoryByCriteria() function to access historical trading data, identifying the last canceled pending order by analyzing the relevant dataset. If no such data is found, the function logs an error message and returns false. When successful, it stores the retrieved information in the provided reference and returns true.

Let us begin by creating the function definition or signature. The GetLastCanceledPendingOrderData() function should be accessible to importing MQL5 programs for external use, which is why we have defined it as exported.

bool GetLastCanceledPendingOrderData(PendingOrderData &getLastCanceledPendingOrderData) export
  {
//-- Function implementation will be explained step by step below.
  }

We will go ahead and attempt to fetch the history of pending orders using the FetchHistoryByCriteria() function with the GET_PENDING_ORDERS_HISTORY_DATA argument. This ensures that the function has access to the required data for canceled pending orders.

If the FetchHistoryByCriteria() function returns false, it indicates that there is no trading history available. In this case, we log an error message using the Print() function to aid in debugging. The function then returns false, signifying the failure to retrieve the data.

if(!FetchHistoryByCriteria(GET_PENDING_ORDERS_HISTORY_DATA))
  {
   Print(__FUNCTION__, ": No trading history available. Last canceled pending order can't be retrieved.");
   return(false);
  }

Once the historical data is available, we will calculate the total number of pending orders using the GetTotalDataInfoSize() function. This value will help us loop through the pendingOrderInfo array to locate the most recent canceled pending order.

Next, we will loop through the pendingOrderInfo array to find an order with a state of ORDER_STATE_CANCELED. The function will save the first matching order to the getLastCanceledPendingOrderData variable. The loop ensures that we check each order's state, and once a canceled order is found, it is saved in the reference variable, after which the loop exits. After storing the data for the last canceled pending order, the function returns true, indicating that the operation was successful.

int totalPendingOrderInfo = GetTotalDataInfoSize(GET_PENDING_ORDERS_HISTORY_DATA);
for(int x = 0; x < totalPendingOrderInfo; x++)
  {
   if(pendingOrderInfo[x].state == ORDER_STATE_CANCELED)
     {
      getLastCanceledPendingOrderData = pendingOrderInfo[x];
      break;
     }
  }
return(true);

If no historical data is available, an error message is logged using the Print() function, including the function name (__FUNCTION__) for clarity. This message helps identify the issue during debugging. The function ensures that the provided reference variable remains unchanged if the operation fails, maintaining the integrity of the input.

Here is the complete implementation of the GetLastCanceledPendingOrderData() function.

bool GetLastCanceledPendingOrderData(PendingOrderData &getLastCanceledPendingOrderData) export
  {
   if(!FetchHistoryByCriteria(GET_PENDING_ORDERS_HISTORY_DATA))
     {
      Print(__FUNCTION__, ": No trading history available. Last canceled pending order can't be retrieved.");
      return(false);
     }

//-- Save the last canceled pending order data in the referenced getLastCanceledPendingOrderData variable
   int totalPendingOrderInfo = GetTotalDataInfoSize(GET_PENDING_ORDERS_HISTORY_DATA);
   for(int x = 0; x < totalPendingOrderInfo; x++)
     {
      if(pendingOrderInfo[x].state == ORDER_STATE_CANCELED)
        {
         getLastCanceledPendingOrderData = pendingOrderInfo[x];
         break;
        }
     }
   return(true);
  }


Last Canceled Pending Order Type Function

The LastCanceledPendingOrderType() function is responsible for retrieving the order type of the most recently canceled pending order and saving it in the referenced variable, lastCanceledPendingOrderType. This variable is passed to the function as input, where it stores the retrieved order type.

To accomplish this, a temporary PendingOrderData variable, lastCanceledPendingOrderInfo, is declared to hold the details of the last canceled pending order. The function then calls GetLastCanceledPendingOrderData() to obtain the required order information.

If the retrieval is successful, the type field from lastCanceledPendingOrderInfo is extracted and assigned to lastCanceledPendingOrderType. The function then returns true to confirm the successful operation. Conversely, if the retrieval fails, the function returns false, leaving the lastCanceledPendingOrderType variable unchanged.

Below is the full implementation of the LastCanceledPendingOrderType() function.

bool LastCanceledPendingOrderType(ENUM_ORDER_TYPE &lastCanceledPendingOrderType) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderType = lastCanceledPendingOrderInfo.type;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Symbol Function

The LastCanceledPendingOrderSymbol() function is designed to fetch the trading symbol linked to the most recently canceled pending order. This symbol is stored in the provided lastCanceledPendingOrderSymbol variable, offering a straightforward way to access this specific property. The function relies on the GetLastCanceledPendingOrderData() utility to obtain the necessary order details.

The process begins by invoking GetLastCanceledPendingOrderData(), which retrieves the details of the last canceled pending order. If the retrieval is successful, the symbol field from the fetched data is assigned to the referenced lastCanceledPendingOrderSymbol variable, and the function returns true to confirm the operation's success.

In cases where the data retrieval fails—such as when there is no relevant order history—the function leaves the referenced variable unchanged and returns false to indicate the failure.

Below is the full implementation of the LastCanceledPendingOrderSymbol() function.

bool LastCanceledPendingOrderSymbol(string &lastCanceledPendingOrderSymbol) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderSymbol = lastCanceledPendingOrderInfo.symbol;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Ticket Function

The LastCanceledPendingOrderTicket() function retrieves the ticket number of the most recently canceled pending order and stores it in the referenced lastCanceledPendingOrderTicket variable. It calls the GetLastCanceledPendingOrderData() function to fetch the order details.

If the data retrieval is successful, the ticket number is stored in the referenced variable, and the function returns true. If the process fails, the function returns false, leaving the variable unchanged.

Below is the complete code for the LastCanceledPendingOrderTicket() function.
bool LastCanceledPendingOrderTicket(ulong &lastCanceledPendingOrderTicket) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderTicket = lastCanceledPendingOrderInfo.ticket;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Price Open Function

The LastCanceledPendingOrderPriceOpen() function fetches the opening price of the most recently canceled pending order and holds it in the referenced lastCanceledPendingOrderPriceOpen variable. It calls GetLastCanceledPendingOrderData() to gather the order details.

Upon successful retrieval, the opening price is saved in the provided variable, and the function returns true. If the retrieval fails, the function returns false without altering the variable.

Here is the full implementation of the LastCanceledPendingOrderPriceOpen() function.

bool LastCanceledPendingOrderPriceOpen(double &lastCanceledPendingOrderPriceOpen) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderPriceOpen = lastCanceledPendingOrderInfo.priceOpen;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Stop Loss Price Function

The LastCanceledPendingOrderSlPrice() function gets the stop loss price of the most recently canceled pending order and saves it in the referenced lastCanceledPendingOrderSlPrice variable. It uses the GetLastCanceledPendingOrderData() function to fetch the order details.

If the retrieval is successful, the stop loss price is stored in the referenced variable, and the function returns true. If the process fails, the function returns false without altering the variable.

Here’s how the LastCanceledPendingOrderSlPrice() function is fully implemented.

bool LastCanceledPendingOrderSlPrice(double &lastCanceledPendingOrderSlPrice) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderSlPrice = lastCanceledPendingOrderInfo.slPrice;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Take Profit Price Function

The LastCanceledPendingOrderTpPrice() function retrieves the take profit price of the most recently canceled pending order and holds it in the referenced lastCanceledPendingOrderTpPrice variable. It utilizes the GetLastCanceledPendingOrderData() function to fetch the order details.

If the data retrieval is successful, the take profit price is saved in the referenced variable, and the function returns true. If the retrieval fails, the function returns false without modifying the variable.

Below is the complete implementation of the LastCanceledPendingOrderTpPrice() function.

bool LastCanceledPendingOrderTpPrice(double &lastCanceledPendingOrderTpPrice) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderTpPrice = lastCanceledPendingOrderInfo.tpPrice;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Stop Loss Pips Function

The LastCanceledPendingOrderSlPips() function retrieves the stop loss pips value of the most recently canceled pending order and stores it in the referenced lastCanceledPendingOrderSlPips variable. By utilizing the GetLastCanceledPendingOrderData() function, it accesses the relevant order details to extract this specific value.

The function begins by invoking GetLastCanceledPendingOrderData() to obtain the data of the last canceled pending order. If the retrieval is successful, the stop loss pips value is extracted from the fetched data and assigned to the lastCanceledPendingOrderSlPips variable. The function then indicates success by returning true.

On the other hand, if the function fails to retrieve the required data—perhaps due to a lack of historical information—it refrains from altering the lastCanceledPendingOrderSlPips variable and instead returns false.

Here is the full implementation of the LastCanceledPendingOrderSlPips() function.

bool LastCanceledPendingOrderSlPips(int &lastCanceledPendingOrderSlPips) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderSlPips = lastCanceledPendingOrderInfo.slPips;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Take Profit Pips Function

The LastCanceledPendingOrderTpPips() function retrieves the take profit pips value associated with the most recently canceled pending order. The retrieved value is saved in the referenced variable, lastCanceledPendingOrderTpPips. To achieve this, the function relies on the GetLastCanceledPendingOrderData() function, which fetches the necessary order details.

Initially, a PendingOrderData variable is declared to temporarily store the details of the last canceled pending order. The GetLastCanceledPendingOrderData() function is then called to populate this variable with relevant data. If the operation succeeds, the take profit pips value is extracted from the variable and stored in the lastCanceledPendingOrderTpPips variable. The function then returns true, indicating success.

However, if the data retrieval fails, the function returns false, leaving the referenced variable unchanged.

Here is the complete implementation of the LastCanceledPendingOrderTpPips() function.

bool LastCanceledPendingOrderTpPips(int &lastCanceledPendingOrderTpPips) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderTpPips = lastCanceledPendingOrderInfo.tpPips;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Time Setup Function

The LastCanceledPendingOrderTimeSetup() function retrieves the time setup of the most recently canceled pending order and stores it in the referenced lastCanceledPendingOrderTimeSetup variable. To perform this operation, the function uses the GetLastCanceledPendingOrderData() function to access the necessary details about the canceled order.

We begin by declaring a PendingOrderData variable to temporarily hold the data for the last canceled pending order. The GetLastCanceledPendingOrderData() function is then invoked to populate this variable with the relevant order details. If the retrieval is successful, the time setup value is extracted and stored in the lastCanceledPendingOrderTimeSetup variable. The function subsequently returns true, confirming the success of the operation.

On the other hand, if the data retrieval fails, the function returns false, ensuring that the lastCanceledPendingOrderTimeSetup variable remains unchanged.

Below is the full implementation of the LastCanceledPendingOrderTimeSetup()function.

bool LastCanceledPendingOrderTimeSetup(datetime &lastCanceledPendingOrderTimeSetup) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderTimeSetup = lastCanceledPendingOrderInfo.timeSetup;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Time Done Function

The LastCanceledPendingOrderTimeDone() function is designed to retrieve the time when the most recently canceled pending order was executed. This time is stored in the referenced lastCanceledPendingOrderTimeDone variable, providing a straightforward way to access this specific piece of data. The function relies on the GetLastCanceledPendingOrderData() utility function to gather the required details of the canceled order.

The function begins by calling GetLastCanceledPendingOrderData(), which extracts the details of the most recently canceled pending order. If the retrieval operation is successful, the time field from the fetched data is assigned to the lastCanceledPendingOrderTimeDone variable, and the function returns true, confirming the successful operation.

However, if the retrieval process fails—such as in the absence of relevant order history—the function does not alter the referenced variable and instead returns false, signaling the failure to fetch the desired information.

For tasks requiring the calculation of the total time a pending order was open before being canceled, this function can be used alongside the LastCanceledPendingOrderTimeSetup() function. Together, they enable you to determine the duration between the order's creation and its cancellation.

Below is the complete implementation of the LastCanceledPendingOrderTimeDone() function.

bool LastCanceledPendingOrderTimeDone(datetime &lastCanceledPendingOrderTimeDone) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderTimeDone = lastCanceledPendingOrderInfo.timeDone;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Expiration Time Function

The LastCanceledPendingOrderExpirationTime() function fetches the expiration time of the most recently canceled pending order and assigns it to the referenced lastCanceledPendingOrderExpirationTime variable. It calls the GetLastCanceledPendingOrderData() function to obtain the order details.

If the data retrieval is successful, the expiration time is saved into the referenced variable and the function returns true. If the retrieval fails, the function returns false without altering the variable.

Below is the complete implementation of the LastCanceledPendingOrderExpirationTime() function.
bool LastCanceledPendingOrderExpirationTime(datetime &lastCanceledPendingOrderExpirationTime) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderExpirationTime = lastCanceledPendingOrderInfo.expirationTime;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Position ID Function

The LastCanceledPendingOrderPositionId() function extracts the position ID of the most recently canceled pending order and updates the referenced lastCanceledPendingOrderPositionId variable with this value. To access the necessary data, it invokes the GetLastCanceledPendingOrderData() function.

If the operation is successful, the position ID is placed into the referenced variable, and the function returns true. In case the retrieval is unsuccessful, the function returns false, leaving the variable unchanged.

Here is the full implementation of the LastCanceledPendingOrderPositionId()function.
bool LastCanceledPendingOrderPositionId(ulong &lastCanceledPendingOrderPositionId) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderPositionId = lastCanceledPendingOrderInfo.positionId;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Magic Function

The LastCanceledPendingOrderMagic() function obtains the magic number associated with the most recently canceled pending order and assigns it to the referenced lastCanceledPendingOrderMagic variable. This process relies on the GetLastCanceledPendingOrderData() function to fetch the required details.

If the data retrieval succeeds, the magic number is transferred to the referenced variable, and the function returns true. Should the operation fail, the function returns false, leaving the variable unmodified.

Here is the complete implementation of the LastCanceledPendingOrderMagic()function.
bool LastCanceledPendingOrderMagic(ulong &lastCanceledPendingOrderMagic) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderMagic = lastCanceledPendingOrderInfo.magic;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Reason Function

The LastCanceledPendingOrderReason() function extracts the reason code for the most recently canceled pending order and stores it in the referenced lastCanceledPendingOrderReason variable. It uses the GetLastCanceledPendingOrderData() utility function to retrieve the order details.

The reason code indicates how the order was placed or why it was triggered. For instance, ORDER_REASON_CLIENT shows that the order was placed manually from a desktop terminal, while ORDER_REASON_EXPERT indicates the order was placed by an Expert Advisor, and ORDER_REASON_WEB indicates that the order was placed from a web platform. Other possible reasons include activation due to Stop Loss or Take Profit, or as a result of a Stop Out event.

If the data retrieval is successful, the function stores the reason code in the provided variable and returns true. If it fails, the function returns false without modifying the variable.

Below is the full implementation of the LastCanceledPendingOrderReason() function.

bool LastCanceledPendingOrderReason(ENUM_ORDER_REASON &lastCanceledPendingOrderReason) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderReason = lastCanceledPendingOrderInfo.reason;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Type Filling Function

The LastCanceledPendingOrderTypeFilling() function determines the filling type of the most recently canceled pending order and assigns it to the referenced lastCanceledPendingOrderTypeFilling variable. It achieves this by calling the GetLastCanceledPendingOrderData() function to gather the necessary order details.

The filling type provides essential information about how the order was intended to be executed. If the type is "Fill or Kill (FOK)," the order must be fully filled at the requested price, and if this is not possible, it is canceled. For "Immediate or Cancel (IOC)," the order is executed immediately for the available volume at the requested price, and any unfilled portion is discarded. The "Return" type allows the order to be partially filled if the full volume is unavailable, with the remaining unfilled volume converted into a limit order. This limit order remains active in the market until it is either filled or canceled manually or by an Expert Advisor.

If the data retrieval operation is successful, the filling type is stored in the provided variable, and the function returns true. If the retrieval fails, the function returns false without modifying the referenced variable.

Below is the full implementation of the LastCanceledPendingOrderTypeFilling() function.

bool LastCanceledPendingOrderTypeFilling(ENUM_ORDER_TYPE_FILLING &lastCanceledPendingOrderTypeFilling) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderTypeFilling = lastCanceledPendingOrderInfo.typeFilling;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Type Time Function

The LastCanceledPendingOrderTypeTime() function extracts the type time of the most recently canceled pending order and updates the referenced lastCanceledPendingOrderTypeTime variable with this value. It uses the GetLastCanceledPendingOrderData() function to retrieve the necessary order details.

The type time of an order indicates how long the order remains valid. There are several types of time associated with orders: Good Till Cancel (GTC), where the order remains active until it is manually canceled; Good Till Current Trade Day, where the order expires at the end of the trading day; Good Till Expired, where the order expires after a specific date or time; and Good Till Specified Day, where the order is valid until 23:59:59 of the specified day, with the added condition that if the time falls outside a trading session, the order expires at the nearest trading time.

If the retrieval is successful, the function assigns the type time to the referenced variable and returns true. If the retrieval fails, it leaves the variable unchanged and returns false.

Here is the complete implementation of the LastCanceledPendingOrderTypeTime() function.

bool LastCanceledPendingOrderTypeTime(datetime &lastCanceledPendingOrderTypeTime) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderTypeTime = lastCanceledPendingOrderInfo.typeTime;
      return(true);
     }
   return(false);
  }


Last Canceled Pending Order Comment Function

The LastCanceledPendingOrderComment() function acquires the comment associated with the most recently canceled pending order and places it in the referenced lastCanceledPendingOrderComment variable. It utilizes the GetLastCanceledPendingOrderData() function to fetch the required order information.

If the order data is successfully obtained, the comment is assigned to the referenced variable, and the function returns true. If the operation fails, the referenced variable remains unmodified, and the function returns false.

Below is the full implementation of the LastCanceledPendingOrderComment()function.
bool LastCanceledPendingOrderComment(string &lastCanceledPendingOrderComment) export
  {
   PendingOrderData lastCanceledPendingOrderInfo;
   if(GetLastCanceledPendingOrderData(lastCanceledPendingOrderInfo))
     {
      lastCanceledPendingOrderComment = lastCanceledPendingOrderInfo.comment;
      return(true);
     }
   return(false);
  }


Conclusion

We have now developed a comprehensive history management library that is capable of querying, retrieving, categorizing, and storing the trading history of filled and canceled pending orders, as well as deals and positions. This marks a significant milestone in simplifying the management of historical trading data in MQL5, equipping developers with a versatile and efficient tool set to handle complex data requirements.

What sets this library apart is its robust and organized framework for managing trading data. By providing structured and intuitive functions, it transforms the often cumbersome task of handling trading history into a seamless process. This approach enhances accessibility to critical data while also ensures it can be effectively applied in various real-world scenarios, such as creating performance analysis tools, optimizing trading strategies, or conducting in-depth historical reviews.

The subsequent step in this series will involve creating the necessary header files that will allow end users to seamlessly import and integrate the library into their projects. Once the headers are complete, I will demonstrate how to implement the library, ensuring developers can easily incorporate its functionality into their codebase.

For your convenience, the updated HistoryManager.mq5 library source code, which includes all the functions created in this and previous articles, plus the compiled EX5 executable binary file HistoryManager.ex5 are attached at the end of this article. In the next article, we will wrap up the history management library by providing complete implementation documentation and practical examples to guide you in using this EX5 library effectively. Thank you for following along, I look forward to connecting with you again as we bring this project to its final stage.

Attached files |
HistoryManager.mq5 (81.42 KB)
HistoryManager.ex5 (33.63 KB)
Master MQL5 from Beginner to Pro (Part III): Complex Data Types and Include Files Master MQL5 from Beginner to Pro (Part III): Complex Data Types and Include Files
This is the third article in a series describing the main aspects of MQL5 programming. This article covers complex data types that were not discussed in the previous article. These include structures, unions, classes, and the 'function' data type. It also explains how to add modularity to your program using the #include preprocessor directive.
Price Action Analysis Toolkit Development (Part 8): Metrics Board Price Action Analysis Toolkit Development (Part 8): Metrics Board
As one of the most powerful Price Action analysis toolkits, the Metrics Board is designed to streamline market analysis by instantly providing essential market metrics with just a click of a button. Each button serves a specific function, whether it’s analyzing high/low trends, volume, or other key indicators. This tool delivers accurate, real-time data when you need it most. Let’s dive deeper into its features in this article.
Monitoring trading with push notifications — example of a MetaTrader 5 service Monitoring trading with push notifications — example of a MetaTrader 5 service
In this article, we will look at creating a service app for sending notifications to a smartphone about trading results. We will learn how to handle lists of Standard Library objects to organize a selection of objects by required properties.
Developing a Calendar-Based News Event Breakout Expert Advisor in MQL5 Developing a Calendar-Based News Event Breakout Expert Advisor in MQL5
Volatility tends to peak around high-impact news events, creating significant breakout opportunities. In this article, we will outline the implementation process of a calendar-based breakout strategy. We'll cover everything from creating a class to interpret and store calendar data, developing realistic backtests using this data, and finally, implementing execution code for live trading.