Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Extreme spreads with Oanda - how to manage this?

    General Code/Help
    3
    5
    2422
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      holicst last edited by

      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

      1 Reply Last reply Reply Quote 0
      • T
        ThatBlokeDave last edited by

        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')
        
        H 1 Reply Last reply Reply Quote 0
        • H
          holicst @ThatBlokeDave last edited by

          @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

          B 1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @holicst last edited by

            @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.

            H 1 Reply Last reply Reply Quote 0
            • H
              holicst @backtrader last edited by

              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

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors