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

Detecting Upside Tasuki Gap Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Upside Tasuki Gap Candlestick Pattern

The Upside Tasuki Gap is a bullish continuation candlestick pattern commonly found in technical analysis of financial markets. It typically appears in an uptrend and signifies the potential for the continuation of the existing bullish momentum. Here’s an overview of its key features:

  1. Formation:
    • The pattern consists of three candles.
    • First Candle: A long white (or green) candle that continues the prevailing uptrend.
    • Second Candle: Another white candle that opens with a gap up from the first candle, indicating strong bullish sentiment.
    • Third Candle: A black (or red) candle that opens within the body of the second candle and closes inside the gap between the first and second candles. This candle does not completely close the gap, leaving a portion of it unfilled.
  2. Interpretation:
    • The Upside Tasuki Gap is interpreted as a bullish signal. The gap up on the second day shows strong buying interest. The third day’s pullback is partial and does not erase the gains of the second day, suggesting that the bullish trend is likely to continue.
  3. Trading Considerations:
    • Traders often view this pattern as an opportunity to join the uptrend, especially if the third candle’s pullback is shallow and does not fill the gap entirely.
    • It is advisable to look for confirmation from additional technical indicators or bullish signals on the following candles.

Importance in Technical Analysis

The importance of the Upside Tasuki Gap candlestick pattern in technical analysis lies in its utility as a bullish continuation signal, particularly in the context of an ongoing uptrend. Its significance in the realm of technical analysis can be outlined as follows:

  1. Continuation Indicator: The Upside Tasuki Gap is a reliable indicator of the continuation of an existing uptrend. By recognizing this pattern, traders can anticipate further bullish momentum.
  2. Market Sentiment Insight: This pattern provides insight into market sentiment. The initial gap up indicates strong buying pressure, while the partial retracement in the third candle suggests that bulls are still in control despite some selling pressure.
  3. Entry and Exit Points: It can be used to identify potential entry points for traders looking to capitalize on an ongoing bullish trend. Similarly, if the pattern fails (e.g., the gap is completely filled), it might serve as a signal to exit or adjust positions.
  4. Volume Confirmation: The pattern’s validity is often confirmed by accompanying high trading volumes, especially on the first two candles. High volume supports the notion of strong buyer commitment.
  5. Combination with Other Indicators: Like all candlestick patterns, the Upside Tasuki Gap’s effectiveness increases when combined with other technical indicators such as moving averages, RSI, or MACD, providing a more comprehensive view of the market.

Example From Trading View

Defining the Upside Tasuki Gap Candlestick Pattern Criteria 

The Upside Tasuki Gap candlestick pattern is a three-candle formation in technical analysis that signals a continuation of an existing uptrend. To accurately identify this pattern, certain criteria must be met. Here is the definition of the Upside Tasuki Gap pattern criteria:

  1. Market Context:
    • The pattern should occur during an established uptrend. This context is crucial as the Upside Tasuki Gap is a bullish continuation pattern.
  2. First Candle:
    • The first candle is a long white (or green) candle, indicating strong bullish momentum. It should have a sizable body to demonstrate clear buying pressure.
  3. Second Candle:
    • The second candle is also a white (or green) candle that gaps up from the first candle. This means it opens at a price higher than the close of the first candle, with no overlap in the bodies of the two candles. This gap up reinforces the bullish sentiment.
  4. Third Candle:
    • The third candle is a black (or red) candle. It opens within the body of the second candle, but crucially, it does not start with a gap up. The top of this candle should be lower than the close of the second candle.
    • This candle should close within the gap created between the first and second candles, but it does not fully close the gap, leaving a portion of it unfilled.

Code For Detecting Upside Tasuki Gap

//@version=5
indicator("Upside Tasuki Gap - Bullish", shorttitle = "Upside 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_bullish = input(color.blue, "Label Color Bullish")
C_UpsideTasukiGapBullishNumberOfCandles = 3
C_UpsideTasukiGapBullish = false
if C_LongBody[2] and C_SmallBody[1] and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_WhiteBody[1] and C_BlackBody and C_BodyLo >= C_BodyHi[2] and C_BodyLo <= C_BodyLo[1]
	C_UpsideTasukiGapBullish := true
alertcondition(C_UpsideTasukiGapBullish, title = "New pattern detected", message = "New Upside Tasuki Gap – Bullish pattern detected")
if C_UpsideTasukiGapBullish
    var ttBullishUpsideTasukiGap = "Upside Tasuki Gap\nUpside Tasuki Gap is a three-candle pattern found in an uptrend that usually hints at the continuation of the uptrend. The first candle is long and green, followed by a smaller green candle with its opening price that gaps above the body of the previous candle. The third candle is red and it closes inside the gap created by the first two candles, unable to close it fully. The bear’s inability to close the gap hints that the uptrend might continue."
    label.new(bar_index, patternLabelPosLow, text="Upside Tasuki Gap", style=label.style_label_up, color = label_color_bullish, textcolor=color.white, tooltip = ttBullishUpsideTasukiGap)
bgcolor(ta.highest(C_UpsideTasukiGapBullish?1:0, C_UpsideTasukiGapBullishNumberOfCandles)!=0 ? color.new(color.blue, 90) : na, offset=-(C_UpsideTasukiGapBullishNumberOfCandles-1))

Output

Output

Overview of the script 

Indicator Setup

//@version=5
indicator("Upside Tasuki Gap - Bullish", shorttitle = "Upside Tasuki Gap", overlay=true)
  • //@version=5: Specifies that the script uses version 5 of Pine Script.
  • indicator(...): This function defines a new indicator named “Upside Tasuki Gap – Bullish” with a short title “Upside Tasuki Gap” and overlays it onto the price chart.

Initial Variable Declarations

C_DownTrend = true
C_UpTrend = true
  • Initializes two boolean variables, C_DownTrend and C_UpTrend, both set to true. These will be used to determine the trend direction.

Trend Detection Settings

var trendRule1 = "SMA50"
var trendRule2 = "SMA50, SMA200"
var trendRule = input.string(trendRule1, "Detect Trend Based On", options=[trendRule1, trendRule2, "No detection"])
  • Defines two trend detection methods based on moving averages (SMA50 alone or a combination of SMA50 and SMA200) and creates an input to let the user select their preferred trend detection method.

Trend Determination Logic

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
  • Sets the logic for determining the trend based on the user’s selection. Uses Simple Moving Averages (SMAs) to identify if the market is in an uptrend or downtrend.

Candlestick Feature Calculations

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
  • C_Len is set to 14, which specifies the length of the period over which the Exponential Moving Average (EMA) of the candlestick body will be calculated. This EMA is used to compare the relative size of a candle’s body to the average.
  • C_ShadowPercent specifies the minimum size of a candle’s shadow as a percentage of its body.
  • C_ShadowEqualsPercent is used to determine if the upper and lower shadows are approximately equal.
  • C_DojiBodyPercent defines the maximum size of a candle’s body, relative to its total range, to be classified as a Doji.
  • C_Factor indicates how much larger a shadow must be compared to the body to be considered significant.
  • C_BodyHi and C_BodyLo calculate the high and low points of the candle’s body, respectively.
  • C_Body computes the size of the candle’s body.
  • C_BodyAvg calculates the EMA of the candle body size over the specified period (C_Len), providing a benchmark to assess whether a candle has a long or short body.
  • C_UpShadow and C_DnShadow calculate the length of the upper and lower shadows of the candle.
  • C_HasUpShadow and C_HasDnShadow determine whether the candle has significant upper and lower shadows, based on the C_ShadowPercent threshold.

Upside Tasuki Gap Pattern Detection Logic

C_UpsideTasukiGapBullishNumberOfCandles = 3
C_UpsideTasukiGapBullish = false
if C_LongBody[2] and C_SmallBody[1] and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_WhiteBody[1] and C_BlackBody and C_BodyLo >= C_BodyHi[2] and C_BodyLo <= C_BodyLo[1]
    C_UpsideTasukiGapBullish := true
  • Defines the logic for detecting the Upside Tasuki Gap pattern. It checks for specific conditions related to candle size, color, and their positions relative to each other during an uptrend.

Alert and Label Configuration

if C_LongBody[2] and C_SmallBody[1] and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_WhiteBody[1] and C_BlackBody and C_BodyLo >= C_BodyHi[2] and C_BodyLo <= C_BodyLo[1]
	C_UpsideTasukiGapBullish := true
alertcondition(C_UpsideTasukiGapBullish, title = "New pattern detected", message = "New Upside Tasuki Gap – Bullish pattern detected")
if C_UpsideTasukiGapBullish
    var ttBullishUpsideTasukiGap = "Upside Tasuki Gap\nUpside Tasuki Gap is a three-candle pattern found in an uptrend that usually hints at the continuation of the uptrend. The first candle is long and green, followed by a smaller green candle with its opening price that gaps above the body of the previous candle. The third candle is red and it closes inside the gap created by the first two candles, unable to close it fully. The bear’s inability to close the gap hints that the uptrend might continue."
    label.new(bar_index, patternLabelPosLow, text="Upside Tasuki Gap", style=label.style_label_up, color = label_color_bullish, textcolor=color.white, tooltip = ttBullishUpsideTasukiGap)
  • Sets an alert condition for when the Upside Tasuki Gap pattern is detected. Also, adds a label on the chart with details about the pattern if it’s found.

Background Coloring

bgcolor(ta.highest(C_UpsideTasukiGapBullish?1:0, C_UpsideTasukiGapBullishNumberOfCandles)!=0 ? color.new(color.blue, 90) : na, offset=-(C_UpsideTasukiGapBullishNumberOfCandles-1))
  • Changes the background color of the chart to indicate the presence of the pattern, enhancing its visibility.

Frequently Asked Questions

What is the Purpose of This Pine Script Code?

To automatically identify the “Upside Tasuki Gap – Bullish” candlestick pattern on TradingView charts.

How Does the Script Determine the Market Trend?

By using Simple Moving Averages (SMA50 alone or SMA50 combined with SMA200).

Can the Script Identify Other Candlestick Patterns?

Yes, with modifications, it can be adapted to identify other candlestick patterns.

What Criteria Does the Script Use for the “Upside Tasuki Gap” Pattern?

It looks for a specific three-candle formation in an uptrend, where a gap up is followed by a smaller candle that does not fully close the gap.

How Does the Script Alert Traders to the Pattern Formation?

Through customizable alerts, chart labels, and background color changes when the pattern is detected.

Conclusion

This Pine Script code identifies the “Upside Tasuki Gap – Bullish” candlestick pattern. Its capability to automate the detection of this bullish continuation pattern in real time significantly enhances trading efficiency and decision-making. By employing Simple Moving Averages for trend analysis and meticulously defining the characteristics of the Upside Tasuki Gap pattern, the script offers a high level of precision in pattern recognition. Moreover, its user-friendly features like customizable alerts and visual indicators on the chart make it accessible to both novice and experienced traders. While it’s tailored for a specific pattern, the underlying principles and calculations can be adapted to identify other candlestick formations, demonstrating the script’s versatility.

Leave a Comment