@ed-bartosh ccxt had some unique properties that made it possible to implement the broker straight from BrokerBase and give access to more then 1 exchange simultaneously in a way that feel very integrated and easy to use. remember that ccxt project is all about unifying the variety of exchanges under one api.
and a key part of my development was that the feed had some exchange info inside it.
but to make a more generic broker means to really create a broker that hold a collection of brokers inside (that are not really unified) and switching between them like you proposed before.
The biggest problem this way, is that there are still methods that will get called by Backtrader in the background on the 'active' broker without the intention of the user.
A better solution that may work more like what i wrote is if every feed will hold some broker information in a well known way and then you don't need to guess on what broker.
@gminorcoles I am just a user of the bt, not an owner. Sometimes I share pieces of the code. @backtrader is an owner.
if you want/can offer any enhancements, then just create pull request with that enhancement. @backtrader will check it and incorporate if it will be suitable from his point of view.
@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)
After testing the code above and plotting the divergences that it found, I think that the issue is with this line:
self.hfi = bt.ind.FindFirstIndexHighest(self.data.high, period=self.p.hl_period)
It looks for the highest point (same for the lowest) within the hl_period (100 bars)
Then in the following line it looks again backwards from that point to find the second high
h_iterable = self.data.get(size=self.p.hl_period, ago=-int(self.hfi) - self.p.hl_min)
So basically the code returns signals for very old divergences. If you are on daily chart, you will try to trade on a divergence that is 100 days old.
So the first day after the high point it signals a sell, then for the next 100 days it still signals a sell !
I have amended the first line to look for a high/low point for the last day only.
In this way if the divergence is growing then it's fine you still get a sell signal, but if the divergence is gone then you don't try to keep selling for 100 days.
I'm learn to use backtrader ,and I'm trying to use the Oandatest.py with some problem. errormsg is the same with you.
I want to know how to run oandatest.py succeed, I have oanda account and token. and pip install oandapy.
but I can't run it succeed. please give me a hand. thanks very much.
So I can loop through all my data in the Next..
self.datas is an array and you can loop over it.
How do I plot the portfolio performance? instead of backtrader printing 1000 different charts...
Depends on what you have defined as performance for your portfolio. There is for example a TimeReturn observer which is intended to plot exactly what the name implies.
If you want to plot other performance indicator, you will need to define it as an indicator or observer
The default is to plot the evolution of the cash and the actual portfolio value which should give a quick indication as to where the system is
And only a single chart will be printed per strategy.
Is there an integrated solution to do this in Backtrader?
There are several samples, blog and documentation pages. See for example:
Docs - Benchmarking
Here the performance is defined as the comparison against another asset.
@bernardlin said in How do I set up correct position close logic?:
Hi, would you mind providing me a link on how 'define a CommissionInfo object which converts the profit and loss (and commissions) of the given pair to your base currency' is done
"Discussed" is not the same as developed.