Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. overcash
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    O
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 6
    • Best 1
    • Groups 0

    overcash

    @overcash

    1
    Reputation
    4
    Profile views
    6
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    overcash Unfollow Follow

    Best posts made by overcash

    • RE: Discrepancy with PnL in the Stop function vs TradeAnalyzer Net PnL

      Thank you. That would make sense.
      If there is an open trade and price has increased then the value of that trade would be a paper gain in the account.

      posted in Indicators/Strategies/Analyzers
      O
      overcash

    Latest posts made by overcash

    • Looking for help on Bresserts DSS Indicator

      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'])
      
      posted in Indicators/Strategies/Analyzers
      O
      overcash
    • RE: Discrepancy with PnL in the Stop function vs TradeAnalyzer Net PnL

      @manos You rock, thanks for checking back-in. Works great!

      posted in Indicators/Strategies/Analyzers
      O
      overcash
    • RE: Discrepancy with PnL in the Stop function vs TradeAnalyzer Net PnL

      @manos

      Thanks for posting. Does it matter where you put that block of code?

      posted in Indicators/Strategies/Analyzers
      O
      overcash
    • RE: Discrepancy with PnL in the Stop function vs TradeAnalyzer Net PnL

      Thank you. That would make sense.
      If there is an open trade and price has increased then the value of that trade would be a paper gain in the account.

      posted in Indicators/Strategies/Analyzers
      O
      overcash
    • Discrepancy with PnL in the Stop function vs TradeAnalyzer Net PnL

      I'm trying to figure out what I'm doing wrong.

      I've been calculating PnL using the Stop function and am switching to using TradeAnalyzer and Returns from the analyzers.

      def stop(self):
          # calculate the actual returns
          self.roi = (self.broker.get_value() / self.val_start) - 1.0
          self.PNL = (self.broker.get_value() - self.val_start )
      
          print('Starting value:     {:.4f}'.format(self.val_start))
          print('Final value:        {:.4f}'.format(self.broker.get_value()))       
          print('PNL:                {:.4f}'.format(self.PNL))
          print('ROI:                {:.4f}%'.format(100.0 * self.roi))
          print('\n')
      

      PnL_Net:
      cerebro.addanalyzer(bt.analyzers.TradeAnalyzer, _name="ta")

      PnL: 8441.32, Pnl_Net: 3595.05

      PnL: 3455.63, Pnl_Net: -78.39

      And then sometimes they two measures of PnL match.
      PnL: -3047.4, Pnl_Net: -3047.4

      Any help would be much appreciated. TIA

      posted in Indicators/Strategies/Analyzers
      O
      overcash
    • Kraken BT-CCXT 403 error

      Hi
      I'm using David Vallance's bt-ccxt library and the sample kraken.py script to simply query an account balance. I'm not making any trades, but I keep getting these two 403 errors.

      requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://support.kraken.com/hc/en-us/articles/205893708-What-is-the-minimum-order-size-

      ccxt.base.errors.ExchangeNotAvailable: GET https://support.kraken.com/hc/en-us/articles/205893708-What-is-the-minimum-order-size- 403 Forbidden <!DOCTYPE html>

      This is my first time connecting BT to an exchange...anyone know what I'm doing wrong? Help would be greatly appreciated. Thanks.

      posted in General Code/Help
      O
      overcash