Algotopian is starting. Let it be the future of backtrader. Check it out! https://www.algotopian.com
For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Cheat on order execution price



  • There're cheat on open / close flag at cerebro / broker level. However, their execution behavior is still not that flexible, plus the interference if both are set to be true.

    Take the documentation example for cheat on open (https://www.backtrader.com/docu/cerebro/cheat-on-open/cheat-on-open.html?highlight=next_open), if cheat_on_open=False, the order get sent on 2005-04-08 and executed at close price 3088.47 on 2005-04-11. if cheat_on_open=True, the order get sent on 2005-04-11, but it still executed at same price. So the cheat on open doesn't have the influence on the execution price, which may be what we wanted depends on the scenario.

    But it can be quite helpful if we want to simulate certain order execution given specific data frequency. For example, I find it hard to implement a simulated strategy which simply buy on open, and sell on close on a daily data.

    So can we have a "complete" cheating order execution, which we can specify the execution price. In the reasonable hand, this could be very helpful and make certain strategy easy to simulate given specific data restriction.


  • administrators

    @aris-l said in Cheat on order execution price and time:

    So the cheat on open doesn't have the influence on the execution price, which may be what we wanted depends on the scenario.

    You cannot influence the price if you send a Market order. The matching logic (in backtrader and in the exchange) will give you what's at hand.

    The major use case about cheat-on-open is, for many people, to be able to calculate stakes accurately with the opening price because they want to go all-in (or near to all-in) and price differences between the previous close and the current open are sometimes the cause for order rejection, because the stake calculated with the previous close price is too large for the current open (and matching) price.

    @aris-l said in Cheat on order execution price and time:

    I find it hard to implement a simulated strategy which simply buy on open, and sell on close on a daily data.

    It's easy.

    Option 1

    • Activate cheat-on-close
    • Issue a sell Market order during next to sell at the closing price
    • Issue then a buy Market (in the same next) and it will buy you the opening price

    Ok, this may not be your logic

    Option 2

    • Activate cheat-on-open and cheat-on-close
    • Issue a buy Market in next_open and it will buy you the opening price
    • Issue a sell Market order during next to sell at the closing price and the position will be closed

Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.