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/

    Looking for help on Bresserts DSS Indicator

    Indicators/Strategies/Analyzers
    1
    1
    102
    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.
    • O
      overcash last edited by

      Hi, I'm attempting to build out a Bresserts DSS (Double Smoothed Stochastic) indicator. I have a working version both in TV and Pandas, but I'm failing to get it to work in BT.

      When I pass the second stochastic into a bt.ind.EMA it fails to produce a line, or a value, only Nan's. I've run this with the EMA as a separate indicator, passing the stochastic as input, and still nothing. Thanks in advance for the help.

      class DSS (bt.Indicator):
      
          lines = ('percent_K', 'pre_Calc','percent_K','stoch_triple', 'smoother','xDSS','stoch2','stochastic',)
          plotlines = dict(percent_K=dict(_name='%K', _plotskip=True,),
                              pre_Calc=dict(_plotskip=True),
                              stoch_triple =dict(_plotskip = True),
                              stochastic =dict(_plotskip = False),
                              xDSS = dict(_plotskip=True),)
      
          params = dict(
              period=10,
              ema_length = 9,
              trigger_length = 5
          )
      
          def __init__(self):
      
      
              self.lines.pre_Calc = btind.EMA(bt.talib.STOCH(self.data.close, self.data.high, self.data.low, period = self.p.period ), period = self.p.ema_length)
              # self.lines.pre_Calc = bt.talib.STOCH(self.data.close, self.data.high, self.data.low, period = self.p.period ) 
      
              self.lines.stochastic = btind.EMA(bt.talib.STOCH(self.lines.pre_Calc, self.lines.pre_Calc, self.lines.pre_Calc, period = self.p.period ),period = self.p.ema_length) 
      
      

      Tradingview code

      '''
      study(title="DSS Bressert (Double Smoothed Stochastic)", shorttitle="DSS Bressert")
      PDS = input(10, minval=1)
      EMAlen = input(9, minval=1)
      TriggerLen = input(5, minval=1)

      xPreCalc = ema(stoch(close, high, low, PDS), EMAlen)
      xDSS = ema(stoch(xPreCalc, xPreCalc, xPreCalc, PDS), EMAlen)
      xTrigger = ema(xDSS, TriggerLen)

      '''

      Pandas code

          def DSS(self, High, Low, Close):
              self.df_xfer = pd.DataFrame()
      
              self.period = 10 #PDS
              self.ema_len = 9 #
              self.trigger_len = 5
       
              # Set minimum low and maximum high of the k stoch
              self.df_xfer['High_Max'] = High.rolling(self.period).max()
              self.df_xfer['Low_Min'] = Low.rolling(self.period).min()
              
              #Calculate the Stochastic
              self.df_xfer['%K'] = 100 * (Close - self.df_xfer['Low_Min']) / (self.df_xfer['High_Max'] - self.df_xfer['Low_Min'])
      
      
              self.df_xfer['preCalc'] = self.df_xfer['%K'].ewm(span = self.ema_len, min_periods=1 ).mean()  
              self.df_xfer['xDSS_3'] = self.stochastics(self.df_xfer['preCalc'],self.df_xfer['preCalc'],self.df_xfer['preCalc']).ewm(span = self.ema_len, min_periods=1).mean()     
              self.df_xfer['Trigger'] = self.df_xfer['xDSS_3'].ewm(span = self.trigger_len, min_periods=1).mean()
      
              return (self.df_xfer['xDSS_3'], self.df_xfer['Trigger'])
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors