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



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



  • How can I find Local extremum? any idea ?



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



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


Log in to reply
 

});