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.
-
@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 previousclose
and the currentopen
are sometimes the cause for order rejection, because the stake calculated with the previousclose
price is too large for the currentopen
(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 duringnext
to sell at the closing price - Issue then a buy
Market
(in the samenext
) and it will buy you the opening price
Ok, this may not be your logic
Option 2
- Activate
cheat-on-open
andcheat-on-close
- Issue a buy
Market
innext_open
and it will buy you the opening price - Issue a sell
Market
order duringnext
to sell at the closing price and the position will be closed
- Activate
-
I have activated coo and coc as you described.
cerebro.broker.set_coo(True) cerebro.broker.set_coc(True)
the problem is that both of them wont work together. The last one takes priority. How do you properly do it?