You're right, I did not share any code and I should've.
First, let me explain what is it exactly I desire.
Suppose your data is daily OHLC. My strategy would be simple :
if a certain condition is met on the current bar datas (lets say the performance is greater than a certain value), I decide to do the following operations the following day, whatever may happen :
- Buy at Open price.
- Sell at Close price.
No cheating whatsoever as I make that decision before I get to know the values of datas.
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?
From what I gather he was trying to do the same thing as me, and the code above only activates
cheat-on-close as the orders issued in both
next are executed at close price, making the operation's profit always null.
Now I did try to find a solution and I think I somehow got it to perform what I needed. Here's my code :
cerebro = bt.Cerebro(cheat_on_open=True) cerebro.broker.set_coc(True)
which, and it is worth stating it, surprisingly gives different results than what was proposed previously :
cerebro = bt.Cerebro() cerebro.broker.set_coo(True) cerebro.broker.set_coc(True)
(As I said this seems to only activate
cheat-on-close, "the last one takes priority" as @Traderone3 said.)
Then, I issued my orders as such :
next_openI issue the order to buy at open price with arguments
nextI issue the order to sell at close price with arguments
self.order = self.sell(coo=False, coc=True)
The results I get are somehow what I need, the first order is executed as I wanted at Open price of datas the next bar.
But the second order, even though it is executed at close price of datas, which is what I want, is only notified by
notify_order the following day (datas), which i guess is normal since it was issued in
next. I would have preferred to see it notified the same day, is there perhaps a method
notify_order_close that makes this possible ?
That's my take on the issue, hope I made myself clear enough and this post helps people struggling with the same problem.