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/

    Setting Open = High = Low = Close

    General Code/Help
    3
    5
    827
    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.
    • C
      cwse last edited by

      Hi,

      My data source has OHLC values, how can I make it so Backtrader only looks at the "Close" column, i.e. Backtrader sets Open = High = Low = Close.

      I am using a Pandas custom data loader, is the following appropriate?

      class CustomBTStockLoader(btfeeds.PandasData):
      
          params = (
                       ('openinterest', None),
                       ('open', 'Close'),
                       ('high', 'Close'),
                       ('low', 'Close'),
                   ) 
          datafields = btfeeds.PandasData.datafields
      

      ... and then later on:

      data = CustomBTStockLoader(dataname=datarange) #allows load additional "Opportunity" column
                  data.plotinfo.plot=False
                  cerebro.adddata(data, name=ticker)
      

      Thank you!

      1 Reply Last reply Reply Quote 0
      • C
        cwse last edited by

        @backtrader the above appears to work as I would expect. Can you please confirm this is a reasonable approach and is indeed setting O = H = L = Close?

        Thanks!

        1 Reply Last reply Reply Quote 0
        • A
          ab_trader last edited by

          Your approach will ruin indicators which use full OHLC values and limit/stop order execution.

          If you want orders to be executed on close than probably better to use cheat-on-close and market orders and original OHLC data.

          So depends on your goals.

          1 Reply Last reply Reply Quote 1
          • C
            cwse last edited by cwse

            hmm..

            Thanks @ab_trader.

            So using the above, when my sell orders complete, they seem to be using the next days close price.

            Does Backtrader use the next day's open when completing a sell on the current day? This shouldn't happen?

            NB: I do NOT have "Cheat on open" configured.

            cheers, CWE

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

              @cwse said in Setting Open = High = Low = Close:

              So using the above, when my sell orders complete, they seem to be using the next days close price.

              Well, your only input is the close price, so it seems reasonable that some close price will be used for the matching.

              @cwse said in Setting Open = High = Low = Close:

              Does Backtrader use the next day's open when completing a sell on the current day?

              No idea what you mean with "next day's open when completing a sell on the current day".

              @cwse said in Setting Open = High = Low = Close:

              This shouldn't happen?

              Why? We still don't know what you do. So it may actually be the intended behavior.

              @ab_trader said in Setting Open = High = Low = Close:

              to use cheat-on-close

              It would seem like if you ignored this advice from @ab_trader

              NB: I do NOT have "Cheat on open" configured.

              Why should this play a role? This functionality gives you the chance to do something before the next bar is officially given to you, but doesn't affect price matching.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }