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/

    NameError: name 'buy_signal' is not defined

    Indicators/Strategies/Analyzers
    2
    2
    154
    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.
    • kam dorra
      kam dorra last edited by

      NameError: name 'buy_signal' is not defined

      Get this error: NameError: name 'buy_signal' is not defined
      even though I have defined 'buy_signal' in def __init__(self):

      	def __init__(self):
      		buy_signal = bt.If(A < float('Inf'), c(0) > B, False)
      		sell_signal = bt.If(C < float('Inf'), c(0) < D, False)
      
      	def next(self):
      		if buy_signal[0]:
      			self.buy()
      		elif sell_signal[0] and self.position > 0:
      			self.close()
      

      Thanks.

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

        https://pythontips.com/2013/08/07/the-self-variable-in-python-explained/

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }