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/

    Execution price is always 0

    General Code/Help
    3
    4
    498
    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
      storm_chaser last edited by

      Hi all!
      I am new to backtrader and am struggling writing my first algo. Basically:

      • I feed the algo a simple line of close prices from a generic CSV (the csv only contains 2 columns: datetime and close price)
      • I only place one buy order, (when the price first goes up compared to the previous week)
      • I print what happens to the price, the order and the portfolio value

      The problem is that no matter what price I call self.buy() with, the execution price is always 0. I wrote price=10 in the following pictures but writing self.dataclose[0] does not work either.

      0_1532081455068_data.png

      2_1532081455070_strat.png
      1_1532081455070_results.png !

      1 Reply Last reply Reply Quote 0
      • S
        storm_chaser last edited by

        Figured something out:

        • the price argument only matters for limit orders
        • data must contain an open price on the next tick, because the trade will be executed at this open price.

        Next question: is there any way to trade at the closing price of the current tick (the "examination" tick)?

        A B 2 Replies Last reply Reply Quote 0
        • A
          ab_trader @storm_chaser last edited by

          @storm_chaser check out cheat on close feature in the docs.

          1 Reply Last reply Reply Quote 2
          • B
            backtrader administrators @storm_chaser last edited by

            @storm_chaser said in Execution price is always 0:

            Figured something out:

            the price argument only matters for limit orders

            Good you figured it out before going live. If you send a Market order using any platform to any broker, it won't matter which price you specify.

            @storm_chaser said in Execution price is always 0:

            data must contain an open price on the next tick, because the trade will be executed at this open price.

            When you issue an order, the current prices DO NO LONGER EXIST. Hence your Market execution will be against the next incoming tick. Just like in the real world.

            If you want to cheat use: cheat-on-close. Docs - Broker

            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(); }); }