PEO - Pending Orders
Concept diagram
The concept diagram provided below depicts the function block associated with this page.
Enabling of pending order mode
A pending order is an instruction given to a broker to execute a trade at a future time when certain conditions are met. This allows for the automation of your trading process. Standard pending orders include limit, stop, or stop limit orders, which can be set for long and short directions.
The Expert Advisor Builder can execute all these orders in the context of automated trading abstraction. However, the configuration process differs slightly from traditional trading. This modification was necessary to maximize the potential of various pending order configurations and to simplify the reuse of a trading idea. Furthermore, the configuration of pending orders was influenced by engineering principles and relied on simple terminology.
With the order manager, you can select between long and short trades. Depending on the trade direction, the stop loss and take profit values will be interchanged to minimize the need for further changes. Generally, the Expert Advisor Builder uses relative values as its input. For instance, a long order requires a stop loss level below the current price. Thus, the stop loss difference is negative, while a short order requires a stop loss level above the current price, resulting in a positive stop loss difference.
Instead of using a positive or negative stop loss difference to define that, the Expert Advisor Builder's stop loss difference input is a positive number. The logic automatically adds or subtracts the stop loss difference from the current price depending on the selected trade direction. This means that when a change of the trading direction is required, only one input modification is needed.
This principle also applies when selecting the pending price of a stop or limit order. Based on the price at which a pending order is sent, the pending price can be either above or below. Derived from that, it can be a stop or limit order, depending on the trade direction. The Expert Advisor Builder only needs information on the pending price difference and whether this value will be added or subtracted. Based on that, the order logic automatically selects the correct order type, take profit, and stop loss levels.
By default, the trading modules produced with the Expert Advisor Builder execute long or short trades. To use a pending order instead, the input parameters > (PEO) Mode has to be adjusted accordingly. The table below shows that this input parameter can be OFF, ADD, or SUB. With it, you define whether the pending price shall be above or below the price when the order is configured.
Input variable within MetaTrader (Identifier in SET file) | Default value | Comment |
---|---|---|
> (PEO) Mode (IN_enmPeoMode) | OFF | Numeric values usable in SET files: 0 - OFF 1 - ADD 2 - SUB |
> (PEO) Mode = OFF
The input parameter > (PEO) Mode allows you to specify the position of the pending price for a trade. When OFF is selected, the order becomes a market order, which means it's either a buy or sell order, depending on the chosen trade direction. This is the default setting.
> (PEO) Mode = ADD
By choosing ADD for the > (PEO) Mode, you are instructing the Expert Advisor Builder, specifically the trading module, to open a pending order with its pending price set above the current price. This implies a difference between the pending price and the current prices, which is determined by the input parameter > (PEO) Price. However, depending on the trade direction, the Expert Advisor Builder will select a buy stop or sell limit order. Please refer to the example charts below to compare the effects of ADD mode.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_2_v_2_0.zip.
> (PEO) Mode = SUB
When you select SUB for the > (PEO) Mode, you're directing the Expert Advisor Builder, specifically the trading module, to open a pending order with its pending price below the current price. This indicates a price difference between the pending price and the current prices, which is defined by the input parameter > (PEO) Price. Depending on the trade direction, the Expert Advisor Builder will choose either a buy limit or sell stop order. Please refer to the example charts below to compare the effects of SUB mode.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_3_v_2_0.zip.
Calculation methods for pending price
The difference between the pending and current prices is always a positive input parameter. Selecting SUB or ADD determines how this value is used. It is either added to or subtracted from the current price. Similar to the initial take profit and initial stop loss, you can choose from several calculation methods for the pending price difference. You can define it by a fixed value measured in pips, a relative value measured in rate of change, or by selecting previous support or resistance as the pending price level. By default, the pending price is set to an earlier support or resistance level. Please refer to the following table and example charts to see the effect of the different > (PEO) Price calculation methods.
Input variable within MetaTrader (Identifier in SET file) | Default value | Comment |
---|---|---|
> (PEO) Price (IN_enmPeoPrice) | MARKET HILO | Numeric values usable in SET files: 0 - FIX PIPS 1 - RATE OF CHANGE 2 - MARKET HILO |
> (PEO) Price = FIX PIPS
When the FIX PIPS option is selected, the pip value defined with the input parameters > (PEO) Fix pips is used to place the pending price above or below the current price. This value remains constant throughout the entire operational time of the trading module.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_4_v_2_0.zip.
> (PEO) Price = RATE OF CHANGE
Over time, many markets undergo slight volatility and general market behavior changes. This often necessitates adjusting the fixed pips value as the price reference changes. For instance, for a stock worth 10 USD at its IPO, a 1 USD pending price difference represents 10%, but when the price increases to 100 USD, the same 1 USD only represents 1%. When selecting the RATE OF CHANGE mode for the input parameter, the pending price difference can be described with a relative measure. The relative value remains constant over time but results in changing absolute difference values.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_5_v_2_0.zip.
> (PEO) Price = MARKET HILO
Please select the MARKET HILO mode to use a previous support or resistance level as pending price. This also requires the adjustment of four distinct input parameters to limit the time range and price range in which it is allowed to search and select a local low (for SUB orders) or local high (for ADD orders) as the pending price. The image below demonstrates a trade with a pending price the same as a previous local low.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_6_v_2_0.zip.
The behavior of stop loss and take profit
The Expert Advisor Builder calculates the initial stop loss and take profit level when the actual trade signal appears. It's clear that simply moving the pending price while keeping the stop loss and take profit levels static could lead to unpredictable risk and money measurements. Therefore, the Expert Advisor Builder adjusts the initial stop loss and take profit values according to the pending price differences. This ensures that the risk ratio, determined when the signal appears, remains the same even when the actual order is executed later. However, keeping the initial stop loss or initial take profit at the same level as a regular market order might be desirable.
With the input parameters > (PEO) Limits, you can decide what happens with the initial stop loss and initial take profit for pending orders.
Input variable within MetaTrader (Identifier in SET file) | Default value | Comment |
---|---|---|
> (PEO) Limits (IN_enmPeoLimits) | SL AND TP MOVED | Numeric values usable in SET files: 0 - INITIAL 1 - TP MOVED 2 - SL MOVED 3 - SL AND TP MOVED |
> (PEO) Limits = INITIAL
The INITIAL option results in initial stop loss and initial take profit levels that are the same as for a regular market order. Please note that this might interfere with the pending price. It's self-explanatory that the stop loss price cannot be above the pending price in the case of a buy limit or buy stop order. The image below demonstrates this option with valid initial take profit and stop loss levels.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_7_v_2_0.zip.
> (PEO) Limits = TP MOVED
When TP MOVED is selected, only the take profit is adjusted by the value of the pending price difference. Please refer to the example chart below to see the difference from the previous chart. Keep in mind that this option changes the risk ratio.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_8_v_2_0.zip.
> (PEO) Limits = SL MOVED
When SL MOVED is selected, only the stop loss is adjusted by the value of the pending price difference. Please refer to the example chart below to see the difference from the previous chart. Keep in mind that this option changes the risk ratio.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_9_v_2_0.zip.
> (PEO) Limits = SL AND TP MOVED
The SL AND TP MOVED option, used as the default value, makes the most sense as it moves both limit values. This option maintains the same risk ratio for pending orders, regardless of the pending price difference. Since the initial stop loss and initial take profit are adjusted according to the pending price difference, the initially determined risk ratio remains unchanged. The image below shows this option for a buy stop order. Compared to the previous options, the initial stop loss and initial take profit are adjusted according to the ADD selection.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_10_v_2_0.zip.
Price series used to trigger order opening
To utilize this feature, you must first enable local pending orders. Please refer to the relevant article for instructions on enabling local pending orders. Trading modules generated with the Expert Advisor Builder offer the flexibility to modify the pending price reference. For instance, while a buy stop order typically uses the ask price to trigger a trade, the local pending orders option allows you to use other prices, such as the middle value between the bid and ask. This can be particularly beneficial in highly volatile markets with wider spreads. Brokers often widen the spread by increasing the ask price and lowering the bid price, which may not accurately reflect actual price movement as your broker's spread characteristic influences it. This setting is advantageous for faster trading styles like scalping and day trading.
Input variable within MetaTrader (Identifier in SET file) | Default value | Comment |
---|---|---|
> (PEO) Reference (IN_enmPeoReference) | ASK BID | Numeric values usable in SET files: 0 - ASK BID 1 - ASK BID MIDDLE 2 - MEDIAN 3 - TYPICAL 4 - WEIGHTED |
All options are demonstrated below, with an example chart featuring a buy order.
> (PEO) Reference = ASK BID
When the ASK BID option is selected, the ask price is used for buy pending orders, and the bid price is used for sell pending orders. The example chart below illustrates a pending order that used this price reference.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_11_v_2_0.zip.
> (PEO) Reference = ASK BID MIDDLE
If the ASK BID MIDDLE option is chosen, both buy and sell pending orders use the value between the ask and bid price, also known as the average price derived from both prices. The example chart below illustrates a pending order that used this price reference to execute the order.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_12_v_2_0.zip.
> (PEO) Reference = MEDIAN
The MEDIAN price series considers the open, low, high, and close price of each bar. The resulting price series is a smoothed price line with fewer peaks. To use this price for triggering pending orders, please select the MEDIAN option. The example chart below illustrates a pending order that used this price reference as a selection.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_13_v_2_0.zip.
> (PEO) Reference = TYPICAL
The TYPICAL price series also considers each bar's open, low, high, and close prices. The resulting price series is a smoothed price line with fewer peaks. Please select the TYPICAL option to use this price for triggering pending orders. The example chart below illustrates a pending order that used this price reference as a selection.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_14_v_2_0.zip.
> (PEO) Reference = WEIGHTED
The WEIGHTED price series considers each bar's open, low, high, and close prices. The resulting price series is a smoothed price line with fewer peaks. Please select the WEIGHTED option to use this price for triggering pending orders. The example chart below illustrates a pending order that used this price reference as a selection.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_15_v_2_0.zip.
Expiration of pending orders
It's possible to set an expiration date for limit and stop orders. The pending order will be deleted if the pending price isn't triggered by the expiration date. The expiration date can be configured by using the input parameter > (PEO) Expiration (<0 -> Seconds, 0 -> OFF, >0 -> Bars).
Input variable within MetaTrader (Identifier in SET file) | Default value | Comment |
---|---|---|
> (PEO) Expiration (<0 -> Seconds, 0 -> OFF, >0 -> Bars) (IN_nPeoExpiration) | 0 | Negative input values represent the expiration time in seconds, while positive input values represent the expiration time in the number of bars in the current timeframe. An input value of zero turns off the expiration entirely. |
As indicated by the name of the input parameters, you can use the value in different forms. The expiration is measured in seconds if the input value is less than zero. For instance, -3600 means the order will be deleted after one hour. If the input value is greater than zero, the expiration time will be interpreted in bars. For example, an input parameter of 10 and a used timeframe of M15 means the order will expire in 150 minutes, approximately 2.5 hours. To turn off the expiration, which means to keep a pending order for an unlimited time, please select 0. This is also the default value. The following demo chart shows the effect of a pending order with expiration. As seen in chart b), the order is deleted before execution.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_16_v_2_0.zip.
Parameters for fix pips based pending price
In the table below, you can find all input parameters used to adjust the FIX PIPS option.
Input variable within MetaTrader (Identifier in SET file) | Default value | Comment |
---|---|---|
> (PEO) Fix pips (IN_nPeoFixPips) | 50 | The input value cannot be smaller or equal to 0. The input parameter is only used when FIX PIPS is selected for > (PEO) Price. |
To use a fixed amount of pips is the most straightforward concept of defining the pending price difference. Nevertheless, the following four chart examples demonstrate how the pending price is placed further away as larger the > (PEO) Price is.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_17_v_2_0.zip.
Parameters for rate of change based pending price
The table below lists all input parameters used to adjust the RATE OF CHANGE option.
Input variable within MetaTrader (Identifier in SET file) | Default value | Comment |
---|---|---|
> (PEO) Rate of change (min value) (IN_dPeoRateOfChange) | 0.0002 | The input value cannot be smaller or equal to 0. The input parameter is used when RATE OF CHANGE is selected for > (PEO) Price or as the backup value if the pending price difference is too close to the actual price. |
As mentioned earlier, the RATE OF CHANGE option allows you to define the pending price as a relative value, using the price as a reference at the moment of opening. When RATE OF CHANGE (ROC) is selected, the opening price represents 100%, for example, 10000 USD. If 0.003 is configured for the input parameter > (PEO) Rate of change (min value), the pending price difference is calculated by 0.003 ROC 10000 USD = 30 USD. As the price changes, the pending price difference adapts accordingly. This is particularly useful for assets with rising prices over time, such as indices. For example, if the indices price grows to 11000 USD, the pending price difference will become 0.003 ROC 11000 USD = 33 USD. In addition to its relative nature, this parameter is the minimum pending price difference for the entire PEO module.
As demonstrated in the series of examples below, the larger the rate of change value is configured, the larger the initial stop loss difference becomes.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_18_v_2_0.zip.
Parameters for HiLo based pending price
The table below lists all the input parameters used to adjust the MARKET HILO option.
Input variable within MetaTrader (Identifier in SET file) | Default value | Comment |
---|---|---|
> (PEO) Market HiLo range (IN_nPeoMarketHiLoRange) | 100 | The input value cannot be smaller or equal to 0. The input parameter is only used when MARKET HILO is selected for > (PEO) Price. |
> (PEO) Market HiLo min (IN_dPeoMarketHiLoMin) | 0.2 | The input value has to be between 0 and 1. The input parameter is only used when MARKET HILO is selected for > (PEO) Price. |
> (PEO) Market HiLo max (IN_dPeoMarketHiLoMax) | 1.0 | The input value has to be between 0 and 1. The input parameter is only used when MARKET HILO is selected for > (PEO) Price. |
> (PEO) Market HiLo prominence (IN_dPeoMarketHiLoProminence) | 0.025 | The input value has to be between 0 and 1. The input parameter is only used when MARKET HILO is selected for > (PEO) Price. |
> (PEO) Market HiLo correction (IN_dPeoMarketHiLoCorrection) | 1.0 | The input value cannot be smaller or equal to 0. The input parameter is only used when MARKET HILO is selected for > (PEO) Price. |
Various input parameters can be used to adjust the MARKET HILO algorithm, each illustrated in the functional diagram below.
The input parameters serve the following purposes:
- > (PEO) Market HiLo range: This defines the bars within which a high or low can be searched.
- > (PEO) Market HiLo min: This sets the minimum prominence a high or low must have to be valid as the value for the initial stop loss. The input is allowed to be between 0 and 1, representing 0% or 100% of the Market HiLo reference. The Market HiLo reference is the difference between the current price and the lowest price (for long trades) or the highest price (for short trades) within the range defined by the Market HiLo range.
- > (PEO) Market HiLo max: This sets the maximum distance the local low or local high can be from the opening price. The Market HiLo reference is also used for these parameters as a reference. The parameter can be between 0 and 1, representing 0% or 100%.
- > (PEO) Market HiLo prominence: The prominence parameter defines the minimum significance required between local lows and local highs to qualify for a valid low or high detection. Similar to the min and max values, it can range between 0 and 1, representing 0% or 100% of the Market HiLo reference.
- > (PEO) Market HiLo correction: This value can be used to fine-tune the final selected initial stop loss value. If the value is smaller than one, the initial stop loss moves closer to the current price. If the value is greater, the stop loss moves away from the current price.
Please refer to the examples below, which demonstrate some setups for the Market HiLo initial stop loss selection.
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_20_v_2_0.zip.
Pending price with hysteresis
The hysteresis feature in the context of automated trading and trade abstraction extends the typically available order types. While most traders are familiar with market, limit, and stop orders, another official order type exists - the stop limit order. This order type requires the price first to increase, then decrease or decrease, and then increase again. However, this order type must be better integrated into MetaTrader 4 or MetaTrader 5. Nevertheless, this order type is a convenient tool for automated trading. Instead of using the stop limit order option, the Expert Advisor Builder introduces a feature called hysteresis. A hysteresis allows a wide range of exciting ways of handling pending orders.
This feature is a software-only solution, available when local pending orders are enabled. Due to its technical nature, it is highly recommended that you familiarize yourself with each pending order combination possible with this feature. However, it's not necessary to use it at all. Most traders will likely be able to build profitable and long-term stable trading solutions without using this feature. The following two input parameters matter for those who wish to use it. The hysteresis feature is active only when one of these input parameters is not equal to zero. By default, it is disabled.
Input variable within MetaTrader (Identifier in SET file) | Default value | Comment |
---|---|---|
> (PEO) Hysteresis min (requires local pending, 0 -> OFF) (IN_nPeoHysteresisMin) | 0 | The pending price must exceed the minimum position to be activated. |
> (PEO) Hysteresis max (requires local pending, 0 -> OFF) (IN_nPeoHysteresisMax) | 0 | The pending order will be automatically deleted if the maximum position is reached. |
In simpler terms, a pending order will only be executed when the price first surpasses the minimum value and then reaches the pending price. However, the order will be deleted if the maximum value is exceeded. This allows for price-dependent deletion of pending orders and the implementation of stop-limit orders. As you'll see in the following examples, this feature helps respond to anticipated future price changes, typically indicated by leading trading signals such as the RSI or the chart analyzer.
Hysteresis - Long, SUB, principle
The diagram below illustrates how positive or negative input parameters for > (PEO) Hysteresis min and > (PEO) Hysteresis max are interpreted for long pending orders. As is typical with the Expert Advisor Builder, all input parameters are relative, meaning that a reference is used to describe absolute prices. In this case, the pending price difference defined with > (PEO) Price is interpreted as 100%. As shown below, depending on whether a negative or positive input parameter is given, different min and max values lead to prices above or below the pending price.
In total, four significant input parameters influence the hysteresis feature. The best approach is to describe all options with function principles and chart examples based on actual trades. Please refer to the following example series to understand all possibilities for long pending orders.
Hysteresis - Long, SUB, max or min value only
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_22_v_2_0.zip.
Hysteresis - Long, SUB, min value < max value
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_23_v_2_0.zip.
Hysteresis - Long, SUB, min value > max value
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_24_v_2_0.zip.
Hysteresis - Long, ADD, max or min value only
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_25_v_2_0.zip.
Hysteresis - Long, ADD, min value < max value
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_26_v_2_0.zip.
Hysteresis - Long, ADD, min value > max value
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_27_v_2_0.zip.
Hysteresis - Short, SUB, principle
The diagram below illustrates how positive or negative input parameters for > (PEO) Hysteresis min and > (PEO) Hysteresis max are interpreted for short pending orders. As is typical with the Expert Advisor Builder, all input parameters are relative, meaning that a reference is used to describe absolute prices. In this case, the pending price difference defined with > (PEO) Price is interpreted as 100%. As shown below, depending on whether a negative or positive input parameter is given, different min and max values lead to prices above or below the pending price.
In total, four significant input parameters influence the hysteresis feature. The best approach is to describe all options with function principles and chart examples based on actual trades. Please refer to the following example series to understand all possibilities for short pending orders.
Hysteresis - Short, SUB, max or min value only
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_29_v_2_0.zip.
Hysteresis - Short, SUB, min value < max value
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_30_v_2_0.zip.
Hysteresis - Short, SUB, min value > max value
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_31_v_2_0.zip.
Hysteresis - Short, ADD, max or min value only
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_32_v_2_0.zip.
Hysteresis - Short, ADD, min value < max value
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_33_v_2_0.zip.
Hysteresis - Short, ADD, min value > max value
To reproduce the chart from above, you can download and use the SET file package um_eab_cpeo_34_v_2_0.zip.