backtrader2 / backtrader

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

Incorrect handling of trail orders #98

Open GithubTourist opened 2 months ago

GithubTourist commented 2 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)