-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
-
When processing a new bar, how does Backtesting decide which price from High/Low comes first?
TradingView's Strategy Tester uses the closest price to the Open price to decide which one comes first. Strategies that use small triggers (small TP/SL), can cause significant inaccuracies in the results.
To illustrate the issue, let's say that my strategy has a Long position with a Stoploss at 10$
and a Takeprofit at 20$
. A new bar comes, with an Open price of 15$
, a High price of 25$
, and a Low price of 5$
. The High price triggers the TP, and the Low price triggers the SL. So depending on which tick comes first, it can change the result.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments
-
Just come by issue #119. I believe the comment made by @rokups makes things closer to reality.
This issue popup when Entry, SL, or TP are close enough to trigger on the same bar - and which happens more often using high time frames.
To add on these two comments:
- If trade entry and take-profit prices are within wicks - close trade in-profit.
- If trade entry and take-profit are within same candle - close trade in-profit only when candle matches trade direction (green candle for longs, red candle for shorts).
I would go for a more pessimistic approach and assume that:
- If there is Entry and TP on the same bar: hit the Entry last and don't hit TP.
- If there is Entry and SL on the same bar: hit the Entry and then the SL.
- If there is Entry, TP, and SL on the same bar: hit the Entry and then the SL.
- If there is TP and SL on the same bar: hit the SL
Beta Was this translation helpful? Give feedback.
All reactions
-
question SL/TP hit on the same bar as trade opened refers to the same problem
Beta Was this translation helpful? Give feedback.
All reactions
-
To illustrate the issue
Do you have code that triggers the issue?
See #119 (comment).
But in other regards, the framework's policy is already pessimistic, i.e. SL-first:
backtesting.py/backtesting/backtesting.py
Lines 1000 to 1011 in 0ce24d8
Beta Was this translation helpful? Give feedback.