Cone8
 ( 4.98% )
- ago
Auto stop and limit orders will fill on entry bars in backtests even when it's clear that the "order of trading" probably (because we cannot know if the entry is a stop or limit order) would not have filled an AutoProfitTargetPrice or AutoStopLossPrice.

Consider this strategy that buys at limit on a dip and sets stop and limit exits on the entry bar.



In the first of 3 example here, the strategy bought the dip, price continued down and we exited at a stop. This scenario is okay.

In the next 2 examples, price opened high, we bought the dip, and then price closed near the bottom of the candle. Nonetheless, the strategy exited at the profit target!

Request
1. For an entry using a limit order, the backtest should only fill a AutoStopLossPrice order beyond the limit entry price. AutoProfitTargetPrice should not be filled.

2. For an entry with a stop order, the backtest should only fill an AutoProfitTargetPrice limit order beyond the stop entry price. AutoStopLossPrice should not be filled.

3. For market order entries, either AutoStop/Limit can be filled since all price action occurs after the open. If both orders could be filled, the stop order should be favored for backtesting.

Note!
In all cases that both a PT and a SL could be filled on the entry bar, the SL (Stop Loss) should be executed for the backtest.
2
1,044
Solved
9 Replies

Reply

Bookmark

Sort
MIH8
- ago
#1
For case 3, one could also bring randomness into play as a simple and statistically good solution (possibly with ratio specification in the backtest), as an alternative to a preference. Another, but complex alternative would be of course to include granular data.

In cases 1 and 2 I cannot understand why price movements after an entry should behave differently? After an entry has occured, how can the order type still be relevant? For me, the behavior after the entry is identical to the market orders, I unfortunately do not understand it yet.
0
Cone8
 ( 4.98% )
- ago
#2
QUOTE:
After an entry has occured, how can the order type still be relevant?
Take the case of the first of the 3 exits on the entry bar in the image above.

The Open was about 383.32 and may have ticked a penny or two higher. Then price dropped and hit the Buy At Limit at about 382.90. Later it hit the stop at abotu 382.49. We know that it hit the stop AFTER the limit entry because both the open of the bar and entry prices were higher than the stop.

On the other hand, assume the limit target was 383.50 and the bar's high was even higher. If price hit both the buy and sell limits, we cannot have known the sequence of those events, so the backtest should not assume a profit.

When there's a choice, we prefer that backtests give a more pessimistic result. Same thing for Case 3.
0
MIH8
- ago
#3
Thanks Cone for taking the time. Can we have a closer look into one example please.

QUOTE:
The Open was about 383.32 and may have ticked a penny or two higher. Then price dropped and hit the Buy At Limit at about 382.90. Later it hit the stop at abotu 382.49. We know that it hit the stop AFTER the limit entry because both the open of the bar and entry prices were higher than the stop.


Yes, you know that the stop was made after the opening and the limit.
We would even be able to tell from the close which price was last crossed.

383.32 open
382,90 limit
382,49 stop

But the price does not move only in one direction.
To illustrate what confuses me is, if we include hi and tp (chosen arbitrarily)

384.00 hi
383.50 tp

Why can't the price go up (even to tp) before it goes down (to sl)?
So, can we see which price was first crossed?

Well, sure, we can end at sl, but there could be a price of 383.4 before that, this puzzles me.
There is no information about how the price moved within a bar. I am still confused, I continue to think about it.
0
Cone8
 ( 4.98% )
- ago
#4
You are correct. The PT could certainly occur before having hit the SL. In live trading, it's not a problem - what will happen, will happen!

In a backtest we cannot be sure of the sequence of two limit prices on the same bar that are above and below the open.

We can guess, but it's just not worth it diving into that minutia. The KISS method (Keep It Simple Stupid) demands giving the backtest a pessimistic result and being pleasantly surprised when a trade like this actually goes in your favor.
0
MIH8
- ago
#5
Following the KISS principle and assuming the pessimistic result is certainly correct.

If we now take into account that the price movements are not known in detail
(everything can happen but we follow the pessimistic approach),
then each order type can in principle behave the same, after the order has been filled.
Is a distinction really necessary?

If not, KISS could be further simplified.

One could consider the three different cases as one, and use the pessimistic approach in all three cases.
Woudn't it even be more consistent in the sense of evaluating the results?
In the end i thought, it is only about the exits and not about the conditions under which the order was filled.
0
Cone8
 ( 4.98% )
- ago
#6
I clarified by adding this note -

Note!
In all cases that both a PT and a SL could be filled on the entry bar, the SL (Stop Loss) should be executed for the backtest.

Cases 1 and 2 identify sequences that we can be relatively confident about. There are more scenarios involving price gaps past the limit or stop orders, but again, it's minutia and special cases that could go one way or the other - so we just pick one.

(Actually, in the case that price opens past both the stop and limit prices may have to be treated differently. Theoretically, you'd buy/sell or short/cover at the same price. Realistically, there would be some difference in the entry and exit.)
0
MIH8
- ago
#7
Thanks.
0
Cone8
 ( 4.98% )
- ago
#8
Smart Same-Bar Exits were Implemented in Build 32 as follows:

In terms of PositionType.Long (opposite case is true for PositionType.Short), same bar exits...

Limit order Entry
- The backtest fills an AutoProfitTargetPrice on the same bar only if the bar's Close is equal to or greater than the AutoProfitTargetPrice.
- If a AutoStopLossPrice is in the entry bar's range it will be filled - even if the "stop loss" price is a better exit than the profit target (which would be a strategy logic error).

Stop order Entry
- The backtest will fill an AutoProfitTargetPrice limit order beyond the stop entry price.
- A same-bar AutoStopLossPrice will be filled only if the bar's Close is below the stop price.
0
Best Answer
MIH8
- ago
#9
https://www.wealth-lab.com/Discussion/AssignAutoStopTargetPrices-explained-8655

The link refers to the topic. Post #11 to #17 give some more context as to why there is a new solution.
0

Reply

Bookmark

Sort