For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

OANDA Data - Generating OHLC candles that incorporate bid/ask



  • Hello

    I'm interested in developing a strategy that is correctly penalized by the spread as that is how OANDA incorporates its commission. Of course the spread is dynamic so making a static assumption about the spread size isn't particularly accurate.

    OANDA does allow you to request bid & ask data when making a history request and provides the data in OHLC format (e.g. for the close you get both a bid and ask price). However, as far as I can tell backtrader uses either the bid or the ask price in the data set meaning the one not used gets dropped and for testing purposes the spread is effectively lost.

    Is there anyway to construct the OHLC candles incorporating both the bid and the ask price as separate values?

    It appears I might be able to work around this by replacing the hierarchy as outlined in the escape from ohlc land post but that has the downside of losing access to some of the pre-built indicators.

    I'm new to backtrader and am guessing I could rebuild any indicators I might need, but I figured I'd ask if there's native functionality so I can avoid that extra effort.


  • administrators

    @swibby said in OANDA Data - Generating OHLC candles that incorporate bid/ask:

    Is there anyway to construct the OHLC candles incorporating both the bid and the ask price as separate values?

    All data feeds (which are part of the hierarchy of objects known as Lines) can be extended. See for example:

    That means you can add the Bid/Ask information to the data feed. To do that, you would of course need to extend or override the Oanda elements to pull the current Bid / Ask data.

    If you were thinking about resampling the incoming data, the resampler wouldn't know what to do with Bid/Ask prices, so resampling is possibly out of the question.

    The broker wouldn't also use those prices for execution.

    @swibby said in OANDA Data - Generating OHLC candles that incorporate bid/ask:

    It appears I might be able to work around this by replacing the hierarchy as outlined in the escape from ohlc land post but that has the downside of losing access to some of the pre-built indicators.

    This was meant for people who already have the Bid/Ask data and want to make OHLC bars out of it and not play with the spread which is your case.



  • Thanks, I'll take a shot at extending the datafeed