Pending Order Grid MT4
- Utilitys
- Francisco Manuel Vicente Berardo
- Version: 1.4
- Aktualisiert: 5 Oktober 2024
- Aktivierungen: 20
The Pending Order Grid is a multi-symbol multi-timeframe script that enables multi-strategy implementation based on pending order grids.
General Description
The Pending Order Grid allows the performing of a user-defined strategy through the creation of pending order grids. The script places pending orders of a given type (Buy Limit, Sell Limit, Buy Stop, or Sell Stop) at equidistant price levels to form each grid. The beginning and finish of every grid are defined by the Start Price and Stop Price input parameters, respectively. The user might set up different grids to exist simultaneously – it's only needed to execute the script multiple times at the chart window(s) of the intended symbol(s).
Risk Management
The volume used to place a pending order is chosen between a fixed and a variable lot size, available through the Volume and Free Margin % input parameters, respectively. If there isn't enough money in the account for the chosen volume, a request for placing the order is still sent to the trade server. The purpose is to allow the corresponding position opening if the free margin increases enough until the target price is reached. This increase could be due to an account deposit or position profit between the placing and triggering of the pending order.
Input Parameters
PENDING ORDER GRID
- Start Price: Price used to define the grid’s start.
- Stop Price: Price used to define the grid’s stop.
- Price Level: Distance used between pending orders of the same type (pips).
PENDING ORDER PLACING
- Magic Number: Script’s identifier.
- Type: Pending order type used to form the grid.
- Volume: Lot size per deal (lots).
- Free Margin %: Percentage of account free margin used to calculate the lot size per deal (%).
- Stop Loss: Distance from the pending order's target price for placing a Stop Loss (pips).
- Take Profit: Distance from the pending order's target price for placing a Take Profit (pips).
- Deviation: Maximum allowed slippage from the requested price (pips).
- Expiration Time: Order validity period.
- Comment: Text message displayed in the Trade or Account History tabs of the Terminal window and Objects list after placing a pending order (it only allows 31 characters).
Some of the available parameters accept values that lead to particular options.
- Price Level: A null value means that the target price is constant for all pending orders.
- Volume: A value lower than the minimum allowed volume by the broker is converted in this last. A value higher than the maximum available volume by the free margin is converted in this last.
- Free Margin %: A value whose volume doesn’t reach the minimum allowed volume by the broker is converted in this last. A value whose volume exceeds the maximum available volume by the free margin is converted in this last.
- Stop Loss or Take Profit: A null value means the parameter’s inactive function. Any value between 0 and the Stop Level is converted in this last.
The input parameters that define the start and stop of the grid must obey a few rules.
- Both the limits of the grid must be selected: Start Price and Stop Price.
- Buy Limit or Sell Stop orders grid: The Start Price cannot exceed the Ask/Bid price minus the Stop Level, respectively. The Stop Price cannot exceed the Start Price.
- Sell Limit or Buy Stop orders grid: The Start Price must equate/exceed the Bid/Ask price plus the Stop Level, respectively. The Stop Price must equate/exceed the Start Price.
Displayed Information
The script possesses a vast number of messages to inform the user about errors and conditions changes that might occur during its execution. The messages are shown through the Alert function (by a pop-up window), its content includes:
- The warning that an input parameter has been incorrectly set.
- The info that the account doesn't have enough money for the chosen volume (see the Risk Management section above).
- The info that the number of permitted orders by the broker has been reached.
- The Trade Server Return Codes description.
- The symbol’s quotes (immediately) before the trade request’s formation, followed by the symbol’s quotes (immediately) after the trade server’s decision.
Note: Some elements of the list are displayed simultaneously (in the same text line): 4 and 5.
Observations
During high activity periods, the trade server’s decision on whether a trade request is executed or rejected may suffer significant delays. Some data used in the request sent to the server might become incorrect, leading to the order’s rejection. When the server is evaluating a request and the symbol's quotes are updated, three cases might occur:
- Pending order placing – the pending order’s target price becomes an incorrect distance.
- Position opening/modifying – the position’s Stop Loss or Take Profit intended level becomes an incorrect distance.
- Position modifying – the position’s Stop Loss or Take Profit previous level takes to its closing.
The symbol’s quotes mentioned in the fifth element of the list in the Displayed Information section are especially useful here (since firsts usually differ from lasts). A careful analysis of these quotes, knowing the implication that certain quote changes have on the request’s evaluation, permits understanding the reason when these cases occur. To avoid the request’s rejection by the trade server due to “invalid stops” (cases 1 and 2), the prices/levels used should exceed the symbol’s Stop Level by a few pips.
A Buy/Sell position is opened at the Ask/Bid price and closed at the Bid/Ask price. Since the position’s stop orders (Stop Loss and Take Profit) are triggered at this last price, in a pending order, they are calculated from the order's target price -/+ the current spread (Ask - Bid), respectively.
When placing a pending order, the validity period can’t be less than 10 minutes. During a grid creation, the script doesn’t place pending orders if the current time exceeds the Expiration Time minus 10 minutes (when the validity period is previously selected).
Conclusion
The Pending Order Grid is a helpful and effective tool regarding the manual creation of pending order grids, especially when the grids consist of a significant number of orders, enabling a simple and intuitive setting of the grids to form.