backtrader2 / backtrader

Python Backtesting library for trading strategies
https://www.backtrader.com
GNU General Public License v3.0
238 stars 54 forks source link

Incorrect handling of trail orders #98

Open GithubTourist opened 7 months ago

GithubTourist commented 7 months ago

Currently, backtrader is only using the closing price to update trailing stops even when OHLC data is provided. The correct way is to use High or Low depending if the order is a Sell or a Buy.

For example, consider the following scenario for a stop sell trail order:

What backtrader will do (incorrect way):

What should be happening instead:

(same idea for the trailing buys, but the Low of the candle should be used)