Creating buy order with trailing stop and take profit. All in one
-
Hi, I have searched forum and found few relevant discussions. Specifically I have read
https://community.backtrader.com/topic/163/trailing-stop-loss/3What I want do is following:
- Create a Buy order, let's say at price = 100, trailingstop = 10, takeprofit =20
I see there are new order types like StopTrail, but they are still separate orders?
Is there a way to create one order which has parameters to define buying price, trailiningstop and takeprofit (all in one) ?
If yes, please share code snippet, that would really help.If not, how backtrader ties up a Buy order to another corresponding StopTrail order created for it?
Thanks
-
-
@ab_trader
Hi,Thanks for your answer. It works and allows to specify all in one. However, I noticed, if I am issuing a buy bracket order and skip mentioning the
limitprice parameter, it still submits a limit order with same price as the buy order.I am sure this is the norm, which means if using bracket orders, we will always have 3 orders in action ?
What if I only want to place a buy order with a trailing stop. What's the most elegant way to achieve this in backtrader ?
-
@sunnyalgotrader
from the first look into docsbt
always issues 3 orders. If it is true, then I would setlimit
price very far from entry price, so the chances to get there are low. But maybe @backtrader can clarify this question and offer better solution. -
Actually version 1.9.61.122 allows the suppression of one of the two brackets.
See: Community - Release 1.9.61.122
Look for the reference in the corresponding methods of the strategy:
buy_bracket
,sell_bracket
. See: Docs - Strategy -
Make sure to use the appropriate stop. In a volatile market, a
StopTrailLimit
vsStopTrail
(Market) can cost you a lot of money.