Home » Candlestick Patterns » Detecting Bearish Stick Sandwich Candlestick Pattern in Pine Script

Detecting Bearish Stick Sandwich Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Bearish Stick Sandwich Candlestick Pattern

The Bearish Stick Sandwich Candlestick Pattern is a unique and relatively rare formation in technical analysis, typically signaling a bearish reversal. Here’s an overview of its key characteristics:

Overview of Bearish Stick Sandwich Candlestick Pattern
  1. Formation and Structure:
    • The pattern consists of three candles: two white (or green) candles sandwiching a black (or red) candle.
    • The first and third candles are bullish, showing a closing price higher than the opening price.
    • The middle candle is bearish, with a closing price lower than its opening price.
  2. Closing Prices Alignment:
    • A critical aspect of this pattern is that the closing prices of the first and third candles are approximately at the same level, indicating a potential exhaustion of the bullish trend.

Importance in Technical Analysis

The Bearish Stick Sandwich Candlestick Pattern holds significant importance in technical analysis for several reasons:

  1. Reversal Signal: It serves as a potential indicator of a bearish reversal, especially when it appears in an uptrend. This can alert traders to prepare for a possible change in market direction.
  2. Market Sentiment Insight: The pattern reflects a struggle between buyers and sellers, where the temporary gain by bears (in the middle candle) is countered by bulls, but without significant progress. This stalemate can signal weakening bullish momentum.
  3. Enhances Trading Strategy: Incorporating the Bearish Stick Sandwich pattern into a trading strategy can aid in making informed decisions about entry and exit points. It’s particularly useful for traders looking to identify tops or to initiate short positions.
  4. Confirmation of Other Indicators: When this pattern aligns with other bearish indicators or technical signals (like resistance levels or bearish divergence in oscillators), it can provide a stronger case for a bearish market outlook.
  5. Risk Management: Recognizing this pattern can help traders in managing risk, particularly by setting stop-loss orders more effectively or adjusting their portfolio to mitigate potential losses.

Example From Trading View

Example From Trading View

Defining the Bearish Stick Sandwich Candlestick Pattern Criteria

The Bearish Stick Sandwich Candlestick Pattern is defined by specific criteria that signal a potential bearish reversal in the market. Here are the key criteria that characterize this pattern:

  1. Three-Candle Formation:
    • The pattern consists of three candles: two bullish (white or green) candles surrounding a central bearish (black or red) candle.
  2. Trend Context:
    • It typically appears during an uptrend, indicating a potential reversal to a downtrend.
  3. First Candle:
    • The first candle is bullish, showing a close higher than its open, contributing to the ongoing uptrend.
  4. Middle Candle:
    • The middle candle is bearish, with a close lower than its open. This candle interrupts the uptrend, but not significantly enough to change the trend on its own.
  5. Third Candle:
    • The third candle is again bullish, closing around the same level as the first candle’s close. This creates a ‘sandwich’ effect.

Code For Detecting Bearish Stick Sandwich

//@version=5
indicator("Bearish Stick Sandwich Pattern", shorttitle="BSSP", overlay=true)

// Function to check if a candle is black (down) or white (up)
isBlackCandle(close, open) =>
    close < open

isWhiteCandle(close, open) =>
    close > open

// Criteria for Bearish Stick Sandwich
firstCandleWhite = isWhiteCandle(close[2], open[2])
middleCandleBlack = isBlackCandle(close[1], open[1])
lastCandleWhite = isWhiteCandle(close, open)

closingPricesNear = math.abs(close[2] - close) < ((high[2] - low[2]) * 0.1)
middleCandleContained = low[1] > low[2] and high[1] < high[2] and low[1] > low and high[1] < high

// Detecting the pattern
bearishStickSandwich = firstCandleWhite and middleCandleBlack and lastCandleWhite and closingPricesNear and middleCandleContained

// Plotting the label
if bearishStickSandwich
    label.new(bar_index[1], high[1], "Bearish Stick\nSandwich", color=color.rgb(255, 0, 0),yloc = yloc.abovebar)

Output

Output

Overview of the script 

1. Script Declaration

//@version=5
indicator("Bearish Stick Sandwich Pattern", shorttitle="BSSP", overlay=true)
  • //@version=5: Specifies that the script is written in version 5 of Pine Script.
  • indicator(...): Declares a new indicator with the name “Bearish Stick Sandwich Pattern”, a short title “BSSP”, and overlay=true indicates that the indicator will be plotted directly on the price chart.

2. Function Definitions for Candle Types

isBlackCandle(close, open) =>
    close < open

isWhiteCandle(close, open) =>
    close > open
  • isBlackCandle: A function to determine if a candle is black (bearish), which is true when the closing price is lower than the opening price.
  • isWhiteCandle: A function to check if a candle is white (bullish), true when the closing price is higher than the opening price.

3. Criteria for Bearish Stick Sandwich

firstCandleWhite = isWhiteCandle(close[2], open[2])
middleCandleBlack = isBlackCandle(close[1], open[1])
lastCandleWhite = isWhiteCandle(close, open)
  • These lines define the core pattern criteria: the first and last candles should be white (bullish), and the middle candle should be black (bearish).

4. Additional Pattern Conditions

closingPricesNear = math.abs(close[2] - close) < ((high[2] - low[2]) * 0.1)
middleCandleContained = low[1] > low[2] and high[1] < high[2] and low[1] > low and high[1] < high
  • closingPricesNear: Checks if the closing prices of the first and last candles are close to each other, within 10% of the range of the first candle.
  • middleCandleContained: Ensures the middle candle is contained within the range of the first and last candles.

5. Detecting the Pattern

bearishStickSandwich = firstCandleWhite and middleCandleBlack and lastCandleWhite and closingPricesNear and middleCandleContained
  • This line combines all the conditions to identify the Bearish Stick Sandwich pattern.

6. Plotting the Label

if bearishStickSandwich
    label.new(bar_index[1], high[1], "Bearish Stick\nSandwich", color=color.rgb(255, 0, 0),yloc = yloc.abovebar)
  • This conditional statement checks if the bearishStickSandwich pattern is true.
  • label.new(...): If the pattern is detected, this function plots a label on the chart.
  • bar_index[1], high[1]: The label is positioned at the high of the middle candle.
  • The label text is “Bearish Stick\nSandwich”, with a red color, placed above the bar.

Frequently Asked Questions

What does the Bearish Stick Sandwich Pine Script identify?

It detects the Bearish Stick Sandwich pattern, a potential bearish reversal signal in an uptrend.

What are the key components of this pattern in the script?

Two white (bullish) candles sandwiching a black (bearish) candle with similar closing prices for the white candles.

Can I modify the script for different trading instruments?

Yes, parameters like the ATR length can be adjusted to suit various instruments and volatility levels.

Is this script suitable for all time frames?

Yes, it can be applied to any time frame, but effectiveness may vary depending on market conditions.

Does the script provide visual indicators on the chart?

Yes, it plots a label on the chart where the Bearish Stick Sandwich pattern is identified.

Conclusion

This script is designed for detecting the Bearish Stick Sandwich Candlestick Pattern, a notable formation in technical analysis signaling a potential bearish reversal. It methodically identifies this pattern by analyzing the specific arrangement of three candles: two bullish candles surrounding a central bearish candle, with the closing prices of the bullish candles being nearly equal. The script enhances trading analysis by automating the detection process, thereby aiding traders in identifying potential reversal points with greater ease and precision. Its integration into trading strategies offers a valuable tool for market analysis, particularly for those focusing on candlestick patterns to inform their trading decisions.

Leave a Comment