Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Have the slowStoch indicator contain 1 or 2 output?

    Indicators/Strategies/Analyzers
    2
    2
    98
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Nguyễn Sơn
      Nguyễn Sơn last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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 naming

        • Docs - ta-lib - STOCH - https://www.backtrader.com/docu/talibindautoref/#stoch

        You 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 here

        • Docs - ta-lib integration - https://www.backtrader.com/blog/posts/2016-07-26-talib-integration/talib-integration/

        As 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)

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }