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 get the last value from line in next()?

    Indicators/Strategies/Analyzers
    2
    4
    247
    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.
    • P
      pizza last edited by

      Hello! This is my indicator

      class TestIndicator(bt.Indicator):
      	...
      	def next(self):
      		dynamic_period = get_dynamic_period(self.data) 
      		sma = bt.indicators.SMA(self.data, period=dynamic_period)
      
      		last_value = sma.get(-1)  
      		self.lines.dynamic_sma[0] = last_value # not work
      		
      

      How to get the last value from line in next()?
      Thanks !

      1 Reply Last reply Reply Quote 0
      • P
        pizza last edited by

        correction:

        class TestIndicator(bt.Indicator):
        	...
        	def next(self):
        		dynamic_period = get_dynamic_period(self.data) 
        		sma = bt.indicators.SMA(self.data.close.get(0, self.p.data_period), period=dynamic_period)
        
        		last_value = sma.get(-1)  
        		self.lines.dynamic_sma[0] = last_value # not work
        
        run-out 1 Reply Last reply Reply Quote 0
        • run-out
          run-out @pizza last edited by

          @pizza You don't have a good grasp on using init and/or next. Please have a look here. https://www.backtrader.com/docu/induse/

          RunBacktest.com

          P 1 Reply Last reply Reply Quote 0
          • P
            pizza @run-out last edited by

            @run-out Thanks!

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