ATR and ADX indicators
-
Hi,
Does backtrader have ADX & ATR indicators within? Or need to use TA-Lib?
Thanks -
ADX and ATR are in the
backtrader
.
docs - indicators ref -
Just as a side note: the
116
in the version number is the total of built-in indicators.The
TA-Lib
indicators are not included in that number, because it's an add-on which people may choose to use (or not) -
Thanks,
Now, how would reference plusDI and Minus DI?
say I want a strategy ; when plusDI is > MinusDI and plusDI>20; Buy
how would i write this in backtrader, please? -
plusDI
andminusDI
are lines of theDirectionalIndicator
(probably the one meant instead of theADX
which is theAverageDirectionalMovementIndex
)There is a family of those indicators and which lines are provided by which is documented.
-
Just look for
AverageDirectionalMovementIndex
How to access the lines of any object containing them is documented here:
Strategies that buy when going over a value and sell when going below another are usually documente with a moving average cross over or a moving average compared with the close price:
And with signals:
In summary
if self.mydi.lines.plusDi > self.mydi.lines.minusDI and ...: self.buy()
-
-
Thanks for the help,
I am also not clear about the difference between bt.indicators.ATR(self.data[0], period=14) and bt.indicators.ATR(self.data,period=14). -
@mahbubk9 said in ATR and ADX indicators:
bt.indicators.ATR(self.data[0], period=14)
That's not a valid construct.
self.data[0]
gives you access to the current data point ofdata
(which is an alias todata0
) and at that point in time may break (will work with preloaded data, but will not work in many other circumstances)bt.indicators.ATR(self.data,period=14)
That builds an
ATR
instance usingself.data
(akaself.data[0] aka
self.datas[0]`) -
Thanks,
Another question, how is the latest bar/tick referenced; self.data[0].close or self.data[-1].close, is it not using python type indexing like first item of a series= series[0], last item=series[-1]?
basically i need latest bar>previous bar> previous bar -
That's all in the link above: Docs - Platform Concepts
There is a section about indexing and how
0
is the current point in time. Last is the last produced value before the current point in time and addressable with-1