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/

    ploting StopLimit, StopTrail observers

    General Discussion
    observers plotting stoplimit stoptrail
    4
    6
    1967
    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.
    • S
      silverbald last edited by

      Hello

      Question: how can I get value of actual limit of bt.Order.StopTrail (and bt.Order.Limit)?

      Goal: I want to plot actual limit of bt.Order.StopTrail (and bt.Order.Limit) - to see on the plot how it is changing during time.

      Details:
      I open bracket orders:

      os=self.buy_bracket(stopexec=bt.Order.Limit, stopprice=stopprice1,
                          limitexec=bt.Order.StopTrail, limitargs=dict(trailpercent=trailpercent1))
      

      and to make plot I use observer:

      class obsSellSLTS(bt.Observer):
          lines = ('StopLoss', 'TrailStop')
          plotinfo = dict(plot=True, subplot=False)
          plotlines = dict(
              StopLoss=dict(color='lime'),
              TrailStop=dict(color='gold')
          )
      
          def next(self):
              if len(self._owner.broker.orders)==3: #checking if bracket order is set
                   if self._owner.broker.orders[1].created.pricelimit is not None:
                       self.lines.StopLoss[0] = self._owner.broker.orders[1].created.pricelimit
                   if self._owner.broker.orders[2].created.pricelimit is not None:
                       self.lines.TrailStop[0] = self._owner.broker.orders[2].created.pricelimit
      

      but looks like ' self._owner.broker.orders[2].created.pricelimit' is not the right data
      So: which data should I use:

      self._owner.broker.orders[2].created.pclose,
      self._owner.broker.orders[2].created.plimit,
      self._owner.broker.orders[2].created.price,
      self._owner.broker.orders[2].created.pricelimit,
      

      or from 'executed'

      self._owner.broker.orders[2].executed.pclose,
      self._owner.broker.orders[2].executed.plimit,
      self._owner.broker.orders[2].executed.price,
      self._owner.broker.orders[2].executed.pricelimit,
      

      or in any other source?

      kind regards
      Pawel

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @silverbald last edited by

        @silverbald said in ploting StopLimit, StopTrail observers:

        I want to plot actual limit of

        @silverbald said in ploting StopLimit, StopTrail observers:

        bt.Order.StopTrail

        This order type has no limit price. The actual order price is tracking the price of the asset. It will actually execute as a Market order when the price is met. The constantly updated price is stored in order.created.price

        1 Reply Last reply Reply Quote 0
        • A
          ab_trader last edited by ab_trader

          can be deleted

          • If my answer helped, hit reputation up arrow at lower right corner of the post.
          • Python Debugging With Pdb
          • New to python and bt - check this out
          1 Reply Last reply Reply Quote 0
          • S
            silverbald last edited by

            Hello

            Thank You to both of you. It helped me a lot.
            Sorry for late response but finally I found reason for issue and together with your suggestion it works well :-)

            thx
            S.

            J 1 Reply Last reply Reply Quote 0
            • J
              jf @silverbald last edited by

              @silverbald I have the same issue, would you mind posting your solution that works? Thanks! J

              B 1 Reply Last reply Reply Quote 0
              • B
                backtrader administrators @jf last edited by

                @jf said in ploting StopLimit, StopTrail observers:

                @silverbald I have the same issue,

                Since the development of the thread seems to indicate that the originally reported issue wasn't the actual issue, ...

                Would you care to let us know which issue are you facing?

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors