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/

    3 Black Crows / 3 White Soldiers

    Indicators/Strategies/Analyzers
    2
    3
    451
    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.
    • mics
      mics last edited by

      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
      
      
      B 1 Reply Last reply Reply Quote 1
      • B
        barton05 @mics last edited by

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

        mics 1 Reply Last reply Reply Quote 0
        • mics
          mics @barton05 last edited by

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

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