Skip to content
Discussion options

You must be logged in to vote

The usual cause here is that the strategy submits a new sell(limit=...) order on every bar while the long position is still open. If several of those pending sell-limit orders later fill, they can close the long trade and then continue into a short position.

If this is just a take-profit exit for the long entry, the cleanest approach is to attach it to the entry order instead of manually placing a separate sell order:

if not self.position:
    self.buy(tp=limit)

That creates a contingent take-profit order tied to the trade. When the TP is hit, it closes the long trade instead of acting like an independent short-entry idea.

If you really want to manage the limit exit manually, keep a refer…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kernc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants