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/

    How to access last indicatior value in __init__()

    Indicators/Strategies/Analyzers
    2
    4
    97
    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.
    • D
      dindom999 last edited by

      class SomeStrategy(bt.Strategy):
      
          def __init__(self):
              self.sma = bt.indicators.SMA(self.datas[0])
      
              #how to write here:
              self.sig = (sma_two_days_go>sma_one_days_go & sma_two_days_go< sma_today)
      
      

      I know how to do it in "def next()", but don't know to do it in init

      1 Reply Last reply Reply Quote 0
      • D
        dindom999 last edited by

        Sorry , mistyping, It should be:

                self.sig = (sma_two_days_ago>sma_one_days_ago & sma_two_days_ago< sma_today)
        
        run-out 1 Reply Last reply Reply Quote 0
        • run-out
          run-out @dindom999 last edited by

          @dindom999 Just use () brackets in init.

          self.sig = (self.sma(-2) > self.sma(-1)) & (self.sma(-2) < self.sma)
          

          RunBacktest.com

          D 1 Reply Last reply Reply Quote 0
          • D
            dindom999 @run-out last edited by

            @run-out It works, thanks!!!

            1 Reply Last reply Reply Quote 1
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors