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/

    Stochastic values generated outside 0-100

    Indicators/Strategies/Analyzers
    2
    2
    121
    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.
    • J
      juliev last edited by

      I have run a backtest on backtrader using a stochastic indicator and have recorded the results to a csv file. On further inspection, I have found stochastic values recorded as less than 0 as well as greater than 100. This is contrary to what was expected from this indicator.

      I have used the following code which includes 2 stochastic indicators. The first(self.stochastic) uses the original data and the second stochastic indicator(self.stochastic15) uses the original data that has been resampled.

      I tried using the stochastic indicator from both Backtrader and Talib and in both cases the same issue was found. The commented out sections in the code represents the Backtrader stochastic indicator.

      class TestStrategy(bt.Strategy):
          def __init__(self):
              #self.stochastic = bt.indicators.StochasticSlow(self.data0, safediv = True, 
              period=5, period_dfast=3, period_dslow=3)
              
               self.stochastic=bt.talib.STOCH(self.data0.high, self.data0.low, 
               self.data0.close, fastk_period=5, slowk_period=3, slowd_period=3)
              
               self.stochastic.csv=True
              
               #self.stochastic15 = bt.indicators.StochasticSlow(self.data1, safediv 
                        = True, period=5, period_dfast=3, period_dslow=3)
              
                self.stochastic15 = bt.talib.STOCH(self.data1.high, self.data1.low, 
                self.data1.close, fastk_period=5, slowk_period=3, slowd_period=3)
              
                self.stochastic15.csv=True
      
      

      Does someone have some advise on how to resolve this?
      Many thanks

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

        @juliev said in Stochastic values generated outside 0-100:

        Does someone have some advise on how to resolve this?

        Yes. Your data is wrong, hence the wrong results. The formula itself prevent any value above 100, but OHLC restrictions have to be for that, i.e.: H >= C >= L

        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(); }); }