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.
@Sajil-Thamban said in I am new to backtrader and want to build a strategy, details below:
can the first signal be a sell signal (say if the first crossover is on the downside)
I the __init__ section include a variable set to None:
self.trades_occured = False
Then include this in the long section to reject the trade if it's the first crossover. The second crossover must be the opposite so this should work.
if not self.position and self.crossover == 1 and self.trades_occured:
Then once the first sell happens change self.trades_occured to True.
if not self.position and self.crossover == -1:
self.trades_occured = True
self.short_sell_order = self.sell_bracket(....
@Giovanni-Caridi said in No trades happened:
I didn't think bad formatting could lead to coding errors
Python is highly space/formatting dependent. Try downloading black formatter. It automatically formats your code and will try to help you if you are off.
@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)