Indicator · Pine Script v5 · On the chart

PIN BAR

by ryangaraygay

The PIN BAR indicator identifies strong and weak pin bar candlestick patterns, including hammers and shooting stars, directly on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code82
Settings7inputs
LicenceMIT
Last update1 year ago10 Apr 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

82 lines of Pine Script v5 from pin.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

pin.pine
//@version=5
indicator("PIN BAR", shorttitle="PIN", overlay=true, max_labels_count=500)

// inputs
atrRange = input.int(5, "ATR Length", tooltip="Bar size must be greater than this ATR to ignore small candles")
wickRatio = input.float(0.66, "Major Wick To Bar Height Ratio", tooltip="How much larger the signal wicks should be compared to whole candle for a strong PIN")
wickRatio2 = input.float(0.40, "Minor Wick To Bar Height Ratio", tooltip="How much larger the signal wicks should be compared to whole candle for a medium PIN")
min_volume_threshold = input.int(1000, "Minimum Volume Threshold")
standout_lookback = input.int(5, title = "Standout lookback", tooltip = "Number of bars to lookback to check if the pin nose/tail stands out.")

upperWickSize = high - math.max(open, close)
lowerWickSize = math.min(open, close) - low
bodySize = math.abs(close - open)

priorBarUp = close[1]>open[1]
priorBarDown = not priorBarUp
priorBodyBigEnough = bodySize[1] >= (ta.ema(bodySize, atrRange) - ta.stdev(bodySize, atrRange))

barSize = high - low
isBarLarge = barSize >= ta.atr(atrRange)// + ta.stdev(barSize, atrRange)
isBarAverageSize = barSize >= ta.atr(atrRange) - ta.stdev(barSize, atrRange)

midpoint = (high - low) / 2
closeSize = close - low
closeBelowMidpoint = (closeSize <= midpoint)
closeAboveMidpoint = (closeSize >= midpoint)

min_volume_met = volume > min_volume_threshold

var color_maxup = input.color(color.new(color.lime, 0), "bullish", group = "Signal Color")
var color_maxdown = input.color(color.new(color.red, 0), "bearish", group = "Signal Color")

downPinColor = color_maxdown
upPinColor = color_maxup

bodyWithinPriorBar = math.max(open, close) <= high[1] and math.min(open, close) >= low[1]

isStandoutHigh = ta.highest(standout_lookback)[1] < high
isStandoutLow = ta.lowest(standout_lookback)[1] > low

commonRules = priorBodyBigEnough and min_volume_met and bodyWithinPriorBar
commonRulesH = commonRules and closeBelowMidpoint and priorBarUp and isStandoutHigh
commonRulesL = commonRules and closeAboveMidpoint and priorBarDown and isStandoutLow

// stronger/stricter pins
pinbar_h = commonRulesH and upperWickSize >= wickRatio*barSize and isBarLarge
pinbar_l = commonRulesL and lowerWickSize >= wickRatio*barSize and isBarLarge

// // weaker pins
shootingstar = commonRulesH and upperWickSize >= wickRatio2*barSize and not pinbar_h and isBarAverageSize
hammer = commonRulesL and lowerWickSize >= wickRatio2*barSize and not pinbar_l and isBarAverageSize

pinbar_h2 = shootingstar
pinbar_l2 = hammer

// d = array.new<string>(0)
// array.push(d, str.tostring(priorBodyBigEnough) + "\n")
// array.push(d, str.tostring(min_volume_met) + "\n")
// array.push(d, str.tostring(bodyWithinPriorBar) + "\n")
// array.push(d, str.tostring(closeAboveMidpoint) + "\n")
// array.push(d, str.tostring(priorBarDown) + "\n")
// array.push(d, str.tostring(isBarAverageSize) + "\n")
// label.new(bar_index, high, str.tostring(d))

barComplete = barstate.isconfirmed

plotshape(barComplete and pinbar_h,style=shape.triangledown,color=downPinColor, size = size.normal)
plotshape(barComplete and pinbar_l,style=shape.triangleup,color=upPinColor,location=location.belowbar, size = size.normal)

plotshape(barComplete and pinbar_h2,style=shape.triangledown,color=downPinColor, size = size.tiny)
plotshape(barComplete and pinbar_l2,style=shape.triangleup,color=upPinColor,location=location.belowbar, size = size.tiny)

failed_newlow = close > low[1]
failed_newhigh = close < high[1]
ipin_up = commonRules and priorBarDown and closeBelowMidpoint and upperWickSize >= wickRatio*barSize and isBarLarge and failed_newlow
ipin_down = commonRules and priorBarUp and closeAboveMidpoint and lowerWickSize >= wickRatio*barSize and isBarLarge and failed_newhigh

plotchar(barComplete and ipin_up,char='⬆',color=upPinColor,location=location.belowbar, size = size.tiny)
plotchar(barComplete and ipin_down,char='⬇',color=downPinColor,location=location.abovebar, size = size.tiny)

alertcondition(barComplete and pinbar_h or pinbar_h2 or ipin_down, "Bearish PIN alert", "A bearish/down PIN candle was detected.")
alertcondition(barComplete and pinbar_l or pinbar_l2 or ipin_up, "Bullish PIN alert", "A bullish/up PIN candle was detected.")

Overview

PIN BAR evaluates pattern validity using major and minor wick-to-bar ratios, ATR volatility filters, volume thresholds, and relative standout lookback periods. Confirmed signals draw upward or downward shapes below or above candles, with larger shapes highlighting high-probability pin bars and smaller shapes marking minor patterns.

Details

Published by

ryangaraygay on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Candlestick patterns

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
ATR Lengthint5atrRange
Major Wick To Bar Height Ratiofloat0.66wickRatio
Minor Wick To Bar Height Ratiofloat0.40wickRatio2
Minimum Volume Thresholdint1000min_volume_threshold
Standout lookbackint5standout_lookback
bullishcolorcolor.new(color.lime, 0)color_maxup
bearishcolorcolor.new(color.red, 0)color_maxdown
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Heikin-Ashi Chart Identifier is an indicator that checks if the current chart uses Heikin-Ashi candles. It tracks matched candles where open equals the average of previous open and close, and verifies no gaps between bars. When conditions match, it display

Indicator v4 Candlestick patterns
Updated 10 days ago · GPL-3.0 GitHub repository of Heikin-Ashi Chart Identifier
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator

All Candlestick Patterns

by shunjizhan
292 stars

All Candlestick Patterns detects and highlights a wide range of bullish, bearish, and neutral candlestick patterns directly on the price chart. It features optional trend filtering using either a 50-period simple moving average or a combination of 50-period an

Indicator v4 Candlestick patternsTrend
Updated 3 years ago · None stated GitHub repository of All Candlestick Patterns
285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study

[RS]MTF Candle Sticks

by ricardosantos79
261 stars

This indicator overlays up to five higher-timeframe candlestick groups on the price chart. For each enabled timeframe it requests open, high, low, and close and can show up to five candles, offset by a spacing setting. The main inputs set the candle count, the

Indicator v4 Candlestick patternsSupport & resistance Repaints
Updated 4 years ago · None stated GitHub repository of [RS]MTF Candle Sticks
257 stars

This indicator detects a large set of classic candlestick patterns and plots colored labels on the price chart. Trend context uses a 50-period simple moving average, or the 50 and 200 averages stacked together, and can be switched off. Users filter bullish, be

Indicator v4 Candlestick patternsTrend
Updated 6 weeks ago · None stated GitHub repository of Snag - All Candlestick Patterns

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers