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



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



  • 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)?



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


  • administrators

    @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