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/

    Proper way to pass args to next() method

    General Code/Help
    2
    4
    1627
    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.
    • Андрей Музыкин
      Андрей Музыкин last edited by Андрей Музыкин

      Hello!

      I want following procedure inside next() method to be executed:

      def next():
          compute some indicators and other <statistic>
           ......
          connect remote server via <socket>,  send <statistic>
          wait for remote to respond with <signal>
          execute by/sell/hold, based on received <signal> 
      

      The question is: how to pass <socket> details , which will be available right before I call cerebro.run()?
      Generally, question is about passing to .next() any arguments, dynamically computed for the specific run()

      Андрей Музыкин 1 Reply Last reply Reply Quote 0
      • Андрей Музыкин
        Андрей Музыкин @Андрей Музыкин last edited by Андрей Музыкин

        UPD:

        Seems the easy way is to reinstantiate bt.Cerebro() before each run and pass everything as parameters:

        class TestStrategy(bt.Strategy):
           params = (('socket', None),) 
        ...
        
         <Loop over multiple strategy runs>: 
           <check RemoteServer, get updated socket details>
           cerebro = bt.Cerebro()
           cerebro.addstrategy(TestStrategy, socket=<FreshSocket>)
           < add data, etc.>
           cerbro.run()
        
        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators last edited by

          You were faster that the coming answer. params (for parameters) is the standard way to pass things that will get to the strategy and that you can later address as self.params.myparam or with the shorthand self.p.myparam

          There is no need for that indentation. See at the top of the page. Use 2 lines with 3-backticks marks to enclose the code block.

          Or go directly (also at the top) to: http://commonmark.org/help/

          Андрей Музыкин 1 Reply Last reply Reply Quote 0
          • Андрей Музыкин
            Андрей Музыкин @backtrader last edited by

            Yup, pure "read manual first" case. Fixed.

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