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/

    Support Resistance Line Break

    General Discussion
    3
    4
    1096
    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.
    • S
      sadegh last edited by

      Hi
      How can I find days when the resistance line is broken I found local extremum days by this code and I want to find after each extremum when the resistance line was break ! my code:

      max_idx = list(argrelextrema(data_f.close.values, np.greater, order=5)[0])
      min_idx = list(argrelextrema(data_f.close.values, np.less, order=5)[0])
      idx = max_idx + min_idx
      idx.sort()
      

      I want to find days like this:
      download (1).png
      How can I do that with backtrader!

      1 Reply Last reply Reply Quote 0
      • S
        sadegh last edited by

        How can I find Local extremum? any idea ?

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

          @sadegh said in Support Resistance Line Break:

          argrelextrema
          You'll either need to break down the numpy formula and convert that into indicators, or you could use numpy on your data in a dataframe before you enter it into the system, and then just read the signal. You need to make a custom pandas class for your signal. Option two sounds easier.

          RunBacktest.com

          1 Reply Last reply Reply Quote 1
          • mics
            mics last edited by

            BT has built in 'Highest' and 'Lowest' indicators that will do this for you.

            https://www.backtrader.com/docu/indautoref/#highest
            https://www.backtrader.com/docu/indautoref/#lowest

            For a long time I used it wrong a received inconsistent results. This structure works for me now:

            import backtrader as bt
            import backtrader.indicators as bt.ind
            
            class TheStrategy(bt.Strategy):
            
                params = (
                    ('highperiod_0', 60),
                    ('lowperiod_0', 60),
                    )
            
            def __init__(self):
            
                self.highest = highest = bt.ind.Highest(self.data, period=self.p.highperiod_0, plot=True, subplot=False)
                self.lowest = lowest = bt.ind.Lowest(self.data, period=self.p.lowperiod_0, plot=True, subplot=False)
            
            
            def next(self):
            
                #LONG POSITION: Breakout high when
                self.data.close > self.highest
                self.buy()
                
                #SHORT POSITION: Breakout low when
                self.data.close() < self.lowest
                self.sell
            

            You need to set the period for the number of bars you want to find the highest/lowest data for. Once you have this static high/low working, try using a dynamic indicator for something a little more complex:

            https://www.backtrader.com/blog/posts/2018-02-06-dynamic-indicator/dynamic-indicator/

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