Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

Need help identifying a pattern of X candles

Apr 23, 2021 - 5:30 PM

Viewed 927 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/23816 COPY
  • I need to tweak my indicator that identifies demand zones on a chart.

    The pattern it needs to look for is:

    A red leg candle...
    Followed by up to 1-4 consecutive base candles...(color doesn't matter)
    Followed by up to 1-4 green leg candles...
    Followed by a base candle (color doesn't matter)

    Leg candle=Body of candle is >= 50% of the whole candle
    Base candle=Body of candle is < 50% of the whole candle

    The current code I have only finds a pattern of Red leg candle, base candle, green leg candle, base candle.

    I need it to be able to allow for 1 to 4 base candles after the first candle, and then 1 to 4 green leg candles after the base candle(s).

    How do I write a condition that the pattern can have 1 to 4 consecutive base candles, but not more than 4?

    1
  • Hey there

    What is a base candle?

    Also, would that help?
    https://www.tradingview.com/script/LLWck8sw-Candles-Cheat-Sheet/

    0
  • Sorry, a base candle is one where the body of it is less than 50% of the total range of the candle. A leg candle is where the body is greater than 50% of the total range of the candle. Unfortunately that page describes how to determine an exact pattern of candles. I haven't found a script that identifies 1-X candles of a certain type.

    0
  • //@version=4
    study(Pattern with Base and Leg Candles, shorttitle=PBL Pattern)

    red_leg = close[1] > open[1] and abs(close[1] - open[1]) >= (high[1] - low[1]) * 0.5
    base = abs(close - open) < (high - low) * 0.5
    green_leg = close > open and abs(close - open) >= (high - low) * 0.5

    var int consecutive_base = 0
    var int consecutive_green = 0

    if red_leg
    consecutive_base := 0
    consecutive_green := 0

    if base
    consecutive_base := consecutive_base + 1
    consecutive_green := 0

    if green_leg
    consecutive_green := consecutive_green + 1

    pattern_detected = consecutive_base >= 1 and consecutive_base <= 4 and consecutive_green >= 1 and consecutive_green <= 4

    plotshape(series=pattern_detected, location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)

    bgcolor(pattern_detected ? color.green : na, transp=90)

    0
CONTENTS