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/

    Interactive input strategy

    General Discussion
    4
    4
    877
    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.
    • R
      robomotic last edited by

      Hello there,
      I have just started to learn bt which is awesome.
      I was just reading the documentation and examples, however I cannot find anything relating to using input to control a strategy.
      What I usually do when I deploy a trading bot is to monitor it and if something is going to be wrong make a few adjustments via keyboard commands in real time.
      Is this possible with bt?

      Cheers.

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

        No such thing is implemented. That's a huge use case. For starters some quick questions:

        • Which commands?
        • You are resampling live data to 15 seconds and you spend 31 seconds in the interactive mode, should the strategy skip the 2 15-seconds bars from the resampler? See them later and what happens if any of them generates a signal for trading?

        A possible approach:

        • Create a thread during the initialization of your strategy and use a method of the strategy as the target
        • This method, now running in parallel (as much as allowed by the GIL) can implement keyboard processing
        1 Reply Last reply Reply Quote 0
        • masoud abedi
          masoud abedi last edited by

          is it possible to create a strategy like this one to get the period outside of strategy?

          class secondstrategy(bt.Strategy):
          
            def __init__(self, period):
              self.period = period
              self.rsi = bt.indicators.RSI_SMA(self.data.close, period=self.period)
          
            def next(self):
              if not self.position:
                if self.rsi < 30:
                  self.buy()
          
              else:
                if self.rsi > 70:
                  self.sell()
          
          1 Reply Last reply Reply Quote 0
          • A
            ab_trader last edited by

            Checkout section Parameters of the Docs - Platform Concepts

            Docs - Quickstart Guide gives extensive explanation of bt features, introduces to parameters use as well.

            • If my answer helped, hit reputation up arrow at lower right corner of the post.
            • Python Debugging With Pdb
            • New to python and bt - check this out
            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors