Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect handling of trail orders #98

Open
GithubTourist opened this issue Apr 23, 2024 · 0 comments
Open

Incorrect handling of trail orders #98

GithubTourist opened this issue Apr 23, 2024 · 0 comments

Comments

@GithubTourist
Copy link

GithubTourist commented Apr 23, 2024

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:

  • A 10$ trail amount sell order from the current price of 100$ (so the price at which the order should be triggered is 90$)
  • Next OHLC candle is O=100, H=108, L=95, C=105.

What backtrader will do (incorrect way):

  • it will use the closing price of the new OHLC candle to update the trailing order. Since the closing price of 105$ is 5$ higher than the starting price of 100$, the new trigger price for the trailing order will become 90$+5$=95$.

What should be happening instead:

  • backtrader should use the High of the candle of 108$ to update the trailing stop to the new trigger price of 90$+8$=98$.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant