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/

    Conditional If statement not executing under the next(self)

    General Code/Help
    2
    2
    52
    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.
    • T
      tx_562 last edited by

      I can't seem to get my conditional if statement to work!

      It works properly with ONE condition (both seem to work), however nothing happens once I introduce TWO comparisons with the AND operator.

      def next(self):
          if not self.position:
              if self.data.close[0] >= self.mov[0] and self.data.close[0] >= self.boll.lines.top[0]:
                  print(self.data.close[0], self.datetime.date(ago=0), self.datetime.time(ago=0))
          else:
              print('nothing to print! ')
      

      I don't get an error, but nothing seems to output. Not even the else statement.

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        Your else statement is in different if condition, so if you have no position it will not come up doesn't matter if your if ... and ... string works or not.

        It can be a case that your conditions under and operator never come together, so and never returns true. You may want to plot the indicators and prices, or print them for each bar, and verify if the pattern you are looking for happens.

        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(); }); }