-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
-
I'm struggling with what might be an obvious thing to many.
If I have multiple trades (long only) and now I want to enter a sell limit for all of them to close them out at a specified price. (Basically I'm looking to set a self.position.close(limit=XXX)
, but close doesn't offer the limit feature. However, if I enter a self.sell(size=self.position.size, limit = XXX)
I'm not sure I'm getting the desired result.
Is there a simple way to do this or do I need to loop through all the open trades and set the tp
= XXX?
Beta Was this translation helpful? Give feedback.
All reactions
However, if I enter a
self.sell(size=self.position.size, limit = XXX)
I'm not sure I'm getting the desired result.
As long as assert self.position.size > 0
, self.sell()
like this looks reasonable. What result do you get?
Replies: 4 comments
-
However, if I enter a
self.sell(size=self.position.size, limit = XXX)
I'm not sure I'm getting the desired result.
As long as assert self.position.size > 0
, self.sell()
like this looks reasonable. What result do you get?
Beta Was this translation helpful? Give feedback.
All reactions
-
Okay then I think it has something to do with my logic because it is popping an AssertionError. Perhaps I'm placing an order in the same bar that I'm calculating the position size (which doesn't account for that order), and it is putting me into a short position. I'll debug and come back with answers or questions. :) Thanks for the quick response.
Beta Was this translation helpful? Give feedback.
All reactions
-
looping back on this. I had some take profits and stop losses in my opening trades, this was causing the problem because that created multiple sell orders sitting waiting in the order book. The sell(limit) wasn't contingent on anything so it wouldn't get canceled if a tp was hit. then I would have a short order sitting in the order book.
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1
-
So how did you end up solving this? I have a similar use case where I have both a tp and sl that are dynamic and are of different size, so I cant use the build in tp and sl arguments. Anyway to force the sell orders to be contingent?
Beta Was this translation helpful? Give feedback.