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/

    Taking the sign on a indicator signal

    General Code/Help
    4
    5
    482
    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.
    • SkullTech
      SkullTech last edited by

      How can I create an indicator in the __init__ of my strategy which just outputs the sign (positive or negative, +1 or -1) of another indicator?

      1 Reply Last reply Reply Quote 0
      • Robin Dhillon
        Robin Dhillon last edited by

        Well, technically you can do that pretty easy. Make a custom indicator that follows the same formulation as your target one, and normalize it to output +1, if it goes above a certain threshold value and vice-versa for the -1. Take a look at the indicator reference and see how you can go about doing this.

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

          try

              def __init__(self):
                  self.l.indicator_2 = (indicator_1 > 0) - (indicator_1 < 0)
          
          • If my answer helped, hit reputation up arrow at lower right corner of the post.
          • Python Debugging With Pdb
          • New to python and bt - check this out
          1 Reply Last reply Reply Quote 0
          • SkullTech
            SkullTech last edited by

            Thanks for the help @Robin-Dhillon @ab_trader !!!

            You're right, it was as simple as declaring

            self.indicator3 = indicator1 > indicator2
            

            I was getting confused because it wasn't showing up in the plot, and because of that I was thinking that I was doing something wrong. I had to do this for the plot to show up.

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

              Individual operations (i.e.: dynamic lines created through operations) are NOT indicators and only indicators do plot.

              You should properly wrap things in the proper structure if you want them plotted. See Docs - Plotting

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