Home » Candlestick Patterns » Detecting Downside Tasuki Gap Candlestick Pattern in Pine Script

Detecting Downside Tasuki Gap Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Downside Tasuki Gap Candlestick Pattern

The Downside Tasuki Gap is a bearish continuation candlestick pattern that is typically observed in a downtrend and indicates the likelihood of the continuation of that trend. It is composed of three specific candles, each playing a crucial role in the formation:

Downside Tasuki Gap Candlestick Pattern
  1. First Candle: A long black (or red) candle, signifying a strong bearish movement. This candle is part of the existing downtrend, confirming the market’s current negative sentiment.
  2. Second Candle: Another black candle that opens with a gap down from the first candle’s closing. This gap is a vital component of the pattern, emphasizing the continued bearish momentum and the eagerness of sellers to drive the price lower.
  3. Third Candle: A white (or green) candle, which opens within the body of the second candle and closes within the gap formed between the first and second candles. However, it doesn’t close the gap entirely. This candle represents a brief pause or retracement in the downward movement, but the failure to close the gap suggests that the downward momentum is still dominant.

Importance in Technical Analysis

In technical analysis, the Downside Tasuki Gap candlestick pattern is highly valued for its ability to signal the continuation of a downtrend, offering traders and investors critical insights into market sentiment and momentum. Its importance in the realm of technical analysis can be summarized as follows:

  1. Confirmation of Bearish Trend Continuation: The Downside Tasuki Gap is primarily significant as it reinforces the ongoing bearish trend in a security’s price. Its appearance gives traders further confirmation that the current downtrend is likely to persist, which is invaluable for decision-making in bearish market phases.
  2. Timely Entry and Exit Signals: This pattern provides traders with potential entry points for short positions or signals to exit long positions. By recognizing the continuation of a downtrend, traders can make timely decisions to capitalize on the expected downward price movement.
  3. Enhances Risk Management: Identifying a Downside Tasuki Gap pattern can aid in risk management strategies. Traders might use this pattern to place stop-loss orders more effectively, thereby minimizing potential losses in a bearish market.
  4. Strengthens Analytical Approach: When combined with other technical analysis tools, such as trendlines, oscillators, and volume analysis, the Downside Tasuki Gap can offer a more comprehensive view of the market. It adds depth to technical analysis by contributing to a multi-faceted approach to understanding market movements.
  5. Psychological Insight: The pattern provides insight into market psychology. The initial gap down indicates strong selling pressure, while the inability of the third candle to close the gap shows a lack of sufficient buying interest, reinforcing the bearish sentiment.

Example From Trading View

Defining the Downside Tasuki Gap Candlestick Pattern Criteria

The Downside Tasuki Gap candlestick pattern is a bearish continuation pattern observed in technical analysis, and it has specific criteria for its formation. Recognizing this pattern involves looking for a particular arrangement of three candles within a downtrend. Here are the defining criteria for the Downside Tasuki Gap pattern:

  1. Prevailing Downtrend: The pattern occurs within the context of an existing downtrend. This is crucial as it indicates that the market is already in a bearish phase.
  2. First Candle: The pattern starts with a long black (or red) candle. This candle is a continuation of the bearish trend, reflecting strong selling pressure.
  3. Second Candle: The second candle is also a black candle. It opens lower than the closing price of the first candle, creating a gap down. This gap is a key feature and signifies continued selling pressure in the market.
  4. Third Candle: The third candle is a white (or green) candle that opens within the body of the second candle but does not close the gap between the first and second candles. It should close within the gap but not above the closing price of the first candle. This candle represents a slight bullish recovery or pause in the downtrend but is insufficient to indicate a trend reversal.
  5. Gap Maintenance: The gap between the first and second candles should not be filled by the third candle. The maintenance of this gap is essential to confirm the pattern’s validity as a bearish continuation signal.

Code For Detecting Downside Tasuki Gap

//@version=5
indicator("Downside Tasuki Gap - Bearish", shorttitle = "Downside Tasuki Gap", 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_DownsideTasukiGapBearishNumberOfCandles = 3
C_DownsideTasukiGapBearish = false
if C_LongBody[2] and C_SmallBody[1] and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_BlackBody[1] and C_WhiteBody and C_BodyHi <= C_BodyLo[2] and C_BodyHi >= C_BodyHi[1]
	C_DownsideTasukiGapBearish := true
alertcondition(C_DownsideTasukiGapBearish, title = "New pattern detected", message = "New Downside Tasuki Gap – Bearish pattern detected")
if C_DownsideTasukiGapBearish
    var ttBearishDownsideTasukiGap = "Downside Tasuki Gap\nDownside Tasuki Gap is a three-candle pattern found in a downtrend that usually hints at the continuation of the downtrend. The first candle is long and red, followed by a smaller red candle with its opening price that gaps below the body of the previous candle. The third candle is green and it closes inside the gap created by the first two candles, unable to close it fully. The bull’s inability to close that gap hints that the downtrend might continue."
    label.new(bar_index, patternLabelPosHigh, text="Downside Tasuki Gap", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishDownsideTasukiGap)
bgcolor(ta.highest(C_DownsideTasukiGapBearish?1:0, C_DownsideTasukiGapBearishNumberOfCandles)!=0 ? color.new(color.red, 90) : na, offset=-(C_DownsideTasukiGapBearishNumberOfCandles-1))

Output

Overview of the script 

1. Indicator Setup

//@version=5
indicator("Downside Tasuki Gap - Bearish", shorttitle = "Downside Tasuki Gap", overlay=true)
  • @version=5: Specifies Pine Script version 5.
  • indicator(...): Declares the script as an indicator, names it “Downside Tasuki Gap – Bearish”, and ensures it overlays on the price chart.

2. Trend Definition and User Input

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"])
  • Initializes variables C_DownTrend and C_UpTrend.
  • Defines two trend detection methods: "SMA50" and "SMA50, SMA200".
  • input.string(...): Allows the user to choose a trend detection method.

3. 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
  • Applies the selected trend rule to define the market trend.
  • Uses Simple Moving Averages (SMA) for trend calculation based on the user’s choice.

4. Candlestick Analysis Criteria

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
  • Sets parameters like C_Len for EMA depth.
  • Calculates candle properties like body size, shadows, and color (black or white).

5. Downside Tasuki Gap Detection Logic

if C_LongBody[2] and C_SmallBody[1] and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_BlackBody[1] and C_WhiteBody and C_BodyHi <= C_BodyLo[2] and C_BodyHi >= C_BodyHi[1]
	C_DownsideTasukiGapBearish := true
  • This part of the script initializes the `C_DownsideTasukiGapBearish` variable as `false`. It will be set to `true` if the criteria for the Downside Tasuki Gap pattern are met.
  • The `if` statement checks for the specific sequence and characteristics of the three candles that form the Downside Tasuki Gap.
  • The candle from two periods ago (`[2]`) must be a long black (red) body (`C_LongBody[2]`), indicating a strong bearish move.
  • The subsequent candle (`[1]`) is also black (`C_BlackBody[1]`), but smaller in size (`C_SmallBody[1]`), and opens below the low of the previous long black candle (`C_BodyHi[1] < C_BodyLo[2]`).
  • The current candle must be white (green) (`C_WhiteBody`), indicating a bullish move. It opens within the body of the previous candle and closes within the gap between the first and second candles, but crucially, does not close the gap entirely (`C_BodyHi <= C_BodyLo[2] and C_BodyHi >= C_BodyHi[1]`).
  • These conditions collectively confirm the presence of the Downside Tasuki Gap pattern, provided the market is in a downtrend (`C_DownTrend`).

6. Alert Condition

alertcondition(C_DownsideTasukiGapBearish, title = "New pattern detected", message = "New Downside Tasuki Gap – Bearish pattern detected")
  • Sets an alert that triggers when the Downside Tasuki Gap pattern is identified. This feature is particularly useful for traders who might not constantly monitor the charts, as it provides a timely notification.

7. Label and Background Coloring

if C_DownsideTasukiGapBearish
    var ttBearishDownsideTasukiGap = "Downside Tasuki Gap\nDownside Tasuki Gap is a three-candle pattern found in a downtrend that usually hints at the continuation of the downtrend. The first candle is long and red, followed by a smaller red candle with its opening price that gaps below the body of the previous candle. The third candle is green and it closes inside the gap created by the first two candles, unable to close it fully. The bull’s inability to close that gap hints that the downtrend might continue."
    label.new(bar_index, patternLabelPosHigh, text="Downside Tasuki Gap", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishDownsideTasukiGap)
bgcolor(ta.highest(C_DownsideTasukiGapBearish?1:0, C_DownsideTasukiGapBearishNumberOfCandles)!=0 ? color.new(color.red, 90) : na, offset=-(C_DownsideTasukiGapBearishNumberOfCandles-1))
  • When C_DownsideTasukiGapBearish is true, indicating the pattern is detected, this code creates a label on the chart. The label, positioned at patternLabelPosHigh, will display “Downside Tasuki Gap” with the predefined style and color settings (label_color_bearish for the label color and white for the text color). The tooltip (ttBearishDownsideTasukiGap) provides a brief description of the pattern.
  • The bgcolor function is used to change the background color of the chart bars where the pattern is detected. It checks if the pattern has occurred within the last C_DownsideTasukiGapBearishNumberOfCandles number of candles. If so, it sets the background color to a semi-transparent red, enhancing the visual representation of the pattern on the chart.

Frequently Asked Questions

What is the purpose of this Pine Script code?

This code automatically detects the Downside Tasuki Gap pattern in trading charts, signaling a continuation of a downtrend.

How does the script identify the trend?

The script uses Simple Moving Averages (SMA50 alone or SMA50 and SMA200 together) to determine the market trend.

What defines the Downside Tasuki Gap pattern in this script?

The pattern is defined by a sequence of three candles: two long bearish candles followed by a smaller bullish candle that does not close the gap.

Does the script provide real-time alerts for the pattern?

Yes, it triggers an alert when the Downside Tasuki Gap pattern is identified.

Can I customize this script for my trading strategy?

Yes, the script allows customization in trend determination and visual aspects like label color.

Conclusion

This script is designed for detecting the Downside Tasuki Gap candlestick pattern in financial market charts, providing traders with a powerful tool for identifying bearish continuation signals within a downtrend. It utilizes Simple Moving Averages (SMA50 or a combination of SMA50 and SMA200) to determine the prevailing market trend, ensuring the pattern is recognized in the correct context. The script’s core functionality lies in its ability to automatically detect the specific sequence of candles that form the Downside Tasuki Gap, thereby alerting traders to potential trading opportunities. Additionally, it offers customization options and enhances chart visualization with labels and background coloring, making it a versatile and user-friendly tool for technical analysis in trading. This combination of automated detection, alerting capabilities, and visual enhancements makes the script an invaluable asset for traders looking to leverage technical analysis in their trading strategies.

Leave a Comment