Backtrader Community

    • 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/

    In need of support with more indicators in a screener

    General Code/Help
    2
    4
    559
    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.
    • R
      Rudi last edited by

      I've been following the blog post on creating a screener on the basis of an Analyzer. Background being that i want to screen the S&P500 stocks at end of day to scan if a stock shows the signals I'm looking for.
      I've been trying several ways, but my python skills are not sufficient I think. Below my try, I would appreciate if somebody could point me in the right direction.

      class Screener(bt.Analyzer):
          params = dict(period=10)
      
          def start(self):
              self.smas = [bt.indicators.SMA(self.datas, period=self.p.period) for data in self.datas]
              self.trend_ema = [bt.indicators.ExponentialMovingAverage(data, period=200) for data in self.datas]
              self.adx = [bt.indicators.ADX(data, period=10) for data in self.datas]
      
              self.result = zip(self.datas, self.smas, self.crsi, self.trend_ema, self.adx)
      
          def stop(self):
              self.rets['over'] = list()
              self.rets['under'] = list()
      
              for value, sma, trend_ema, adx in self.result
                  node = data._name, data.close[0], crsi[0]
                  if value > trend_ema and adx >= 30
                      self.rets['over'].append(node)
      
      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        • Which direction?

        • What's the problem your code poses?

        Obviously you haven't run that code, because to start with you have something called self.crsi which doesn't exist but it is being put in a zip statement.

        @rudi said in In need of support with more indicators in a screener:

        I've been trying several ways, but my python skills are not sufficient I think.

        Let me be blunt. Programming skills are a pre-condition.

        R 1 Reply Last reply Reply Quote 0
        • R
          Rudi @backtrader last edited by

          @backtrader I'll forgive you your bluntness. I know C#, javascript and ruby, just python is new for me. And I did indeed simplify the code before posting but apparently left some in.

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

            If this is a contest, here is my list:

            • FPGA programming
            • Assembly for Motorola and Intel (MASM, TASM and gas)
            • m4
            • sh
            • C ... down to the OS kernel
            • C++
            • Pascal
            • Modula-2
            • C64 Basic (No ... the Motorola Assembly was not on a C64)
            • Python
            • Javascript
            • PHP
            • Visual Basic
            • SQL
            • dBase III (you could create fairly complicated things with nice character based GUIs)

            Under SunOS, Solaris, Linux, DOS, Win32, IRIX, C64, Web Browsers and Proprietary Environments (not all at the same time, not with all the languages obviously)

            And that's why I learnt that to ask for help/support I had to post something which was what I was actually trying to run (or running but with problems), what the input/output was, what I thought the problem was, what error was being shown., ...

            Now that the "mine is larger" contest is over ...

            • An isolated and redacted piece of code which isn't executable and has obviously never been put to the test to see if it executes ... doesn't help.
            1 Reply Last reply Reply Quote 2
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors