How to get data stream notifier from inside indicator
-
Hi there,
Thanks for the great platform!
A fairly straightforward question:How do I get the data status (
CONNECTED
,DELAYED
,LIVE
etc.) inside myIndicator
?Inside a
strategy
I can usedef notify_data(self, data, status, *args, **kwargs): logger.info(self.asset_name+" DATA STREAM NOTIFIER = {}".format(data._getstatusname(status))) if status == data.LIVE: self.counttostop = self.p.stopafter self.datastatus = 1
But I'm not sure how I can translate this to inside the
indicator
.Thanks!
Josh -
Indicators do not receive notifications. They are meant to be calculators.
But nothing prevents you from passing any information to an indicator, via a member attribute or invoking a user defined method.
-
Thanks for the response, and good to know.
I managed to solve my issue by doing
try: status = (self.datas[0]._getstatusname(self.datas[0]._laststatus)) except AttributeError: # Means we backtesting status = None
within the
next
of myindicator
.Cheers,
Josh -
Although that code seems sane, it doesn't make any sense when the data feed for the indicator is not a data feed which provides notifications.
A classical example is an
SMA
of anotherSMA
. It would therefore seems more logical and reasonable to pass the information using a method.But each master ... has his own way
-
Aha, yes I see your point. Well, for now this will work :)
Thanks for pointing it out!
Josh