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/

    Attributes position in Strategy - how to set value correctly?

    General Code/Help
    2
    8
    50
    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.
    • D
      dmitry.prokopiev last edited by

      I made my class broker, orders are sent and executed - ok.
      But, how to set the value of attributes position correctly?
      i see several methods:

      1. using notify_trade, and thus set the value attributes position
      2. using self.data[0], and thus set the value attributes position

      But how do it right in the broker class?

      D run-out 2 Replies Last reply Reply Quote 0
      • D
        dmitry.prokopiev @dmitry.prokopiev last edited by

        Addition, notify_trade sending only after call order.execute method. Its correctly.

        How correctly setting self.position (upopened, size ... etc)?
        I'm still :) looking in source ...

        1 Reply Last reply Reply Quote 0
        • run-out
          run-out @dmitry.prokopiev last edited by

          @dmitry-prokopiev said in Attributes position in Strategy - how to set value correctly?:

          how to set the value of attributes position correctly

          Having a hard time understanding your question. Could you clarify what you are trying to accomplish with value of attributes position?

          Thanks.

          D 1 Reply Last reply Reply Quote 0
          • D
            dmitry.prokopiev @run-out last edited by

            @run-out thnx the answer :)

            In documentation for the Strategy class, section Member Attributes has:

            ....
            position: actually a property which gives the current position for data0.
            Methods to retrieve all possitions are available (see the reference)

            This attribute, instance of class Position.
            When the broker (class broker) receives an order to open a position, this attribute must be correctly set.

            run-out D 2 Replies Last reply Reply Quote 0
            • run-out
              run-out @dmitry.prokopiev last edited by

              @dmitry-prokopiev said in Attributes position in Strategy - how to set value correctly?:

              position: actually a property

              Position size does not need to be set. It is tracked in the Position class here. You can obtain the current position for a line using:

              getposition(data=None, broker=None)
              Returns the current position for a given data in a given broker.
              If both are None, the main data and the default broker will be used
              A property position is also available

              D 1 Reply Last reply Reply Quote 1
              • D
                dmitry.prokopiev @run-out last edited by

                @run-out How to tracking position - understandable.

                But, if implemented broker class is, how to correctly set position (size, upclosed, upopened)?

                1 Reply Last reply Reply Quote 0
                • D
                  dmitry.prokopiev @dmitry.prokopiev last edited by

                  @run-out in github, i searched and found an example (https://github.com/bartosh/backtrader/blob/ccxt/backtrader/brokers/ccxtbroker.py)

                      def _submit(self, owner, data, exectype, side, amount, price, params):
                          order_type = self.order_types.get(exectype)
                          _order = self.store.create_order(symbol=data.symbol, order_type=order_type, side=side,
                                                           amount=amount, price=price, params=params)
                          order = CCXTOrder(owner, data, amount, _order)
                          self.notify(order)
                          return order
                  

                  Why is the order being re-created?

                  D 1 Reply Last reply Reply Quote 1
                  • D
                    dmitry.prokopiev @dmitry.prokopiev last edited by

                    @run-out thnx, I understand

                    i misunderstood the order creation and interaction with a broker class

                    1 Reply Last reply Reply Quote 1
                    • 1 / 1
                    • First post
                      Last post
                    Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
                    $(document).ready(function () { app.coldLoad(); }); }