How to Create a Trading Strategy with Both a Limit Order and a Stop Order Active at the Same Time

Warning stops, limits, trailing stops, and stop limits are difficult to understand and simulate. You may not understand this tip unless you are a trader experienced with these concepts. It is beyond the scope of our technical support services to educate you in these concepts, so this tip should be examined only by the most advanced users. Furthermore, we often argue that trailing stops should be considered “insurance” in case your trading strategy fails, rather than an integral part of the strategy itself. Even though we allow trailing stops in trading strategies and will even optimize them, you may want to consider using the insurance concept and keep the trailing stops between you and your broker.

NOTE 1: Please read the web tip “How the Trailing Stop Interacts with the Exit Order in a Trading Strategy” before reading further as it provides a basis of understanding of the explanation that follows:

NOTE: A distinct Stop order and a distinct Limit Order are not accomplished by using the Stop-Limit Order. The Stop-Limit Order is actually only one distinct order.

In the NeuroShell Trader, the Trailing Stop and Exit Order are considered two distinct methods of exiting a position. The NeuroShell Trader does not currently allow multiple exit methods for the same bar, so it must make a decision on each bar with regard to which of these exit methods shall be used. Currently, the NeuroShell Trader gives the Exit Order precedence over a Trailing Stop.

Because the NeuroShell Trader does not allow multiple exits for the same bar, it is impossible to have both a stop order and a limit order active on the same bar. However it is possible to create a trading strategy to simulate having both a stop order and limit order active on the same bar for the purposes of backtesting only. This is accomplished by allowing the strategy to look forward in time to decide which of the two orders would be executed. NeuroShell can then place the one that is appropriate. Because this simulation looks forward in time to determine which order to place for the next bar, the trading strategy CAN NOT BE USED FOR ACTUAL TRADING.

The Trading Strategy to simulate a limit order and a stop order active at the same time will take the following form:

Long Entry: Condition A
Trailing Stop: Price X
Long Exit: Condition B (Limit Order at Price Y)

The condition A is any condition which you have decided to use to enter a position. Price X is the stop price for the next bar. Price Y is the limit price for the next bar. The trick to the simulation is in Condition B. Since the NeuroShell Trader can not place both a stop order and a limit order on the same bar, Condition B is essentially the condition which controls whether the limit price (Condition B true) is placed or the stop price (Condition B false) is placed for the next bar.

The trick is to make Condition B look forward to the next bar to make sure whichever order will be executed in the next bar is the one which is placed. To make the limit order get placed whenever it will be hit in a long position, you would simply enter the Condition B as follows:

A>B ( Lead(High,1), Price Y)

This effectively places a stop order at Price X for the next bar, unless Price Y is reached on the next bar, in which case a limit order at Price Y is placed. This makes the simulation work correctly, i.e., as it would have in real trading.

The above condition B handles everything but the situation when BOTH Price X and Price Y are reached in the following bar. In that case, a decision must be made as to which price will be hit first. Since the NeuroShell Trader only has the Open, High, Low, and Close of the next bar, it is impossible to actually determine which price is hit first with any certainty. The condition used above is actually a best case scenario because the limit order will always be assumed to be executed before the stop order when both get hit in the same bar. However, this may provide artificially high backtest results because the limit price is usually more favorable than the stop price and therefore you would get more profit exiting at the limit price than the stop price. To backtest using a worst case scenario, you would want to assume that the stop price is always hit before the limit price in a given bar. To make the stop price get placed whenever it will be hit in a long position (worst case scenario), you would change Condition B as follows:

A>B ( Lead(Low,1), Price X)

If you don’t want a worst case or best case scenario, we leave it to the users imagination to create some more complex logic for Condition B to determine whether Price X or Price Y would be hit first in a given bar (we suggest using some logic based upon the relative differences between the open, high, low, and close values …).

Please note that since this Trading Strategy looks forward one bar, it won’t produce trades on the last bar. If you use this in real time, the trades will magically appear on the second bar back simply because the information was not available on the first bar to make a decision. Because of this, this Trading Strategy should only be used for backtesting purposes and not used for real time Trading. Obviously, you can get around this by graphing the stop and limit price indicators on the chart and placing the stop and limit orders yourself.

Was this article helpful?

Related Articles