Backtrader Community

    • 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/

    Accessing the Open and Close of a Trade

    General Code/Help
    3
    3
    72
    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.
    • Z
      Z last edited by

      Hey, I'm a noob. How do I access the Open Price and Close Price of a trade? For example:

      def notify_trade(self, trade)
           when a new trade is opened (trade.justopened???):
                print(trade open price)
                print(trade close price)
      

      I looked at the Trade section of the documentation, but didn't find any attribute for the Trade Open Price and Trade Close Price, but maybe I'm just blind or something.

      Thanks much!

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

        Trade documentation is here: [Docs - Trade][https://backtrader.com/docu/trade/]

        Member Attributes:

        • ref: unique trade identifier

        • status (int) : one of Created, Open, Closed

        • tradeid: grouping tradeid passed to orders during creation
          The default in orders is 0

        • size (int) : current size of the trade

        • price (float) : current price of the trade

        • value (float) : current value of the trade

        • commission (float) : current accumulated commission

        • pnl (float) : current profit and loss of the trade (gross pnl)

        • pnlcomm (float) : current profit and loss of the trade minus
          commission (net pnl)

        • isclosed (bool) : records if the last update closed (set size to
          null the trade

        • isopen (bool) : records if any update has opened the trade

        • justopened (bool): if the trade was just opened

        • baropen (int): bar in which this trade was opened

        • dtopen (float): float coded datetime in which the trade was
          opened

          • Use method open_datetime to get a Python datetime.datetime
            or use the platform provided num2date method
        • barclose (int) : bar in which this trade was closed

        • dtclose (float) : float coded datetime in which the trade was
          closed

          • Use method close_datetime to get a Python datetime.datetime
            or use the platform provided num2date method
        • barlen (int ) : number of bars this trade was open

        • historyon (bool) : whether history has to be recorded

        • history (list) : holds a list updated with each “update” event
          containing the resulting status and parameters used in the update

        1 Reply Last reply Reply Quote 0
        • Black jonh
          Black jonh last edited by

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