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
-
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.
-
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
-
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()
-
Checkout section Parameters of the Docs - Platform Concepts
Docs - Quickstart Guide gives extensive explanation of
bt
features, introduces to parameters use as well.