Indicator · Pine Script v5 · On the chart

Horns Pattern Identifier [LuxAlgo]

by theonetrade· code credited to LuxAlgo

The Horns Pattern Identifier highlights standard and inverted horn pattern formations directly on the price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code134
Settings3inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

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

134 lines of Pine Script v5 from assets/indicator/bit-exact/horns_pattern_identifier_luxalgo_eyakzwYP.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

horns_pattern_identifier_luxalgo_eyakzwYP.pine
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo

//@version=5
indicator("Horns Pattern Identifier [LuxAlgo]"
  , overlay         = true
  , max_lines_count = 500)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
threshold = input.float(0.05
  , step   = .01
  , minval = 0)
  
//Style
bull_css = input.color(#0cb51a, 'Bullish Horn Levels'
  , group = 'Style')

bear_css = input.color(#ff1100, 'Bearish Horn Levels'
  , group = 'Style')

//-----------------------------------------------------------------------------}
//Variables declaration
//-----------------------------------------------------------------------------{
var line conf = na
var line tp   = na

var target = 0.
var lvl    = 0.
var os     = 0
var cross  = 0

//-----------------------------------------------------------------------------}
//Rolling max/min & normalized distance
//-----------------------------------------------------------------------------{
max = math.max(high,high[1],high[2])
min = math.min(low,low[1],low[2])

top = math.abs(high - high[2])/(max-min)
btm = math.abs(low - low[2])/(max-min)

//-----------------------------------------------------------------------------}
//Detect and display horns alongside confirmation level/take profit
//-----------------------------------------------------------------------------{
n = bar_index

line.set_x2(conf, n)
line.set_x2(tp, n)

//Inverted Horn
if ta.crossunder(top, threshold) and high[1] < math.min(high, high[2])
    os := 0
    
    line.set_x2(conf, n - 2)
    line.set_x2(tp, n - 2)
    
    line.new(n
      , high
      , n - 2
      , high[2]
      , color = bear_css)
    
    lvl := min
    target := min - (max - min)
    
    conf := line.new(n
      , lvl
      , n + 1
      , lvl
      , style = line.style_dotted
      , color = bear_css)
      
    tp := line.new(n
      , target
      , n + 1
      , target
      , style = line.style_dashed
      , color = bear_css)

//Horn
if ta.crossunder(btm, threshold) and low[1] > math.max(low, low[2])
    os := 1
    
    line.set_x2(conf, n - 2)
    line.set_x2(tp, n - 2)
    
    line.new(n
      , low
      , n - 2
      , low[2]
      , color = bull_css)

    lvl := max
    target := max + (max - min)
    
    conf := line.new(n
      , lvl
      , n + 1
      , lvl
      , style = line.style_dotted
      , color = bull_css)
    
    tp := line.new(n
      , target
      , n + 1
      , target
      , style = line.style_dashed
      , color = bull_css)
    
//-----------------------------------------------------------------------------}
//Display breakout signals
//-----------------------------------------------------------------------------{
buy = ta.crossover(close, lvl) and os == 1 and cross == 1
sell = ta.crossunder(close, lvl) and os == 0 and cross == 1
cross := lvl != lvl[1] ? 1 : buy or sell ? 0 : cross[1]

//Plots
plotshape(buy ? low : na, "Buy Label"
  , style     = shape.labelup
  , location  = location.absolute
  , color     = #0cb51a
  , text      = "B"
  , textcolor = color.white
  , size      = size.tiny)

plotshape(sell ? high : na, "Sell Label"
  , style     = shape.labeldown
  , location  = location.absolute
  , color     = #ff1100
  , text      = "S"
  , textcolor = color.white
  , size      = size.tiny)

//-----------------------------------------------------------------------------}

Overview

Horns Pattern Identifier [LuxAlgo] evaluates three-bar price extremes and normalized high or low distances against a user-configurable threshold to detect patterns. Upon pattern identification, the script connects the horn peaks or troughs with colored lines and projects dotted confirmation and dashed target levels. It plots buy and sell shapes when the closing price breaks out across the confirmation levels. Users can adjust the distance threshold and custom level colors.

Details

Published by

theonetrade on GitHub

Code credit

LuxAlgo, as written in the script's header

Draws

On the price chart

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.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
thresholdfloat0.05threshold
Bullish Horn Levelscolor#0cb51abull_css
Bearish Horn Levelscolor#ff1100bear_css
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

220 stars

This indicator identifies High Of Low Price (HOLP) and Low Of High Price (LOHP) candlestick setups based on price extremes over a specified lookback period. A HOLP signal triggers when the current bar closes above the high of a recent session low, whereas a LO

Indicator v5 Candlestick patternsBreakout
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns - HOLP-LOHP

Reversal Breakout System

by TamaraKGreen
47 stars

This indicator detects inside candles inside larger parent candles on the price chart. It plots colored boxes around inside and parent candles, fills them with user-adjustable transparency, draws Fibonacci retracement lines and mother candle range lines, and d

Indicator v6 Candlestick patternsBreakout
Updated 2 months ago · None stated GitHub repository of Reversal Breakout System

TheStrat Setup Screener

by 345-strategies
30 stars

This indicator screens Rob Smith's TheStrat setups across six configurable timeframes for TradingView's Pine Screener. It classifies bars and exposes inside reversals, 2-2 reversals and continuations, failing 2s, range expansions, and outside bars as numeric p

Indicator v6 Candlestick patternsSupport & resistance Repaints
Updated 2 weeks ago · MPL-2.0 GitHub repository of TheStrat Setup Screener

Candle Breaks 1v1 L+S

by chargersfan47
7 stars

This indicator detects 1v1 candle break patterns where the current candle breaks and closes beyond the open of the prior opposite-colored candle. It projects a 1.618 Fibonacci extension target based on the previous candle's range, calculating the expected perc

Indicator v5 BreakoutCandlestick patterns
Updated 6 months ago · None stated GitHub repository of Candle Breaks 1v1 L+S
7 stars

This indicator identifies market displacement, structure breaks, and Fair Value Gaps (FVGs) directly on the main price chart. It highlights displacement candles using an average range lookback and multiplier factor, with optional structure break filtering usin

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 4 months ago · None stated GitHub repository of [CT] Displacement FVG Toolkit

CTF Raid Indicator

by jerryinyang
5 stars

This indicator detects stop hunts, liquidity raids, and Rob Hoffman Inventory Retracement Bar breakouts directly on the main price chart. It tracks bullish and bearish retracement bars using dynamic arrays, identifying when incoming price action breaks these s

Indicator v5 SMC / ICT / price actionBreakout
Updated 2 years ago · None stated GitHub repository of CTF Raid Indicator

More Candlestick patterns scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers