Thanks for the link. I was thinking to create simple strategy in bt which will go thru all of the contracts and return me continuous contract data feed built by my rules.
Since I am using daily bars I am not so concerned about live trading right now. I is beneficial, but not mandatory.
@USMacScientist HI! I am few days new to this.
I have your zig zag called in strategy class like any other indicator in quickstart guide. The chart produced is great! I appreciate you sharing your code. I produce the chart as well which is great.
self.zz = ZigZag(self.data, plotname='ZZ')
I like to humbly ask you how do I access your other lines in this study such as last_pivor_t etc?
I am trying to access the values stored in these lines. Thanks!
I am using this approach since a while now and I have to say that I am quite happy with it:
Makes it possible for me to evaluate OptReturn objects without the need of any further input (like a cerebro object).
@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.
May I suggest as an additional option just zero-padding, symmetrization, or smooth padding out the short data feed to the length of the longest line? Then all the data will start at the same bar. At the end you can simply trim the output to match the actual individual line length if you wish.
@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.
@scottz1 Answering my own question, I found how analyzers can easily access attributes in the strategy. This would allow me to avoid creating a duplicate ATR indicator in the analyzer, but I've run into a problem with this. If I use a buystop order to open a trade, the strategy doesn't know the fill price until notify_order. I therefore use strategy notify_order order.Completede to calculate a stop loss in ATR units and submit a stop loss order. My analyzer needs to know that stop loss measurement, but... Analyzer notify_trade is called before strategy notify_order. What would be a good design for this?
@ab_trader said in IndexError: array index out of range:
In the __init()__ indexing should be done with (), not with  brackets, ref Docs - Lines: DELAYED indexing:
Pointed out some days ago by @ab_trader
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.