For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Need help with this risk management strategy. Can it be done with the current features? (closing out half of a position, updating stop loss, trailing stop with dynamic value, etc.)



  • I am trying to set up this risk management strategy and not sure how much is reasonable with the current feature set. I could use some advice and suggestions. And if not, other alternative ideas or changes to the strategy are much appreciated!


    Let's say I want to take a long with this setup:

    Take profit 2
    Take profit 1
    Buy stop entry
    Stop loss (after TP1 is hit, move this up to breakeven, then trail it while reaching for TP2)


    We enter with a buy stop also set with a stop loss and take profit. (I'm assuming this best way to do this is with a bracket order?)

    self.buy_bracket(exectype=bt.Order.Limit,
      limitprice=TP1,
      price=buystop,
      stopprice=stoploss,
    )
    

    After TP1 is hit, close 50% of the position. (Is there a way to close out only half of the position? It seems like it might be easier/better to just open 2 positions at once, one for TP1 and another for TP2?)

    Move the stop loss up to the entry price to breakeven, begin trailing it now. (It doesn't seem like I can update a stop loss?)

    Using the other 50% left in the trade, try to hit TP2 as well.


    Is this reasonable or should I just keep it simple and just trying to set it all up at the beginning with 2 orders, even though it's not exactly what I want? Like this:

    self.buy_bracket(exectype=bt.Order.Limit,
      limitprice=TP1,
      price=buystop,
      stopprice=stoploss,
      size=0.5,
    )
    
    self.buy_bracket(exectype=bt.Order.Limit,
      limitprice=TP2,
      price=buystop,
      stopprice=stoploss, # can this initial value also be set with the trail?
      size=0.5,
    
      stopexec=bt.Order.StopTrail,
      trailamount=3*0.001, # trailamount or trailpercent but not both
      trailpercent=7,
    )
    

    (If using a trailing stop, can I set the initial stop loss too or only the trailamount or trailpercent? Also, is it possible to make it dynamically change more specifically than a fixed amount or percent e.g. trail the stop loss at # pips below last # candles low? If I can't do that, guess I should just start it off with 2*ATR?)

    Thanks!



  • @booboothefool

    Let's say I want to take a long with this setup:
    Take profit 2
    Take profit 1
    Buy stop entry
    Stop loss (after TP1 is hit, move this up to breakeven, then trail it while reaching for TP2)

    We enter with a buy stop also set with a stop loss and take profit. (I'm assuming this best way to do this is with a bracket order?)

    Bracket orders are good for simple cases where you send orders and wait for their execution. You want to make much more work with the orders, so I would better do separate order management.

    After TP1 is hit, close 50% of the position. (Is there a way to close out only half of the position? It seems like it might be easier/better to just open 2 positions at once, one for TP1 and another for TP2?)

    Issue one order to open full position, than issue two take profit and two stops loss orders for half of the position. If you use bracket orders, than issue two sets bracket orders.

    Move the stop loss up to the entry price to breakeven, begin trailing it now. (It doesn't seem like I can update a stop loss?)

    It seems that we have this undocumented feature. Check out here https://community.backtrader.com/post/11405

    Using the other 50% left in the trade, try to hit TP2 as well.

    Is this reasonable or should I just keep it simple and just trying to set it all up at the beginning with 2 orders, even though it's not exactly what I want?

    Nobody prevents you from writing your own order management and have what you want if built-in tools are not suitable.

    (If using a trailing stop, can I set the initial stop loss too or only the trailamount or trailpercent?

    Only the trailamount or trailpercent according to the documentation.

    Also, is it possible to make it dynamically change more specifically than a fixed amount or percent e.g. trail the stop loss at # pips below last # candles low? If I can't do that, guess I should just start it off with 2*ATR?)

    Possible. Write your own order management script which will change stop/take prices as you want. Based on that undocumented feature above you may not even need to cancel and issue orders on every bar.



  • @ab_trader Wow, thanks! That stop update without cancel opens up a whole new world of possibilities. But as someone else mentioned, does it work on a live broker? Would the broker get the call to move the stop?



  • @booboothefool said in Need help with this risk management strategy. Can it be done with the current features? (closing out half of a position, updating stop loss, trailing stop with dynamic value, etc.):

    But as someone else mentioned, does it work on a live broker? Would the broker get the call to move the stop?

    I believe the best way to answer this question is to open demo account with your broker and run simple script which employs this feature. If it will work than good, if not than better to start with the order cancel/re-issue concept.


Log in to reply
 

});