@blonc said in Strategy Selection Pattern:
The concept I am trying to achieve is to have many strategies all being monitored by a master strategy. This way, the master strategy could be using a markov chain to monitor returns to turn on and off individual strategies based on the total returns of all strategies. It seems the best path is to , correct me if wrong, put the strategies logic into indicators and bring them into one master strategy.
@backtrader said in Strategy Selection Pattern:
Sub-strategies is not a pattern which does exist in backtrader. Using Indicator instances could do the trick.
Was also thinking about utilizing the concept of having a "master" strategy turning on and off "micro strategies", so I'm glad I found this post :)
I can think of a lot of use cases for using a master strategy that based on a wide overview of a market/s can control what micro strategies are suited to be used.
the idea of using indicators as sub-strategies seem brilliant (haven't tested it yet).
but from my understanding strategies can be better analyzed and give valuable insights. I hope we can wider the discussion just to explore more solutions (as @backtrader mentioned nested strategies are not supported)
one idea I have that I don't think break backtrader structure is:
declaring a 'master' that run first and based on whatever user logic it creates a 'signal dictionary' that is then passed to all other micro strategies. allowing them to decide if to run or not in next().
this way all strategies are kept in the same level of operation (not nested)
@mothee said in Why the datetime is set to the end of day for minute period bars in the csv data feed?:
it need set 'timeframe = bt.TimeFrame.Minutes' explicitly.
If you don't tell the platform what your data feed is, it cannot know it.
@algoguy235 said in Detect new resampled price:
I wasn't able to get len() as a line object in the init function
len is a builtin and cannot be overridden. Given it is only meant to check a single value (because it increase monotonically) it seems pointless to have a replacement function for it to deliver a lines object.
The logic cannot be elsewhere but next, because it is what will be called on a regular basis.
The difference between creating and operating with indicators is explained here: Docs - Platform Concepts - Stage 1 and Stage 2
You may also look at the lifecycle of the Strategy: Docs - Strategy
@peterzcc said in Any updated guide on custom live data and live trading?:
Is there any updated guide on that, thanks!
Updated with regards to?
There is no specific guide that I know of. Things you may have a look at:
Community - Store Development
Community - IG Store Development
Community - How to create live data feed?
Docs - Binary Datafeed Development
As for the broker, have a look at the sources.
@tw00000 said in Datetime format internally?:
Using: [bt.utils.date.num2date(date) for date in self.datas.datetime.get(size=150)]
In place of: self.datas.datetime.get(size=150)
This is partially correct. If you are working with timezones, that will only give you UTC time. The correct form would be:
current_datetime = self.data.num2date()
For those 150 objects
those_150_datetimes = [self.data.numdate(x) for x in self.data.datetime.get(size=150)]
@toolkmit said in Execution of Limit Orders:
I believe the default behavior is to execute the limit order when price reaches 2700, which rarely happens in live trading.
backtrader is not about what rarely happens. It tries to model reality. Actually if you have a Limit order to sell at 2700, you are NOT going to be matched at 2700.25 because that would actually go AGAINST what you have specified as limit. Your broker would be breaching the contract it has with you not to executed your order at any price higher than 2700.
You ar probably looking at these options:
Adding slippage: Docs - Slippage
Using StopLimit (i.e.: only having a Limit order active if a trigger price has been reached).
You may also be looking for an order type which is not implemented in backtrader: Limit If Touched. When the price touches 2700 you will be looking to have a Limit order placed at 2700.25