Cheat on order execution price
Aris L last edited by Aris L
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.
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
Marketorder. The matching logic (in backtrader and in the exchange) will give you what's at hand.
The major use case about
cheat-on-openis, 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
closeand the current
openare sometimes the cause for order rejection, because the stake calculated with the previous
closeprice is too large for the current
open(and matching) price.
I find it hard to implement a simulated strategy which simply buy on open, and sell on close on a daily data.
- Issue a sell
nextto 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
- Issue a buy
next_openand it will buy you the opening price
- Issue a sell
nextto sell at the closing price and the position will be closed
Traderone3 last edited by Traderone3
I have activated coo and coc as you described.
the problem is that both of them wont work together. The last one takes priority. How do you properly do it?