Extreme spreads with Oanda - how to manage this?



  • Hi,

    I'm testing with my Oanda practice account and found some huge differences between the current price (1-minute timeframe) and the price on which I could buy/sell. Then I checked the historical spreads on the Oanda website and found that the spread is extremely high every day around 23:00. Actually that was the time when my strategy has lost a lot of money (21:00 local time). Other periods were fine, buy and sell prices were very close to the actual price.

    How can we avoid trading when the spread is so high? Is it possible to get the current spread of an instrument somehow?

    3_1494502268172_Market_order_4.jpg 2_1494502268172_Market_order_3.jpg 1_1494502268172_Market_order_2.jpg 0_1494502268172_Market_order_1.jpg

    Cheers,
    Tamás



  • This is a tricky one, because unless you are monitoring the ticks, you might not see a spike until late in the game.

    A couple of ideas..... May not be perfect.

    1. Move to a higher TF where the spread is less of an issue.
    2. Use the Oandpy library to monitor the bid and ask spread
    3. Close positions before that particular spike zone each day. Also avoid adding new positions.

    I guess since you are on the 1min timeframe, you are not a long term trader so picking your trading times might be the best way to do it.

    A very simple example....

    import datetime
    import backtrader as bt
    
    trading_open = datetime.time(0,0)
    trading_close = datetime.time(8,0)
    
    
    class testStrategy(bt.Strategy):
    
        def __init__(self):
            self.dataclose = self.datas[0].close
    
    
        def next(self):
            self.data_time = self.datas[0].datetime.time()
            if self.data_time > trading_open and self.data_time < trading_close:
                print('I can trade!')
            else:
                print('Trading closed')
    


  • @ThatBlokeDave
    Hi,

    Thanks for the tips. Probably number 2 would be the best. I wonder if it is interesting for @backtrader to include that in one of the future versions. Like to have self.datas[0].current_spread or something like that ;)

    Number 3 is also a good way to go but then I'll need to check the historical spreads for all the instruments and of course I need to sync the timezones.

    Thanks again and cheers,
    Tamás


  • administrators

    @holicst said in Extreme spreads with Oanda - how to manage this?:

    self.datas[0].current_spread

    Something which can be looked into, with a general model being necessary. For example: the 5-seconds real-time bars offered by Interactive Brokers deliver no Bid-Ask information and people can switch them on.



  • Hi @backtrader,

    Is it possible to get bid/ask lines in an Oanda datasource, similarly to what you've described in your "Escape from OHLC land" post? That would also solve the spread problem because that way calculating the spread would be super easy.
    As I can see there is an option ("bidask") that controls what is retrieved from Oanda, so I believe it is already partially implemented.

    Would it be possible to add the bid/ask lines to the data if the timeframe is set to bt.TimeFrame.Ticks?

    Cheers,
    Tamás


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.