Have the slowStoch indicator contain 1 or 2 output?
-
Hi,
I tend to use the stochasticK and stochasticD by using function integrated with TA lib. On TA lib side, talib.STOCH contain 2 output, I also have read the doc but is seem to be wrong when implemented
print(bt.talib.STOCH.__doc__) >STOCH([input_arrays], [fastk_period=5], [slowk_period=3], [slowk_matype=0], [slowd_period=3], [slowd_matype=0]) >Stochastic (Momentum Indicators) >Inputs: > prices: ['high', 'low', 'close'] >Parameters: > fastk_period: 5 > slowk_period: 3 > slowk_matype: 0 > slowd_period: 3 > slowd_matype: 0 >Outputs: > slowk > slowd
then I use
self.stoch, self.stoch1 = bt.talib.STOCH(self.data.high, self.data.low, self.data.close) >>ValueError: not enough values to unpack (expected 2, got 0)
Pls, help!
-
Indicators in backtrader have lines which are the output and are not calculated on the spot as your execution suggests.
All
ta-lib
indicators when integrated in backtrader behave as the regular indicators of backtrader. They won't work isolated (which seems to be how you use them)See the actual auto-generated
STOCH
indicator here and the lines namingYou have to use it like any other indicator in backtrader by referencing the lines and the actual index
[x]
you want to address (or by using arithmetic/logic operations on the lines)- Docs - Indicator Usage - https://www.backtrader.com/docu/induse/
- Docs - Platform Concepts - Lines - https://www.backtrader.com/docu/concepts/#lines
You may also have a look at the
ta-lib
comparison post hereAs shown the values are exactly the same (actually backtrader is more accurate or de-facto-compliant in some cases, where
ta-lib
fails to define an initial seed for exponentially smoothed based indicators)