Execute order on bid/ask only
-
Hi, I'm trying to follow along with the Escape from OHLC Land blog post as well as the 'Execute on bid/ask' thread referenced above, but am having some difficulties actually executing an order when my data doesn't contain OHLC lines.
I've successfully created a data source and can see the tick data in my strategy
.next()
method, but attempting to call.buy()
or.sell()
results in errors inbbroker.py
ororder.py
as those classes hard code against.open
and.close
attributes on theLineSeries
class. Presumably I should be able to buy using.ask
, and sell using.bid
?Would someone who is more familiar with the backtrader internal architecture please weigh in on the correct place to override existing functionality to allow a more complete use of bid/ask data than is suggested in 'Escape from OHLC Land'? It looks like I can maybe write my own broker and instantiate
Cerebro
with it instead of with the includedBackBroker
, although the documentation seems to indicate that this is generally unnecessary:Because the broker is instantiated by
Cerebro
and there should be
(mostly) no reason to replace the broker, the params are not controlled
by the user for the instance.Is full
bid/ask
functionality a valid reason to replace the broker? Or should I expect to be able to parameterize the existingBackBroker
implementation somehow to accomplish this?This recent post also suggests that I can put
bid
data in one line,ask
in another, and link the two with acompensation
function. Would this be more in line with the backtrader architecture than creating my own broker?Finally, I suppose I could create OHLC data from the bid/ask and lay that into the same data feed per this blog post, run the strategy logic on the bid/ask data and use the OHLC to execute orders. Is this a sensible approach?
Many thanks in advance for your guidance!
-
@repentsinner said in Execute order on bid/ask only:
Presumably I should be able to buy using .ask, and sell using .bid?
That's nowhere in that post to be found.
But you may want to see this
- Regarding FAQ: if Backtrader is not a bid-ask Platform - what is it then: https://community.backtrader.com/topic/741/regarding-faq-if-backtrader-is-not-a-bid-ask-platform-what-is-is-then/3
-
@Paska-Houso said in Execute order on bid/ask only:
@repentsinner said in Execute order on bid/ask only:
Presumably I should be able to buy using .ask, and sell using .bid?
That's nowhere in that post to be found.
Ah, sorry I guess I should have rephrased: with bid/ask data on a backtesting platform, presumably one would like to continue on to use bid/ask data to execute orders? I thought I was clearly not implying that this is possible out-of-the-box, hence my question. I'm unclear what the purpose was of extending backtrader to allow running a strategy on bid/ask data is if you can't continue on to use the strategy to create orders.
But you may want to see this
- Regarding FAQ: if Backtrader is not a bid-ask Platform - what is it then: https://community.backtrader.com/topic/741/regarding-faq-if-backtrader-is-not-a-bid-ask-platform-what-is-is-then/3
Thanks, I saw your reply in that thread as well as I asked about here:
This recent post also suggests that I can put bid data in one line, ask in another, and link the two with a compensation function. Would this be more in line with the backtrader architecture than creating my own broker?
It sounds like this is your recommended approach from your understanding of the platform, though it still seems like if I create separate data objects for
bid
andask
they'll still be missing OHLC lines, which is the thing that seems to be required for.buy()
and.sell()
to work. I understand the concept of splitting the data, but it doesn't seem like this solves the problem I'm facing?Are there any other perspectives amongst the community here?
Thanks!