For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

3 Black Crows / 3 White Soldiers



  • Sharing a simple candle indicator. These two patterns (coupled with other price movements), can be good indicators for price reversal:

    • 3 White Soldiers
    • 3 Black Crows

    This is an adaptation from an earlier post by @backtrader.

    3 Black Crows Example:

    import backtrader as bt
    
    class BlackCrows(bt.Indicator):
    
        lines = ('crows',)
        params = (
            ('period', 3),  # how many to consider
            ('ago', 0),  # offset to start in the past
        )
    
        def __init__(self):
            incs = [self.data.close(-i) < self.data.open(-i) for i in range(self.p.ago, self.p.ago + self.p.period)]
            self.lines.crows = bt.All(*incs)
    

    Use in strategy below. I often use 5 consecutive candles when there has been a fast move that is reversing.

    class TheStrategy(bt.Strategy):
        
        def __init__(self):
            self.three_crows = BlackCrows(self.data)  # 3 black crows. Default period = 3
            self.five_crows = BlackCrows(self.data, period=5)  # 5 black crows. Overrides period = 5
    
    


  • Maybe dont need to reinvent the wheel? Using bt.talib.CDL3WHITESOLDIERS and bt.talib.CDL3BLACKCROWS should work.



  • @barton05 said in 3 Black Crows / 3 White Soldiers:

    bt.talib

    Must be a new addition since the backtrader website was developed. It isn't listed on the BT website.

    https://www.backtrader.com/docu/talibindautoref/

    Quite a few other great indicators in the ta-lib library too:

    https://github.com/mrjbq7/ta-lib

    Thanks for pointing this out.


Log in to reply
 

});