Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Oandav20 separate trail order

    General Code/Help
    2
    2
    46
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J T
      J T last edited by

      Hi

      I like to ask if anyone has experience with creating a single trail order in oanda. I tried the below but got the following error:

      self.long_trailstop = self.sell(price=trail_stop_px, exectype=bt.Order.StopTrail, size=stop_size, trailamount=self.ATR_at_exe * 1.5, id='888')
      but the above does not work.
      

      I got an error which bascially is an error when issuing stoptrail orders without brackets.

      okwargs['type'] = self._ORDEREXECS[order.exectype]
      KeyError: 5
      

      Will some kind souls help me out with this?

      Thanks alot!

      1 Reply Last reply Reply Quote 0
      • D
        dasch last edited by

        See the latest changes in btonadav20. I have added a somehow simulation of a StopTrail, StopLimit and StopTrailLimit order using brackets. Since these orders are not supported by oanda, I used a stop order to enter, when the entry order is filled, the trail stop is attached to the trade. You can replace the trail stop with a new one, too.

        It is using a stop order to enter the market and issues a trailing stop loss order on the stop side. See readme how to use them.
        Also the latest change added a possibility to replace pending orders using the replace param.

        If there are any issues, open a ticket. I have tested it with stop limit orders and it works fine.

        Example of create buy StopTrail order

        o, ostop, olimit = buy_bracket(exectype=bt.Order.Stop, stopexec=bt.Order.StopTrail, stopargs={trailpercent or trailamount},  limitexec=None)
        

        Create new trailing stop for parent order

        self.sell(exectype=bt.Order.StopTrail, replace=ostop.ref, trailamount or trailpercent)
        
        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }