Overview of On Neck Candlestick Pattern
The On Neck candlestick pattern is a bearish continuation pattern found in financial markets, typically observed on a candlestick chart. This pattern consists of two candles and is formed during a downtrend. Here’s an overview of its structure and implications:
- Formation:
- First Candle: It is a long black (or red) candle, indicating a strong bearish sentiment. This candle continues the prevailing downtrend.
- Second Candle: This is a smaller white (or green) candle. It opens lower than the first candle’s close, indicating continued bearish pressure. However, it closes just at or slightly below the closing price of the first candle, hence the name ‘On Neck.’
- Interpretation and Implications:
- The On Neck pattern suggests that the bearish sentiment is still strong. Despite the slight bullish attempt seen on the second day, the bears manage to keep the price down.
- This pattern is generally considered a signal that the current downtrend is likely to continue.
Importance in Technical Analysis
The importance of technical analysis in financial markets lies in its ability to help traders and investors make informed decisions based on price movements and patterns. Technical analysis is founded on the premise that historical price movements and market data can indicate future price movements. Here are some key aspects that highlight its importance:
- Predicting Price Movements:
- Technical analysis allows traders to predict potential future price movements based on historical patterns. This prediction is not certain, but it gives traders a statistical edge in the market.
- Identifying Trends:
- One of the core principles of technical analysis is the identification of trends. By recognizing whether a market is in an uptrend, downtrend, or sideways trend, traders can align their trades with the overall market direction, increasing their chances of success.
- Risk Management:
- Technical analysis tools like support and resistance levels, trend lines, and technical indicators assist in setting stop-loss and take-profit levels, crucial for effective risk management.
- Timing Entry and Exit Points:
- It helps in determining optimal entry and exit points for trades. Identifying patterns, like the On Neck candlestick pattern, provides signals that traders use to time their trades.
- Supplementing Fundamental Analysis:
- While fundamental analysis looks at a company’s financial health and intrinsic value, technical analysis focuses on market sentiment and price movements. Many traders use a combination of both to make well-rounded trading decisions.
Example From Trading View
Defining the On Neck Candlestick Pattern Criteria
The On Neck candlestick pattern is a specific formation in technical analysis that is typically identified under certain conditions on a candlestick chart. Here are the defining criteria for this pattern:
- Market Context:
- The pattern should occur during a downtrend. This is crucial as the On Neck pattern is considered a bearish continuation pattern, indicating the potential continuation of the existing downtrend.
- First Candle:
- The first candle should be a long black (or red) candle, which is part of the ongoing bearish trend. This candle reflects strong selling pressure.
- Second Candle:
- The second candle should be a smaller white (or green) candle.
- It opens at or below the closing level of the first candle. This gap down at the opening is a sign of continued bearish sentiment.
- The critical feature of the second candle is that it closes just at or slightly below the closing price of the first candle. This is what gives the pattern its name – the second candle’s close is ‘on the neck’ of the first candle.
Code For Detecting On Neck
//@version=5 indicator("On Neck - Bearish", shorttitle = "On Neck", 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_OnNeckBearishNumberOfCandles = 2 C_OnNeckBearish = false if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_WhiteBody and open < close[1] and C_SmallBody and C_Range!=0 and math.abs(close-low[1])<=C_BodyAvg*0.05 C_OnNeckBearish := true alertcondition(C_OnNeckBearish, title = "New pattern detected", message = "New On Neck – Bearish pattern detected") if C_OnNeckBearish var ttBearishOnNeck = "On Neck\nOn Neck is a two-line continuation pattern found in a downtrend. The first candle is long and red, the second candle is short and has a green body. The closing price of the second candle is close or equal to the first candle's low price. The pattern hints at a continuation of a downtrend, and penetrating the low of the green candlestick is sometimes considered a confirmation. " label.new(bar_index, patternLabelPosHigh, text="On Neck", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishOnNeck) bgcolor(ta.highest(C_OnNeckBearish?1:0, C_OnNeckBearishNumberOfCandles)!=0 ? color.new(color.red, 90) : na, offset=-(C_OnNeckBearishNumberOfCandles-1))
Output
Overview of the script
Indicator Setup
//@version=5 indicator("On Neck - Bearish", shorttitle = "On Neck", overlay=true)
//@version=5
: Specifies the version of Pine Script being used (version 5 in this case).indicator(...)
: Declares a new custom indicator. It sets the full name to “On Neck – Bearish,” a short title to “On Neck,” and overlays this indicator on the price chart (overlay=true
).
Initial Variable Declarations
C_DownTrend = true C_UpTrend = true
These lines initialize two boolean variables, C_DownTrend
and C_UpTrend
, both set to true
. These will be used later 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 rules based on moving averages (SMA50 and SMA50/SMA200) and creates an input to let the user select the 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
- These blocks set the logic for trend detection based on the user’s selection. They use Simple Moving Averages (SMAs) to determine if the market is in an uptrend or downtrend.
Candlestick Pattern Criteria Variables
C_Len = 14 // ta.ema depth for bodyAvg
C_Len
is set to 14. This variable is used as the length parameter in calculating an exponential moving average (ema
) for the average body size of the candlesticks.
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
- These lines define constants related to the candlestick’s shadows and body:
C_ShadowPercent
: The minimum size of shadows as a percentage of the candle body.C_ShadowEqualsPercent
: Used to determine if the upper and lower shadows are roughly equal in size.C_DojiBodyPercent
: Percentage used to define a Doji candle (a candle with a very small body).C_Factor
: A factor indicating how much larger a shadow must be compared to the body to be considered dominant.
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)
- These lines calculate:
C_BodyHi
: The higher value of the candle’s open or close price.C_BodyLo
: The lower value of the candle’s open or close price.C_Body
: The size of the candle’s body.C_BodyAvg
: The exponential moving average of the candle body size overC_Len
periods.
C_SmallBody = C_Body < C_BodyAvg C_LongBody = C_Body > C_BodyAvg
- Defines whether a candle has a
C_SmallBody
(smaller than the average body size) or aC_LongBody
(larger than the average body size).
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
- Calculates the size of the upper (
C_UpShadow
) and lower (C_DnShadow
) shadows of the candle and defines whether the candle has significant upper (C_HasUpShadow
) and lower (C_HasDnShadow
) shadows based onC_ShadowPercent
.
C_WhiteBody = open < close C_BlackBody = open > close
- Determines the color of the candle:
C_WhiteBody
for a bullish candle (close price is higher than open price) andC_BlackBody
for a bearish candle (close price is lower than open price).
C_Range = high-low C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
C_Range
represents the total range of the candle (from high to low).C_IsInsideBar
checks if the current candle is an inside bar (completely within the range of the previous candle).
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_BodyMiddle
calculates the midpoint of the candle’s body.C_ShadowEquals
determines if the upper and lower shadows are roughly equal in size.
C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100 C_Doji = C_IsDojiBody and C_ShadowEquals
C_IsDojiBody
checks if the candle’s body is small enough relative to its range to be considered a Doji (usually signifies indecision in the market).C_Doji
combines theC_IsDojiBody
andC_ShadowEquals
conditions to fully define a Doji candle.
On Neck Pattern Detection Logic
C_OnNeckBearishNumberOfCandles = 2 C_OnNeckBearish = false if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_WhiteBody and open < close[1] and C_SmallBody and C_Range!=0 and math.abs(close-low[1])<=C_BodyAvg*0.05 C_OnNeckBearish := true
- Defines the logic for detecting the On Neck bearish pattern. It checks for a downtrend, a long black candle followed by a small white candle with specific opening and closing conditions.
Alert and Label Configuration
alertcondition(C_OnNeckBearish, title = "New pattern detected", message = "New On Neck – Bearish pattern detected") if C_OnNeckBearish var ttBearishOnNeck = "On Neck\nOn Neck is a two-line continuation pattern found in a downtrend. The first candle is long and red, the second candle is short and has a green body. The closing price of the second candle is close or equal to the first candle's low price. The pattern hints at a continuation of a downtrend, and penetrating the low of the green candlestick is sometimes considered a confirmation. " label.new(bar_index, patternLabelPosHigh, text="On Neck", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishOnNeck)
- Sets up an alert condition for when the On Neck pattern is detected. Additionally, if the pattern is found, it adds a label to the chart with details about the pattern.
Background Coloring
bgcolor(ta.highest(C_OnNeckBearish?1:0, C_OnNeckBearishNumberOfCandles)!=0 ? color.new(color.red, 90) : na, offset=-(C_OnNeckBearishNumberOfCandles-1))
- Changes the background color of the chart to indicate the presence of the pattern. It uses the highest value function
ta.highest
to check if the pattern has been detected in the lastC_OnNeckBearishNumberOfCandles
candles.
Frequently Asked Questions
This code is designed for identifying the “On Neck – Bearish” candlestick pattern in financial charts on TradingView. It helps traders recognize this specific bearish continuation pattern automatically, aiding in their technical analysis.
The code uses Simple Moving Averages (SMA) to assess the market trend. Users can choose between a single 50-period SMA or a combination of 50-period and 200-period SMAs for trend analysis. The trend is determined based on the closing prices in relation to these SMA lines.
While primarily focused on the “On Neck – Bearish” pattern, the script includes detailed candlestick feature calculations that could be adapted to identify other patterns in future modifications.
The “On Neck – Bearish” pattern is detected during a downtrend and involves a sequence of a long black candle followed by a smaller white candle. The white candle must open below the black candle’s close and close near its low.
Upon detecting the pattern, the script triggers an alert and places a label on the chart for easy identification. It may also change the background color around the pattern for enhanced visibility.
Conclusion
This Pine Script code identifies the “On Neck – Bearish” candlestick pattern, a significant pattern in the realm of technical analysis, particularly useful in bearish market conditions. The script efficiently automates the detection of this pattern, aiding traders in recognizing the potential continuation of downtrends without manual chart inspection. Key features of the script include its use of Simple Moving Averages for trend determination, customizable settings for user preference, and the implementation of specific criteria to accurately identify the “On Neck – Bearish” pattern. While it’s primarily focused on this particular pattern, the underlying framework of the script, with its detailed analysis of candlestick features, offers potential for adaptation to other candlestick patterns. The script’s ability to alert users through visual cues and notifications makes it a valuable asset for traders who rely on technical analysis for their trading decisions. However, like all technical analysis tools, it should ideally be used in conjunction with other indicators and analysis methods to ensure a comprehensive trading strategy.