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



  • 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?



  • 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.



  • try

        def __init__(self):
            self.l.indicator_2 = (indicator_1 > 0) - (indicator_1 < 0)
    


  • 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.


  • administrators

    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


Log in to reply
 

});