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/

    Execution price problem with order for multiple stocks

    General Code/Help
    3
    4
    183
    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.
    • I
      innuendo last edited by

      Hi all!
      I am new to backtrader and countering some difficulty about the transaction part. For some reason I don't know, the execution price for the order is always 0 when I try to run a portfolio strategy, though it looks all good when I step back and test a single stock test strategy.

      I printed the open price data supposed to be used, and it seems all right. And I tried both simple buy order and target percent order, both return the same issue.

      Hers is the code and result. It would be much appreciated for you help. Thanks very much!
      Code:
      5ab519cf-9486-431f-bc94-a22a88178db7-image.png
      Result:
      f374ce62-b6fb-4a7c-b3ac-6aeeb7674773-image.png

      1 Reply Last reply Reply Quote 0
      • Олег Шпагин
        Олег Шпагин last edited by

        Hello! )) Please resend your screen shots again.

        B 1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators @Олег Шпагин last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • Олег Шпагин
            Олег Шпагин last edited by

            Hello! I am using the same construction, and all seems OK:

                        self.log(ticker + f": >>> BUY ORDER '{order.info.level_name}' COMPLETED at {order.executed.price:.{globals.f_decimal[ticker]}f} price, "
                                          f"size = {order.size}, Cost={order.executed.value:.2f}, Comm={order.executed.comm:.2f}, "
                                          f"DEPO={self.cerebro.broker.getcash():.2f}, Was Created={order.info.created_date}")
                        self.log_for_csv(ticker=ticker, level_name=order.info.level_name, order='BUY',
                                         order_price=f"{order.executed.price:.{globals.f_decimal[ticker]}f}",
                                         size=order.size, status=order.getstatusname(order.status),
                                         cost=f"{order.executed.value:.2f}",
                                         comm=f"{order.executed.comm:.2f}", amount="?", bar_high=order.data.high[0], bar_low=order.data.low[0])
            

            Have you resolved your problem?

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