Home » Candlestick Patterns » Detecting Bearish Abandoned Baby Candlestick Pattern in Pine Script

Detecting Bearish Abandoned Baby Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Bearish Abandoned Baby Candlestick Pattern

The Bearish Abandoned Baby is a reversal candlestick pattern used in technical analysis to indicate a potential shift from an uptrend to a downtrend. Characterized by a specific arrangement of three candles, it is considered a reliable signal of changing market dynamics. The pattern begins with a large bullish candle, reflecting the prevailing upward trend. This is followed by a doji, a candle with a small or virtually nonexistent body, symbolizing market indecision. The doji gaps up from the preceding bullish candle, highlighting a disconnection in price action. The final element is a large bearish candle that opens with a gap down from the doji, signifying a sudden shift in sentiment toward selling. The gaps on either side of the Doji are critical, as they reinforce the reversal signal.

Bearish Abandoned Baby Candlestick Pattern

This pattern is rare but is treated with significance by traders and analysts due to its predictive value in anticipating downturns in the market.

Importance in Technical Analysis

In technical analysis, the Bearish Abandoned Baby candlestick pattern is highly valued due to its significance and implications for market trends. Its importance can be summarized in several key points:

  1. Reversal Signal: The Bearish Abandoned Baby is primarily recognized as a reversal pattern, indicating a potential shift from an uptrend to a downtrend. This makes it a crucial tool for traders looking to anticipate and capitalize on early signs of market reversals.
  2. Market Sentiment Indicator: The pattern represents a clear shift in market sentiment. It starts with a bullish candle, suggesting ongoing buying pressure. The subsequent doji indicates indecision or a balance between buyers and sellers, and the final bearish candle signals a strong shift towards selling, highlighting a change in trader psychology.
  3. Reliability: Though rare, the Bearish Abandoned Baby is considered a more reliable reversal pattern compared to some others, largely due to the gaps between the candles. These gaps are a significant indicator of a shift in market dynamics.
  4. Volume Confirmation: For added reliability, traders often look for accompanying high trading volume, particularly on the final bearish candle. Increased volume can provide further confirmation of the bearish momentum.
  5. Risk Management Tool: Recognizing this pattern can help traders in managing their risk, especially those holding long positions. It can serve as a signal to tighten stop losses, close existing long positions, or even initiate short positions.

Example From Trading View

Example From Trading View

Defining the Bearish Abandoned Baby Candlestick Pattern Criteria 


To accurately identify the Bearish Abandoned Baby candlestick pattern, a series of specific criteria must be met:

  1. Preceding Uptrend: The pattern should emerge during an uptrend in the market, indicating the dominance of bullish sentiment prior to the formation of the pattern.
  2. First Candle – Bullish: The pattern starts with a large bullish candle, signifying the continuation of the existing uptrend. This candle shows strong buying pressure.
  3. Second Candle – Doji: The middle candle is a doji, characterized by a small or almost nonexistent body. This candle represents market indecision and should gap up from the first candle, meaning its opening price is higher than the closing price of the first candle, creating a noticeable gap.
  4. Third Candle – Bearish: The final candle in the pattern is a large bearish candle. It should open with a gap down from the doji, meaning its opening price is lower than the closing price of the doji. This gap is crucial as it indicates a sudden shift in market sentiment from bullish to bearish.
  5. No Overlap in Gaps: There should be no overlap between the bodies or shadows of the first and third candles with the doji. The distinct gaps on either side of the doji are what characterize the Bearish Abandoned Baby.

Code For Detecting Bearish Abandoned Baby

//@version=5
indicator("Abandoned Baby - Bearish", shorttitle = "Abandoned Baby - Bear", overlay=true)

C_DownTrend = true
C_UpTrend = true
var trendRule1 = "SMA50"
var trendRule2 = "SMA50, SMA200"
var trendRule = input.string(trendRule1, "Detect Trend Based On", options=[trendRule1, trendRule2, "No detection"])

if trendRule == trendRule1
	priceAvg = ta.sma(close, 50)
	C_DownTrend := close < priceAvg
	C_UpTrend := close > priceAvg

if trendRule == trendRule2
	sma200 = ta.sma(close, 200)
	sma50 = ta.sma(close, 50)
	C_DownTrend := close < sma50 and sma50 < sma200
	C_UpTrend := close > sma50 and sma50 > sma200
C_Len = 14 // ta.ema depth for bodyAvg
C_ShadowPercent = 5.0 // size of shadows
C_ShadowEqualsPercent = 100.0
C_DojiBodyPercent = 5.0
C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick body

C_BodyHi = math.max(close, open)
C_BodyLo = math.min(close, open)
C_Body = C_BodyHi - C_BodyLo
C_BodyAvg = ta.ema(C_Body, C_Len)
C_SmallBody = C_Body < C_BodyAvg
C_LongBody = C_Body > C_BodyAvg
C_UpShadow = high - C_BodyHi
C_DnShadow = C_BodyLo - low
C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
C_WhiteBody = open < close
C_BlackBody = open > close
C_Range = high-low
C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
C_BodyMiddle = C_Body / 2 + C_BodyLo
C_ShadowEquals = C_UpShadow == C_DnShadow or (math.abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100) < C_ShadowEqualsPercent and (math.abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100) < C_ShadowEqualsPercent
C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
C_Doji = C_IsDojiBody and C_ShadowEquals

patternLabelPosLow = low - (ta.atr(30) * 0.6)
patternLabelPosHigh = high + (ta.atr(30) * 0.6)

label_color_bearish = input(color.red, "Label Color Bearish")
C_AbandonedBabyBearishNumberOfCandles = 3
C_AbandonedBabyBearish = C_UpTrend[2] and C_WhiteBody[2] and C_IsDojiBody[1] and high[2] < low[1] and C_BlackBody and low[1] > high
alertcondition(C_AbandonedBabyBearish, title = "New pattern detected", message = "New Abandoned Baby – Bearish pattern detected")
if C_AbandonedBabyBearish
    var ttBearishAbandonedBaby = "Abandoned Baby\nA bearish abandoned baby is a specific candlestick pattern that often signals a downward reversal trend in terms of security price. It is formed when a gap appears between the lowest price of a doji-like candle and the candlestick of the day before. The earlier candlestick is green, tall, and has small shadows. The doji candle is also tailed by a gap between its lowest price point and the highest price point of the candle that comes next, which is red, tall and also has small shadows. The doji candle shadows must completely gap either below or above the shadows of the first and third day in order to have the abandoned baby pattern effect."
    label.new(bar_index, patternLabelPosHigh, text="Abandonrd Baby", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishAbandonedBaby)
bgcolor(ta.highest(C_AbandonedBabyBearish?1:0, C_AbandonedBabyBearishNumberOfCandles)!=0 ? color.new(color.red, 90) : na, offset=-(C_AbandonedBabyBearishNumberOfCandles-1))

Output

Output

Overview of the script 

Indicator Setup

//@version=5
indicator("Abandoned Baby - Bearish", shorttitle = "Abandoned Baby - Bear", overlay=true)
  • Declares the script using Pine Script version 5.
  • Sets up an indicator with the name “Abandoned Baby – Bearish”, a short title for display purposes, and specifies that it should overlay on the price chart.

Trend Determination Configuration

var trendRule1 = "SMA50"
var trendRule2 = "SMA50, SMA200"
var trendRule = input.string(trendRule1, "Detect Trend Based On", options=[trendRule1, trendRule2, "No detection"])
  • Defines two methods for trend detection (using 50-day SMA alone or both 50-day and 200-day SMAs) and allows the user to choose one through an input dropdown.

Trend Calculation

if trendRule == trendRule1
	priceAvg = ta.sma(close, 50)
	C_DownTrend := close < priceAvg
	C_UpTrend := close > priceAvg

if trendRule == trendRule2
	sma200 = ta.sma(close, 200)
	sma50 = ta.sma(close, 50)
	C_DownTrend := close < sma50 and sma50 < sma200
	C_UpTrend := close > sma50 and sma50 > sma200
  • If the first trend rule is selected, calculates a 50-day SMA and defines a downtrend or uptrend based on the closing price’s position relative to this SMA.
  • If the second trend rule is chosen, it uses both 50-day and 200-day SMAs for a more comprehensive trend analysis.

Candlestick Analysis Parameters

C_Len = 14 // ta.ema depth for bodyAvg
C_ShadowPercent = 5.0 // size of shadows
C_ShadowEqualsPercent = 100.0
C_DojiBodyPercent = 5.0
C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick body

C_BodyHi = math.max(close, open)
C_BodyLo = math.min(close, open)
C_Body = C_BodyHi - C_BodyLo
C_BodyAvg = ta.ema(C_Body, C_Len)
C_SmallBody = C_Body < C_BodyAvg
C_LongBody = C_Body > C_BodyAvg
C_UpShadow = high - C_BodyHi
C_DnShadow = C_BodyLo - low
C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
C_WhiteBody = open < close
C_BlackBody = open > close
C_Range = high-low
C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
C_BodyMiddle = C_Body / 2 + C_BodyLo
C_ShadowEquals = C_UpShadow == C_DnShadow or (math.abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100) < C_ShadowEqualsPercent and (math.abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100) < C_ShadowEqualsPercent
C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
C_Doji = C_IsDojiBody and C_ShadowEquals
  1. Candle Body and Shadow Calculations:
    • C_BodyHi, C_BodyLo, and C_Body: These calculate the high, low, and overall size of the candle’s body.
    • C_UpShadow and C_DnShadow: These calculate the size of the upper and lower shadows (wicks) of the candle.
  2. Body Size Analysis:
    • C_BodyAvg: Computes the average body size over the last 14 candles using an Exponential Moving Average (EMA).
    • C_SmallBody and C_LongBody: Determines if the candle has a small or long body compared to the average.
  3. Candle Color:
    • C_WhiteBody and C_BlackBody: Determines if the candle is bullish (white body) or bearish (black body) based on whether the closing price is higher or lower than the opening price.
  4. Shadow Analysis:
    • C_HasUpShadow and C_HasDnShadow: Checks if the candle has significant upper or lower shadows, using a percentage threshold.
  5. Doji Identification:
    • C_IsDojiBody: Defines criteria for a candle to be considered a doji, which is crucial for patterns like the Bearish Abandoned Baby. A doji is identified based on a very small body relative to its overall range.
    • C_Doji: Final condition that confirms a candle as a doji, taking into account both body size and shadow equality.

Bearish Abandoned Baby Pattern Detection

C_AbandonedBabyBearish = C_UpTrend[2] and C_WhiteBody[2] and C_IsDojiBody[1] and high[2] < low[1] and C_BlackBody and low[1] > high

Core logic to detect the Bearish Abandoned Baby pattern. It checks for:

  • A bullish candle two periods ago during an uptrend (C_WhiteBody[2]).
  • A doji candle that gaps up from the previous bullish candle (C_IsDojiBody[1] and high[2] < low[1]).
  • A bearish candle that gaps down from the doji (C_BlackBody and low[1] > high).

Alerts and Visualization

alertcondition(C_AbandonedBabyBearish, title = "New pattern detected", message = "New Abandoned Baby – Bearish pattern detected")
if C_AbandonedBabyBearish
    var ttBearishAbandonedBaby = "Abandoned Baby\nA bearish abandoned baby is a specific candlestick pattern that often signals a downward reversal trend in terms of security price. It is formed when a gap appears between the lowest price of a doji-like candle and the candlestick of the day before. The earlier candlestick is green, tall, and has small shadows. The doji candle is also tailed by a gap between its lowest price point and the highest price point of the candle that comes next, which is red, tall and also has small shadows. The doji candle shadows must completely gap either below or above the shadows of the first and third day in order to have the abandoned baby pattern effect."
    label.new(bar_index, patternLabelPosHigh, text="Abandonrd Baby", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishAbandonedBaby)
  • Sets up an alert condition when the Bearish Abandoned Baby pattern is found.
  • When the pattern is detected, create a label on the chart for visual indication.

Background Coloring

bgcolor(ta.highest(C_AbandonedBabyBearish?1:0, C_AbandonedBabyBearishNumberOfCandles)!=0 ? color.new(color.red, 90) : na, offset=-(C_AbandonedBabyBearishNumberOfCandles-1))
  • Changes the background color of the chart to highlight when the pattern occurs.

Frequently Asked Questions

What is the primary function of this Pine Script code?

The code is designed to identify the Bearish Abandoned Baby candlestick pattern in trading charts, aiding traders in spotting potential trend reversals.

Can the trend detection method within the script be altered?

Yes, users can choose between different trend detection methods, such as using a 50-day SMA, a combination of 50-day and 200-day SMAs, or opting for no specific trend detection mechanism.

Does the script include visual cues on the trading charts?

It enhances usability by marking the pattern with labels and altering the chart’s background color where the pattern is detected, making it visually prominent.

Is there flexibility in the script to customize candlestick analysis?

Indeed, the script allows for the customization of key parameters like the average candle body size and shadow lengths, enabling users to tailor it to their specific analysis needs.

How does the script alert users to the pattern’s presence?

The script is equipped with an alert system that notifies users whenever the Bearish Abandoned Baby pattern is identified, providing timely indications for potential trading decisions.

Conclusion

This Pine Script code identifies the Bearish Abandoned Baby candlestick pattern. This pattern is a significant indicator in financial markets, often signaling a potential reversal from an uptrend to a downtrend. The script’s strength lies in its customizability and user-friendly features. It allows traders to choose different methods for trend detection and to adjust candlestick analysis parameters to their specific trading needs. The inclusion of visual cues like on-chart labels and background color changes, along with an alert system, makes it an effective tool for traders to quickly and accurately identify potential market reversals. However, it’s essential to remember that reliance on a single indicator is not advisable. The most effective use of this script would be in conjunction with other technical analysis tools and a comprehensive understanding of market dynamics for well-informed trading decisions.

Leave a Comment