1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
ATR Length
int
5
atrRange
Major Wick To Bar Height Ratio
float
0.66
wickRatio
Minor Wick To Bar Height Ratio
float
0.40
wickRatio2
Minimum Volume Threshold
int
1000
min_volume_threshold
Standout lookback
int
5
standout_lookback
bullish
color
color.new(color.lime, 0)
color_maxup
bearish
color
color.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.
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
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
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
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
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
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