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/

    which ticker opened/closed in notify_order

    General Code/Help
    3
    11
    2057
    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.
    • A
      Alon Horesh last edited by

      How can I tell which ticker symbol was opened or closed when notify_order is called?

      1 Reply Last reply Reply Quote 0
      • P
        Paska Houso last edited by

        notify_order receives an order. And this contains several attributes including data

        • https://www.backtrader.com/docu/order.html
        1 Reply Last reply Reply Quote 0
        • A
          Alon Horesh last edited by

          but data attribute does not include the ticker, or am I missing something?
          what is the data attribute for the ticker symbol?

          1 Reply Last reply Reply Quote 0
          • P
            Paska Houso last edited by

            That depends on the data source and what you have done (which we don't know). Data feeds have for example an parameter dataname which is the parameter you use to create them. And they can also be assigned a name in cerebro.adddata which is later available as _name

            • https://www.backtrader.com/docu/cerebro.html
            • https://www.backtrader.com/docu/datafeed.html

            But at the end of the day it's up to you and your data feed.

            1 Reply Last reply Reply Quote 0
            • A
              Alon Horesh last edited by

              I added the data source with
              data = bt.feeds.QuandlCSV(dataname="+ticker[0]+".csv",...)
              but when calling print(order.data._name) I get the name of the ticker for datas[0] every time, regardless of the order sent to the print command, BTW all other parameters are displayed OK, only the _name is the same.
              it should be basic and intuitive to get the ticker symbol.

              1 Reply Last reply Reply Quote 0
              • P
                Paska Houso last edited by

                Although your explanation for sure makes sense for you, it doesn't make any sense here.

                @Alon-Horesh said in which ticker opened/closed in notify_order:

                I added the data source with
                data = bt.feeds.QuandlCSV(dataname="+ticker[0]+".csv",...)

                You didn't add anything. You created it.

                @Paska-Houso said in which ticker opened/closed in notify_order:

                And they can also be assigned a name in cerebro.adddata which is later available as _name

                From my own comment above, it should be clear that _name is only available when provided with cerebro.adddata. See the linked doc for cerebro

                it should be basic and intuitive to get the ticker symbol.

                Subclass, add your own field ticker and get it. There is no code and not much can be said. You can read the linked docs and then work it out. Or you can further complain.

                1 Reply Last reply Reply Quote -1
                • A
                  Alon Horesh last edited by

                  the data was added using cerebro.adddata
                  for ticker in tickers:
                  # Create a Data Feed
                  data = bt.feeds.QuandlCSV(
                  dataname='ticker[0]+'.csv',
                  fromdate=datetime.datetime(2013, 1, 1),
                  todate=datetime.datetime(2016, 12, 29),
                  adjclose=False, reverse=True)
                  # Add the Data Feed to Cerebro
                  cerebro.adddata(data)

                  1 Reply Last reply Reply Quote 0
                  • A
                    Alon Horesh last edited by

                    here is the entire code sample:
                    # Create a cerebro entity
                    cerebro = bt.Cerebro()

                    # load symbol list from file
                    with open('list.txt', 'r') as f:
                        reader = csv.reader(f)
                        tickers = list(reader)
                    
                    for ticker in tickers:
                        # Create a Data Feed
                        data = bt.feeds.QuandlCSV(
                            dataname=ticker[0]+'.csv',
                            fromdate=datetime.datetime(2013, 1, 1),
                            todate=datetime.datetime(2016, 12, 29),
                            adjclose=False, reverse=True)
                        # Add the Data Feed to Cerebro
                        cerebro.adddata(data)
                    
                    P 1 Reply Last reply Reply Quote 0
                    • P
                      Paska Houso @Alon Horesh last edited by

                      @Alon-Horesh said in which ticker opened/closed in notify_order:

                      cerebro.adddata(data)
                      

                      No name is being assigned when using addata

                      . https://www.backtrader.com/docu/cerebro.html

                      1 Reply Last reply Reply Quote 0
                      • T
                        Trade Prophet last edited by Trade Prophet

                        cerebro.adddata(data,name=ticker[0])

                        1 Reply Last reply Reply Quote 0
                        • T
                          Trade Prophet last edited by

                          the problem is solved on another line:
                          self.buy(data = ticker_data,...)

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