@daniel-cunha Add your 1-k indicators to your asset in pandas before loading, then load your close + k indicators together as one data feed. You will then have a data line for each asset that has the 1-k indicators in the same line.
Based on one old comment from the 'bt' author (search forum for 'lineplotterindicator') 'lineplotterindicator' was made to quickly show a line. So you may need to make an indicator from 'self.inds['signal1']' to be able to customize it's plotting.
@dasch :facepalm: Thank you so much! It's so obvious now, the only reason it was working before with non-live data was because preload parameter defaults to true with non-liva data. If I manually set preload as false when using GenericCSVData, the same behaviour occurs & the current value of the indicator is alway nan.
Updated my strategy so it now looks at the indicator values in the past, it is working as intended.
Thanks your reply did solve my problem both using the __init_method and using the next metod. Thanks for pointing out the link.
However the next issue I ran into is the limitiation of buying at open and sell att close. As I understand there is no way to check if there is a gap and if there is buy at the same opening price that was used to calculate if there is a gap and then sell at close? Buy default this strategy would check for a gap at day 0 and then execute the order at day 1?
Is this correct and is it possible sidestep this and implement a strategy that buy at the current open in backtrader?
An Order instance (let's call it order) carries an attribute data which is the asset on which the order has been issued. The ticker name should be available as: order.data._name (where _name is the name you have assigned when using adddata)
Names are actually a late addition to backtrader, because one of the underlying design concepts is that the development of a trading idea should, ideally, not be bound to a specific asset.
A signal / indicator has (like a Strategy) receives an array of the available data feeds in the environment in which they are instantiated (an Indicator can be instantiated inside a Strategy or inside another Indicator)
If your Strategy has 4 data feeds, the indicator will default to receiving 4 data feeds, which will be available in the iterable self.datas and as self.data0, ..., self.data3. Most indicators actually only use 1 data feed. One can actually declare that a given indicator must receive more than 1 data feed.
The outer SMA receives the inner SMA as data feed. And this data feed carries no name, even if it's calculating the simple moving average of self.data1. We still don't know what self.data1 is. It could be an RSI for example. See:
MyInd2 passes 2 data feeds, one is the main data feed received (which can be anythin) and the 2nd is the RSI. As such MyInd1 receives an RSI instance as self.data1, but it doesn't know it. It simply does an SMA on it and then a 2nd SMA
If your signal is going to be name-bound, it will be limited to real data feeds which carry a _name attribute and will fail to be generic for any kind of actual data feed, like in the examples above.
lines = ('name_bound',)
if self.data0._name == 'my-preferred-name':
self.lines.name_bound = bt.ind.SMA(self.data3)
self.lines.name_bound = bt.ind.SMA(self.data2)
At least data0 must be a real data feed with a name in that example.