Thanks @backtrader. Yes that is an option to do it but I just wish it was more flexible.
I guess I will have to live with it.
Posts made by FaiqS
Multiple Datafeeds and multiple Timeframes
I am running backtests with multiple feeds (multiple stocks all USA market). So am following recommended approach: sudo code
for stock in stockiist: data = load corresponding csv file into Pandas dataframe cerebro.adddata(data)
Then in next func of strategy:
for stock in self.datas: do whatever
And that is working well for me. However, now I need to use Fibonnaci pivot point indicator which requires monthly data. According to this documentation
I will need to add resampled line after adding the data, something like this
for stock in stockiist: data = load corresponding csv file into Pandas dataframe cerebro.adddata(data) #Daily sampled data cerebro.resampledata(data,bt.TimeFrame.Months)
My understanding is that now self.datas will have the following:
"stock1 daily line, stock1 monthly line, stock2 daily line, stock2 monthly line, ..etc
Which is not convenient to iterate through in next function of strategy.
I wonder if there is a way to have monthly data added to another feed (other than self.datas) so in next function will have daily data fetched from self.datas and monthly data fetched from this additional feed.
The documentation here
"backtrader has built-in support for resampling by passing the original data through a filter object. Although there are several ways to achieve this, a straightforward interface exists to achieve this"
The straightforward it is referring to is to add "cerebro.adddata(data)" but nothing is said about other approaches. Would appreciate if anybody has done this and can provide help
Clarification about bracket orders
Looking at the bracket order implementation in backtrader, I think something is missing.
When I do bracket order with broker (long for example), I have the option to specify buy limit. For example, if close price is $50, I want to buy at $51 but not to exceed $52 and then stop loss is $45 and Take Profit is $60.
I see that stop loss is implemented as sell stop and take a profit is implemented as sell limit which is exactly what broker offer. However, I don't see the limit for buy entry. The reason behind this limit is, I want to catch momentum when equity is going up but if it gaps or goes to high, it is not worth buying it anymore.
Can somebody help me explain how to do this in backtrader if possible?
Indicator for multiple data feeds
I have read documentation and went over the issues that people had regarding this but still can't find an answer to my question so I am hoping someone can help me out here.
Basically I have strategy that uses multiple data feeds (each feed is for specific equity) and I am creating own indicator.
My understanding is, the output lines of the indicator will be array of lines (Line for each feed or equity). Is my understanding correct?
If so, how do I define lines array inside the indicator? all I am seeing is
lines = ('metric1','metric'2)
If I have multiple feeds then I should have an array of metric1 and metric 2 for each feed, correct?
Size of the array will be the number of the equities I am feeding to my strategy. That number will be known in my strategy and should be passed to indicator at instantiation. ?
Can you somebody help?