FRENESDE

Cheat-on-close

By default, an order decided in next() executes at the open of the next bar: you decide with the known close and execute later, as in real life.
cerebro.broker.set_coc(True) enables cheat-on-close: the order executes at the close price of the very bar on which it was decided. Handy to simulate an order placed in the closing auction, but dangerous if the decision uses that very close.
A more honest alternative: self.buy(exectype=bt.Order.Close) executes the order at the close of the next bar. The decision is still made with data already known.
There is also cheat-on-open: with bt.Cerebro(cheat_on_open=True), the next_open() method is called before execution, when the bar’s open is already known. It is used, for example, to compute a position size from the opening price.

Examples

Key terms

Cheat-on-close
Execution at the close price of the bar on which the order is decided
set_coc
Broker method that enables cheat-on-close
Look-ahead
Bias that uses information not yet known at decision time
Closing auction
Auction that sets a stock’s closing price
Take the mission on Doji Academy

← Back to the index