There are five structures that handle trade exits. Each will be covered in detail below. While none of these structures are required in a query, at least one type would be necessary for meaningful results.
The EXIT condition can be used to exit trades initiated by the SAME order block. There are two variants of this exit structure: EXIT and EXIT INDIVIDUAL. EXIT (similar to EXIT Combined in the Exit Action window, discussed below) exits all orders initiated by the order block. EXIT INDIVIDUAL can be used to exit only those trades that meet security specific conditions (discussed below). Specifying either type of exit condition is similar to specifying the WHEN conditions for the trade.
The EXIT INDIVIDUAL condition allows greater flexibility in exiting trades when more than one security is involved in the same order block. The query below shows an example where both US and BP are bought at the same time. If we also want to exit both US and BP at the same time, we can just use the EXIT condition. If, however, we want to exit a trade (i.e. US or BP) only if the trade becomes unprofitable, we can use EXIT INDIVIDUAL. In this case, regardless of what happens to US, the BP trade is exited only if it becomes unprofitable. Similarly, US is exited if it becomes unprofitable. An application of this might be to first initiate a pseudo-hedged trade and then lift one ‘leg’ of the hedge when that ‘leg’ becomes unprofitable.
In the example below, also note how additional order blocks are used to exit the profitable trades.
The following query highlights some of the various ways of exiting a trade.
The first block enters a trade in both US and BP. Note the EXIT INDIVIDUAL condition in this block. This exit type triggers an exit only for the security that meets the conditions. In this example, if only US has open equity less than –500, then only the US trade is exited. On the other hand, if the exit type were EXIT (meaning, EXIT COMBINED) and not EXIT INDIVIDUAL, both US and BP would have been exited when either lost more than 500.
The second and third order blocks highlight the use of the Exit trade order. Block 2 handles the exit for US while block 3 takes care of BP.
1: ORDER
1.1: Buy 1 contract of US
Enter on the close
1.2: Buy 1 contract of BP
Enter on the close
1.3: Exit individual 1.1: on the Close
WHEN
Date is after 1/1/1990
AND
Close of US is more than 30 day highest of US 1 day ago
AND
Close of BP is more than 30 day highest of BP 1 day ago
EXIT individual
open_equity is less than -500
2: ORDER
2.1: Exit individual 1.1: on the Close
WHEN
Close of US is less than 30 day lowest of US 1 day ago
3: ORDER
3.1: Exit individual 1.2: on the Close
WHEN
Close of BP is less than 30 day lowest of BP 1 day agoAnother way to exit a trade is to place an Exit trade order () in the Exit Trade area () of the Order window. The main benefit of this structure is that it can be used to exit orders and trades initiated by another order block. Each trade order can be referenced by unique labels (1.1, 1.2, etc., in the example below). This allows the behavior of one block to influence the behavior of another. Also, as with the EXIT condition described above, this structure also has two variants: Exit Combined and Exit Individual. The steps involved in using the Exit order are shown below.

A new window displays to add the Exit information.

Perhaps the simplest way to exit a trade is when an opposite trade signal is generated. To exit a trade when a reverse signal is generated, select the check box for Exit On Reverse Signal in the Execute Options window (from the menu bar, select Options>Execute Options then select the Order tab) (see and below). Exit on Reverse Signal is the system default.

The following shows a query that would be used with the Exit on Reverse Signal setting.
1: ORDER
1.1: Buy 1 contract of US
Enter on the close
WHEN
Date is after 1/1/1980
AND
Close of US crosses above 30 day average of US
2: ORDER
2.1: Sell 1 contract of US
Enter on the close
WHEN
Date is after 1/1/1980
AND
Close of US crosses below 30 day average of USThis exit type Maintain Positions Overnight is listed in the Execute Options window (from the menu bar select Options>Execute Options then select the Order tab). This option controls the treatment of open trades at the end of the day. Uncheck this option if all open trades are to be exited at the end of the day. Otherwise (with this option selected), all open positions will be maintained until the next day and the trade will have to be exited via other methods.
Some price based exit rules (stops and objectives, for example) can be specified directly in the Exit Options area of the Order window. The main benefit of this structure is that it is a convenient way to specify trailing stops and moving objectives. The system takes care of updating stops and objectives as the trade progresses.
Stop-loss and trail stop-loss are two types of loss control stops employed in XMIM. In the Exit Options area of the Order window they are called Exit Loss Value and Exit Loss Trail. Exit Loss Value is the same as the traditional money management stop. It can be used to specify the initial stop loss point. Exit Loss Trail can be used to specify a trailing stop that moves with the market as the trade develops in the expected direction. In stop-loss and trail stop-loss, 100 and $100 is different. 100 is price and $100 is value and they are not interchangeable. The system ensures that if a trailing stop is used, it always moves to protect greater and greater profits. For example, in a long position, the trailing stops will always be moving up with the market. The system will ignore a trailing stop calculation that is below the current trailing stop value. If both Exit Loss Value and Exit Loss Trail are used, the Exit Loss Trail is ignored until it protects greater profits than the Exit Loss Value. In the Order windows, the Exit on Open, Close, or Market buttons can be selected to govern when the stop-loss orders are checked and executed. An example of a stop-loss order is presented below.
1: ORDER
1.1: Buy 1 contract of US
Enter on the close
Exit with stop_loss at entry_price - 0.005
trail stop_loss at 4 day lowest of US 1 day ago - 0.003Exit Profit Value and Exit Profit Trail: There are also two types of profit objective exits in the Exit Options area of the Order window. In fact, Exit Profit Value and Exit Profit Trail are exact mirror images of Exit Loss Value and Exit Loss Trail. An interesting use of Exit Profit Value and Exit Profit Trail objectives might be to exit a trade when the market exhibits extraordinary momentum in the favorable direction. Of course, such a trade should be exited when the market is expected to reverse or consolidate. As with Exit Loss Value, Exit Profit Value specifies the initial profit objective. Exit Profit Trail can be used to specify a profit objective that always moves with the market as the trade develops in the expected direction. An example of profit objectives is presented below.
1: ORDER
1.1: Buy 1 contract of US
Enter on the close
Exit with stop_loss at entry_price - 0.005
trail stop_loss at 4 day lowest of US 1 day ago - 0.003
take profit at entry_price + 0.006
trail profit at High of US 1 day agoThis section will describe how the system executes Limit and Stop orders:
If the security opens at the limit or below the limit, it will buy at the Open price. If the security opens above the limit, and then crosses to or below the limit, then it will buy at the limit.
If the open price is at or above the stop, it will buy at the open price. If the security opens below the stop, and then crosses to or above the stop, then it will buy at the stop value.
The entry-stop-value is above the limit value: If the security opens at or below the limit or at or above the stop, it will buy at the open. If the security opens above the limit and below the stop, and then crosses to or above the stop, it will buy at the stop. If it opens above the limit and below the stop, and crosses to or below the limit, it will buy at the limit. If it opens between the limit and stop and the bar extends through both the limit and the stop, it will use the mid-point method: it will buy at the entry stop if the open is above the mid-point of the range between the stop and the limit; it will buy at the limit if it opens below the range.
The limit value is above the entry-stop-value: If it opens at or above the stop and at or below the limit, it will buy at the limit. If the open is below the stop and crosses to or above the stop, it will buy at the stop. If the open is above the limit and crosses to or below the limit, it will buy at the limit. If it opens between the stop and the limit and the bar extends through both the limit and the stop, it will use the midpoint method: it will buy at the limit if the open is above the midpoint of the range between the stop and the limit; it will buy at the stop if it is below the midpoint.
If the security opens at the profit or above the profit, it will sell at the open. If the open is below the profit and crosses to or above the profit, then it will exit at the profit.
If the open is at or below the stop, it will sell at the open. If the open is more than the stop and it trades to or through the stop, it sells at the stop.
If the open is at or above the profit, it will sell at the open. If the open is at or below the stop, it will sell at the open. If the open is below the profit and above the stop, and crosses to or above the profit, it will sell at the profit. If the open is below the profit and above the stop, and crosses below the stop, it will sell at the stop. If it opens between the profit and the stop and the bar extends through the profit and the stop, it will use the midpoint method: it will sell at the profit if the stock opens above the midpoint of the range between the profit and the stop; it will sell at the stop if it is below the midpoint.
If it opens at or above the profit and below the stop, it will sell at the stop. If it opens between the profit and the stop and the bar extends through both the profit and the stop, it will use the midpoint method: it will sell at the stop if the open is above the midpoint of the range between the stop and the profit; it will sell at the profit if the open is below the midpoint.
If the open is at or above the limit, it will sell at the open. If the open is below the limit and crosses to or though the limit, it will sell at the limit.
If the open is at or less than a stop, it will sell short at the stop. If the security opens above the stop, then crosses to or below the stop, then it will sell at the stop value.
The entry stop is above the limit value: if the open is at or below the stop and at or above the limit, it will sell short at the open. If the open is above the stop and crosses to or through the stop, it will sell short at the stop. If the open is below the limit and crosses to or above the limit, it will sell short at the limit. If it opens between the entry stop value and the limit value and the bar extends through both the entry stop value and the limit value, it will use the midpoint method: it will sell at the entry stop value if it opens above the midpoint of the range between the entry stop and the limit value; it will sell short at the limit if it opens below the midpoint.
The limit value is above the stop: if the open is at or above the limit it will sell short at the open. If the open is at or below the stop, it will sell short at the stop. If the open is between the limit and the stop and it crosses to or above the limit, it will sell short at the limit. If it opens between the limit value and the entry stop, and the bar extends through both the limit value and the stop value, it will use the midpoint method; it will sell short at the limit value if it opens above the midpoint of the range. It will sell at the stop value if it opens below the midpoint.
If the open is at or below the profit value, it will buy at the open. If the open is above the profit and crosses to or below the profit, it will buy at the profit.
If the open is at or above the stop loss value, it will buy at the open. If the open is below the stop loss value, and crosses to or above, it will buy at the stop loss value.
If the open is below profit and above the stop, it will buy at the open. If the open is above the profit and crosses to or below the profit, it will buy at the profit. If the open is below the stop loss value and crosses to or above the stop, it will buy at the stop. If the open is between the stop loss value and the profit, and the bar extends through both the stop loss value and the profit, it will use the midpoint method: it will buy at the profit value if the open is above the midpoint of the range. It will buy at the stop loss price if it is below the midpoint.
When using a Buy Stop above a Buy Limit
If the open is at or above the stop loss value, buy at the open. If the open is at or below the profit value, it will buy at the open. If the open is between the stop loss value and the profit value and it crosses to or above the stop loss value, buy at the stop loss value. If the open is between the stop loss value and the profit value and it crosses to or below the profit value, and the bar extends through both the stop loss value and the profit value then it will use the midpoint method: it will buy at the stop loss value if the open is above the midpoint of the range. It will buy at the profit value if the open is below the midpoint.
Notice that when you are long, the profit trail will behave like the stop loss but the system will ignore the profit trail if it is below the stop loss value. The opposite is true for a short.