Indicator · Pine Script v5 · On the chart

Candlestick Structure [LuxAlgo]

by theonetrade· code credited to LuxAlgo

Candlestick Structure [LuxAlgo] detects sixteen classic bullish and bearish candlestick patterns, including Hammers, Engulfing patterns, Stars, Haramis, Tweezers, and Three Methods.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code478
Settings32inputs
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

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

candlestick_structure_luxalgo_xkLUzGBp.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("Candlestick Structure [LuxAlgo]",shorttitle = "LuxAlgo - Candlestick Structure", overlay = true, max_labels_count = 500, max_lines_count = 500)
//---------------------------------------------------------------------------------------------------------------------}
//Tooltips
//---------------------------------------------------------------------------------------------------------------------{
hammer_tt = "The Hammer pattern appears at the bottom of a downtrend. It is identified by a small upper wick (or no upper wick) with a small body, and an elongated lower wick whose length is 2X greater than the candle body’s width."
ihammer_tt = "The Inverted Hammer pattern appears at the bottom of a downtrend. It is identified by a small lower wick (or no lower wick) with a small body, and an elongated upper wick whose length is 2X greater than the candle body’s width."
hman_tt = "The Hanging Man pattern appears at the top of an uptrend. It is identified by a small upper wick (or no upper wick) with a small body, and an elongated lower wick whose length is 2X greater than the candle body’s width."
sstar_tt = "The Shooting Star pattern appears at the top of an uptrend. It is identified by a small lower wick (or no lower wick) with a small body, and an elongated upper wick whose length is 2X greater than the candle body’s width."
bulle_tt = "The Bullish Engulfing pattern appear at the bottom of a downtrend. It is a 2 bar pattern, identified by a large bullish candle body fully encapsulating (opening lower and closing higher) the previous small (bearish) candle body."
beare_tt = "The Bearish Engulfing pattern appear at the top of a downtrend. It is a 2 bar pattern, identified by a large bearish candle body fully encapsulating (opening higher and closing lower) the previous small (bullish) candle body."
r3_tt = "The Rising Three Method Pattern is an indicator of continuation for the current trend. It is a 5 bar pattern, identified by an initial full-bodied bullish candle, followed by 3 bearish candles who trade within the high and low of the initial candle, followed by another full-bodied bullish candle closing above the high of the initial candle."
f3_tt = "The Falling Three Method Pattern is an indicator of continuation for the current trend. It is a 5 bar pattern, identified by an initial full-bodied bearish candle, followed by 3 bullish candles who trade within the high and low of the initial candle, followed by another full-bodied bearish candle closing below the low of the initial candle."
tws_tt = "The Three White Soldiers Pattern appears at the bottom of a downtrend. It is identified by 3 full-bodied bullish candles, each opening within the body and closing below the high, of the previous candle."
tbc_tt  = "The Three Black Crows Pattern appears at the top of an uptrend. It is identified by 3 full-bodied bearish candles, each open within the body and closing below the low, of the previous candle."
mstar_tt = "The Morning Star Pattern appears at the bottom of a downtrend. It is a 3 bar pattern, identified by a full-bodied bearish candle, followed by a small-bodied bearish candle, followed by a full-bodied bullish candle that closes above the halfway point of the first candle."
estar_tt = "The Evening Star Pattern appears at the top of an uptrend. It is a 3 bar pattern, identified by a full-bodied bullish candle, followed by a small-bodied bullish candle, followed by a full-bodied bearish candle that closes below the halfway point of the first candle."
bullh_tt = "The Bullish Harami Pattern appears at the bottom of a downtrend. It is a 2 bar pattern, identified by an initial bearish candle, followed by a small bullish candle whose range is entirely contained within the body of the initial candle."
bearh_tt = "The Bearish Harami Pattern appears at the top of an uptrend. It is a 2 bar pattern, identified by an initial bullish candle, followed by a small bearish candle whose range is entirely contained within the body of the initial candle."
tweezer_top_tt = "The Tweezer Top bearish reversal candlestick pattern is identified by an initial bullish candle, followed by a bearish candle, both having equal highs."
tweezer_btm_tt = "The Tweezer Bottom bullish reversal candlestick pattern is identified by an initial bullish candle, followed by a bearish candle, both having equal lows."

//---------------------------------------------------------------------------------------------------------------------}
//User Inputs
//---------------------------------------------------------------------------------------------------------------------{

group1 = "    Bullish Patterns               Bearish Patterns"

//Bullish
hammerTog   = input.bool(true, "Hammer                ", group = group1, inline = "1")
ihammerTog  = input.bool(true, "Inverted Hammer   ", group = group1, inline = "2")
bulleTog    = input.bool(true, "Bullish Engulfing    ", group = group1, inline = "3")
r3Tog       = input.bool(true, "Rising 3                  ", group = group1, inline = "4")
twsTog      = input.bool(true, "3 White Soldiers     ", group = group1, inline = "5")
mstarTog    = input.bool(true, "Morning Star         ", group = group1, inline = "6")
bullhTog    = input.bool(true, "Bullish Harami      ", group = group1, inline = "7")
btmTweezTog = input.bool(true, "Tweezer Bottom    ", group = group1, inline = "8")

//Bearish
hmanTog     = input.bool(true, "Hanging Man", group = group1, inline = "1")
sstarTog    = input.bool(true, "Shooting Star", group = group1, inline = "2")
beareTog    = input.bool(true, "Bearish Engulfing", group = group1, inline = "3")
f3Tog       = input.bool(true, "Falling 3", group = group1, inline = "4")
tbcTog      = input.bool(true, "3 Black Crows", group = group1, inline = "5")
estarTog    = input.bool(true, "Evening Star", group = group1, inline = "6")
bearhTog    = input.bool(true, "Bearish Harami", group = group1, inline = "7")
topTweezTog = input.bool(true, "Tweezer Top", group = group1, inline = "8")

//Trend Options
minorDCLength = input.int(10, title = "Minor Trend Length", group = "Minor Trend", tooltip = "Minor Trend determined by Donchian Channels.")

majorTrendType = input.string("SuperTrend", title = "Major Trend Method", options = ["EMA","ChoCh","SuperTrend","Donchian Channel"], group = "Major Trend")

majorSwingLength = input.int(20, title = "Swing Length", minval = 2, group = "ChoCh Parameters")

majorEma1Length = input.int(50, title = "Short EMA Length", minval = 1, group = "EMA Parameters")
majorEma2Length = input.int(200, title = "Long EMA Length", minval = 1, group = "EMA Parameters")

majorSTFactor = input.float(4, title = "Super Trend Factor", group = "Super Trend Parameters")
majorSTLength = input.int(20, title = "Length", group = "Super Trend Parameters")

majorDCLength = input.int(40, title = "Donchian Channel Length", group = "Donchian Channel Parameters")

//Style
bcTog = input.bool(false, title = "Color Candles", group = "Style", tooltip = "Color Candles to visualize minor trend.")
bullColor = input.color(#089981, title = "Bull Color  ", group = "Style")
bearColor = input.color(#f23645, title = "Bear Color", group = "Style")
showFill = input.bool(true, title = "Show Gradient", group = "Style")
txtSize = input.string("tiny", title = "Label Size", options = ["tiny","small","normal","large","huge","auto"], group = "Style", inline = "3")

//Dashboard
showDash = input.bool(true, 'Show Dashboard', group = 'Dashboard')
dashLoc  = input.string('Bottom Right' , 'Location'  , options = ['Top Right', 'Bottom Right', 'Bottom Left'] , group = 'Dashboard')
textSize = str.lower( input.string('Tiny', 'Size', options = ['Tiny', 'Small', 'Normal'], group = 'Dashboard') )

//---------------------------------------------------------------------------------------------------------------------}
//Functions
//---------------------------------------------------------------------------------------------------------------------{
invis = color.new(chart.bg_color,100)

//Counting 
count(condition, filter)=>
    var reversals = 0
    var total = 0

    reversals += condition and filter ? 1 : 0 
    total += condition ? 1 : 0 

    [condition and filter, reversals / total * 100, total]

//SuperTrend Detection
get_st(_factor, _length) =>
    [st,s_dir] = ta.supertrend(_factor,_length)
    float no_data = na
    [st,st,(s_dir*-1)]

//EMA Trend Detection
get_ema(_len1,_len2) =>
    s_ema = ta.ema(close,_len1)
    l_ema = ta.ema(close,_len2)
    var int s_dir = 0
    if s_ema > l_ema
        s_dir := 1
    if s_ema < l_ema
        s_dir := -1
    
    [s_ema,l_ema,s_dir]

//Donchian Channel Trend Detection
get_dc(_length) =>
    upper = ta.highest((_length>0?_length:1))
    lower = ta.lowest((_length>0?_length:1))
    var int s_dir = 0
    var float trend_line = na
    if high == upper and s_dir != 1
        s_dir := 1
    if low == lower and s_dir != -1
        s_dir := -1

    [lower,upper,s_dir]


//Structure ChoCh Trend Detection
get_choch(len)=>
    var os = 0
    
    upper = ta.highest(len)
    lower = ta.lowest(len)

    os := high[len] > upper ? 0 : low[len] < lower ? 1 : os[1]

    top = os == 0 and os[1] != 0 ? high[len] : na
    btm = os == 1 and os[1] != 1 ? low[len] : na

    t = not na(top)
    b = not na(btm)

    var float t_val = na
    var float b_val = na
    var int t_bar = na
    var int b_bar = na
    var int t_count = 1
    var int b_count = 1 

    if t
        t_bar := bar_index-len
        t_val := top
        t_count := 1
    if b
        b_bar := bar_index-len
        b_val := btm
        b_count := 1

    bull_choch = ta.crossover(close,t_val) and t_count == 1
    bear_choch = ta.crossunder(close,b_val) and b_count  == 1 

    rev_up = false
    rev_down = false
    var int s_dir = 0
    if bull_choch and s_dir != 1
        line.new(t_bar, t_val, bar_index, t_val, color = bullColor, style = line.style_dashed)
        label.new(int(math.avg(t_bar,bar_index)), t_val, text = "ChoCh", style = label.style_label_down, color = invis, textcolor = bullColor, size = size.tiny)
        t_count := 0
        s_dir := 1
        rev_up := true
    if bear_choch and s_dir != -1
        line.new(b_bar, b_val, bar_index, b_val, color = bearColor, style = line.style_dashed)
        label.new(int(math.avg(b_bar,bar_index)), b_val, text = "ChoCh", style = label.style_label_up, color = invis, textcolor = bearColor, size = size.tiny)
        b_count := 0
        s_dir := -1
        rev_down := true
    float no_data = na
    [no_data,no_data,s_dir]

//Decodes User-Inputs into Actual values used by the script
get_trend(_type,swingLength,ema1Length,ema2Length,STFactor,STLength,DCLength) =>
    switch
        _type == "EMA" => get_ema(ema1Length,ema2Length)
        _type == "ChoCh" => get_choch(swingLength)
        _type == "SuperTrend" => get_st(STFactor,STLength)
        _type == "Donchian Channel" => get_dc(DCLength)

//Tracks signal alignment with major trend
get_pattern_data(_signal,_bias,_dir) =>
    var int same_trend = 0
    var int diff_trend = 0
    if _signal and _bias == _dir
        same_trend += 1
    if _signal and _bias != _dir
        diff_trend += 1
    total = same_trend+diff_trend
    [(same_trend/total),total]

//---------------------------------------------------------------------------------------------------------------------}
//Trends
//---------------------------------------------------------------------------------------------------------------------{
[minor_v1, minor_v2, minor_dir] = get_trend("Donchian Channel",0,0,0,0,0,minorDCLength)
[major_v1, major_v2, major_dir] = get_trend(majorTrendType,majorSwingLength,majorEma1Length,majorEma2Length,majorSTFactor,majorSTLength,majorDCLength)

minor_bear = minor_dir < 0
minor_bull = minor_dir > 0

major_bear = major_dir < 0
major_bull = major_dir > 0

major_color = major_bear?bearColor:major_bull?bullColor:na
minor_color = minor_bear?bearColor:minor_bull?bullColor:na

major_up = majorTrendType == "EMA" ? major_v1 : (major_bull ? major_v1 : close)
major_down = majorTrendType == "EMA" ? major_v2 : (major_bear ? major_v2 : close)

major_up_col = majorTrendType == "EMA" ? major_color : (major_bull ? major_color : invis)
major_down_col = majorTrendType == "EMA" ? major_color : (major_bear ? major_color : invis)

//---------------------------------------------------------------------------------------------------------------------}
//Candestick Patterns
//---------------------------------------------------------------------------------------------------------------------{
rc = close < open // Red Candle
gc = close > open // Green Candle

c_top = math.max(open,close) //Top of candle
c_bot = math.min(open,close) //Bottom of candle

hl_width = high-low //Total candle width (wick to wick)
bod_width = (c_top - c_bot) //Width of candle body (open to close)
hw_per = ((high - c_top)/hl_width)*100 //Percent of total candle width that is occupied by the upper wick
lw_per = ((c_bot - low)/hl_width)*100 //Percent of total candle width that is occupied by the lower wick
b_per = (bod_width/hl_width)*100 //Percent of total candle width that is occupied by the candle body

doji = math.round_to_mintick(close) == math.round_to_mintick(open)



//Bullish patterns
[hammer, hammer_per, hammer_count] = count(
  (lw_per > (b_per*2) and b_per < 50 and hw_per < 2 and not doji)
  , minor_bear)

[inv_hammer, inv_hammer_per, inv_hammer_count] = count(
  (hw_per > (b_per*2) and b_per < 50 and lw_per < 2 and not doji)
  ,minor_bear)

[rising_3, rising_3_per, rising_3_count] = count(
  (gc[4] and b_per[4] > 50) 
  and (rc[3] and c_top[3] <= high[4] and c_bot[3] >= low[4]) 
  and (rc[2] and c_top[2] <= high[4] and c_bot[2] >= low[4]) 
  and (rc[1] and c_top[1] <= high[4] and c_bot[1] >= low[4]) 
  and (gc and close > high[4] and b_per > 50)
  ,minor_bull[4])

[bull_engulfing, bull_engulfing_per, bull_engulfing_count] = count(
  rc[1] and gc and (bod_width > (bod_width[1]/2))  and (open < close[1]) and c_top > c_top[1] and (not rising_3) and (not doji[1])
  ,minor_bear)

[soldiers, soldiers_per, soldiers_count] = count(
  (gc[2] and b_per[2]>70)
  and (gc[1] and b_per[1]>70 and c_bot[1] >= c_bot[2] and c_bot[1] <= c_top[2] and close[1] > high[2])
  and (gc and b_per>70 and c_bot >= c_bot[1] and c_bot <= c_top[1] and close > high[1])
  ,minor_bear[2])

[m_star, m_star_per, m_star_count] = count(
  (rc[2] and b_per[2] > 80) 
  and (rc[1] and bod_width[1] < (bod_width[2]/2) and open[1] < close[2]) 
  and (gc and close > hl2[2])
  ,minor_bear[2])

[bull_harami, bull_harami_per, bull_harami_count] = count(
  gc and (high <= c_top[1] and low >= c_bot[1]) and rc[1] 
  ,minor_bear[1])

[tweezer_btm, tweezer_btm_per, tweezer_btm_count] = count(
  math.round_to_mintick(low) - math.round_to_mintick(low[1]) == 0 and gc and rc[1]
  ,minor_bear[1])

//Bearish Patterns
[s_star, s_star_per, s_star_count] = count(
  (hw_per > (b_per*2) and b_per < 50 and lw_per < 2 and not doji) 
  ,minor_bull)

[h_man, h_man_per, h_man_count] = count(
  (lw_per > (b_per*2) and b_per < 50 and hw_per < 2 and not doji)
  ,minor_bull)

[falling_3, falling_3_per, falling_3_count] = count(
  (rc[4] and b_per[4] > 50) 
  and (gc[3] and c_top[3] <= high[4] and c_bot[3] >= low[4]) 
  and (gc[2] and c_top[2] <= high[4] and c_bot[2] >= low[4]) 
  and (gc[1] and c_top[1] <= high[4] and c_bot[1] >= low[4]) 
  and (rc and close < low[4] and b_per > 50)
  ,minor_bear[4])

[bear_engulfing, bear_engulfing_per, bear_engulfing_count] = count(
  gc[1] and rc and (bod_width > (bod_width[1]/2)) and (open > close[1]) and c_bot < c_bot[1] and (not falling_3 )and (not doji[1]) 
  ,minor_bull)

[crows, crows_per, crows_count] = count(
  (rc[2] and b_per[2]>70)
  and (rc[1] and b_per[1]>70 and c_top[1] <= c_top[2] and c_top[1] >= c_bot[2] and close[1] < low[2])
  and (rc and b_per>70 and c_top <= c_top[1] and c_top >= c_bot[1] and close < low[1])
  ,minor_bull[2])

[e_star, e_star_per, e_star_count] = count(
  (gc[2] and b_per[2] > 80) 
  and (gc[1] and bod_width[1] < (bod_width[2]/2) and open[1] > close[2]) 
  and (rc and close < hl2[2])
  ,minor_bull[2])

[bear_harami, bear_harami_per, bear_harami_count] = count(
  rc and (high <= c_top[1] and low >= c_bot[1]) and gc[1]
  ,minor_bull[1])

[tweezer_top, tweezer_top_per, tweezer_top_count] = count(
  math.round_to_mintick(high) - math.round_to_mintick(high[1]) == 0 and rc and gc[1]
  ,minor_bull[1])

//---------------------------------------------------------------------------------------------------------------------}
//Labels
//---------------------------------------------------------------------------------------------------------------------{

//Major Direction is checked to determine the display of the pattern.
//Bullish Pattern Lables
if hammer and hammerTog and major_bull
    label.new(bar_index,low,"H", color = color(na), style = label.style_label_up, textcolor = bullColor, size = txtSize, tooltip = hammer_tt)

if inv_hammer and ihammerTog and major_bull
    label.new(bar_index,low,"IH", color = color(na), style = label.style_label_up, textcolor = bullColor, size = txtSize, tooltip = ihammer_tt)

if rising_3 and r3Tog and major_bull
    label.new(bar_index,low,"R3", color = color(na), style = label.style_label_up, textcolor = bullColor, size = txtSize, tooltip = r3_tt)

if bull_engulfing and bulleTog and major_bull
    label.new(bar_index,low,"EG▲", color = color(na), style = label.style_label_up, textcolor = bullColor, size = txtSize, tooltip = bulle_tt)

if soldiers and twsTog and major_bull
    label.new(bar_index,low,"3WS", color = color(na), style = label.style_label_up, textcolor = bullColor, size = txtSize, tooltip = tws_tt)

if m_star and mstarTog and major_bull
    label.new(bar_index,low,"MS", color = color(na), style = label.style_label_up, textcolor = bullColor, size = txtSize, tooltip = mstar_tt)

if bull_harami and bullhTog and major_bull
    label.new(bar_index,low,"H▲", color = color(na), style = label.style_label_up, textcolor = bullColor, size = txtSize, tooltip = bullh_tt)

if tweezer_btm and btmTweezTog and major_bull
    label.new(bar_index,low,"TB", color = color(na), style = label.style_label_up, textcolor = bullColor, size = txtSize, tooltip = tweezer_btm_tt)

//Bearish Pattern Labels
if s_star and sstarTog and major_bear
    label.new(bar_index,high,"SS", color = color(na), style = label.style_label_down, textcolor = bearColor, size = txtSize, tooltip = sstar_tt)
if h_man and hmanTog and major_bear
    label.new(bar_index,high,"HM", color = color(na), style = label.style_label_down, textcolor = bearColor, size = txtSize, tooltip = hman_tt)
if falling_3 and f3Tog and major_bear
    label.new(bar_index,high,"F3", color = color(na), style = label.style_label_down, textcolor = bearColor, size = txtSize, tooltip = f3_tt)
if bear_engulfing and beareTog and major_bear
    label.new(bar_index,high,"EG▼", color = color(na), style = label.style_label_down, textcolor = bearColor, size = txtSize, tooltip = beare_tt)
if bear_engulfing and beareTog and major_bear
    label.new(bar_index,high,"EG▼", color = color(na), style = label.style_label_down, textcolor = bearColor, size = txtSize, tooltip = beare_tt)
if crows and tbcTog and major_bear
    label.new(bar_index,high,"3BC", color = color(na), style = label.style_label_down, textcolor = bearColor, size = txtSize, tooltip = tbc_tt)
if e_star and estarTog and major_bear
    label.new(bar_index,high,"ES", color = color(na), style = label.style_label_down, textcolor = bearColor, size = txtSize, tooltip = estar_tt)
if bear_harami and bearhTog and major_bear
    label.new(bar_index,high,"H▼", color = color(na), style = label.style_label_down, textcolor = bearColor, size = txtSize, tooltip = bearh_tt)
if tweezer_top and topTweezTog and major_bear
    label.new(bar_index,high,"TT", color = color(na), style = label.style_label_down, textcolor = bearColor, size = txtSize, tooltip = tweezer_top_tt)

//---------------------------------------------------------------------------------------------------------------------}
//Table
//---------------------------------------------------------------------------------------------------------------------{
var table_position = dashLoc == 'Bottom Left' ? position.bottom_left 
  : dashLoc == 'Top Right' ? position.top_right 
  : position.bottom_right

var t = table.new(table_position, 4, 10
  , bgcolor      = #1e222d
  , border_color = #373a46
  , border_width = 1
  , frame_color  = #373a46
  , frame_width  = 1)

//Table setup
if showDash
    t.merge_cells(0,0,1,0)
    t.merge_cells(2,0,3,0)

if barstate.islast and showDash
    //Titles
    t.cell(0,0, "Bullish", text_color = color.white, bgcolor = color.new(bullColor,50), text_size  = textSize)
    t.cell(2,0, "Bearish", text_color = color.white, bgcolor = color.new(bearColor,50), text_size  = textSize)
    t.cell(0,1, "Pattern", text_color = color.white, text_size  = textSize)
    t.cell(1,1, "Alignment %", text_color = color.white, text_size  = textSize)
    t.cell(2,1, "Pattern", text_color = color.white, text_size  = textSize)
    t.cell(3,1, "Alignment %", text_color = color.white, text_size  = textSize)

    // Bullish Stats
    if hammerTog
        t.cell(0,2, "Hammer (H)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(1,2, str.tostring(nz(hammer_per), format.percent), tooltip = "Pattern Count:" + str.tostring(hammer_count), text_color = color.white, text_size  = textSize)

    if ihammerTog
        t.cell(0,3, "Inverted Hammer (IH)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(1,3, str.tostring(nz(inv_hammer_per), format.percent), tooltip = "Pattern Count:" + str.tostring(inv_hammer_count), text_color = color.white, text_size  = textSize)

    if bulleTog
        t.cell(0,4, "Bullish Engulfing (EG▲)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(1,4, str.tostring(nz(bull_engulfing_per), format.percent), tooltip = "Pattern Count:" + str.tostring(bull_engulfing_count), text_color = color.white, text_size  = textSize)

    if r3Tog
        t.cell(0,5, "Rising 3 (R3)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(1,5, str.tostring(nz(rising_3_per), format.percent), tooltip = "Pattern Count:" + str.tostring(rising_3_count), text_color = color.white, text_size  = textSize)

    if twsTog
        t.cell(0,6, "3 White Soldiers (3WS)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(1,6, str.tostring(nz(soldiers_per), format.percent), tooltip = "Pattern Count:" + str.tostring(soldiers_count), text_color = color.white, text_size  = textSize)

    if mstarTog
        t.cell(0,7, "Morning Star (MS)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(1,7, str.tostring(nz(m_star_per), format.percent), tooltip = "Pattern Count:" + str.tostring(m_star_count), text_color = color.white, text_size  = textSize)

    if bullhTog
        t.cell(0,8, "Bull Harami (H▲)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(1,8, str.tostring(nz(bull_harami_per), format.percent), tooltip = "Pattern Count:" + str.tostring(bull_harami_count), text_color = color.white, text_size  = textSize)

    if btmTweezTog
        t.cell(0,9, "Tweezer Bottom (TB)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(1,9, str.tostring(nz(tweezer_btm_per), format.percent), tooltip = "Pattern Count:" + str.tostring(tweezer_btm_count), text_color = color.white, text_size  = textSize)

    // Bearish Stats
    if hmanTog
        t.cell(2,2, "Hanging Man (HM)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(3,2, str.tostring(nz(h_man_per), format.percent), tooltip = "Pattern Count:" + str.tostring(h_man_count), text_color = color.white, text_size  = textSize)   

    if sstarTog
        t.cell(2,3, "Shooting Star (SS)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(3,3, str.tostring(nz(s_star_per), format.percent), tooltip = "Pattern Count:" + str.tostring(s_star_count), text_color = color.white, text_size  = textSize)

    if beareTog
        t.cell(2,4, "Bear Engulfing (EG▼)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(3,4, str.tostring(nz(bear_engulfing_per), format.percent), tooltip = "Pattern Count:" + str.tostring(bear_engulfing_count), text_color = color.white, text_size  = textSize)

    if f3Tog
        t.cell(2,5, "Falling 3 (F3)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(3,5, str.tostring(nz(falling_3_per), format.percent), tooltip = "Pattern Count:" + str.tostring(falling_3_count), text_color = color.white, text_size  = textSize)

    if tbcTog
        t.cell(2,6, "3 Black Crows (3BC)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(3,6, str.tostring(nz(crows_per), format.percent), tooltip = "Pattern Count:" + str.tostring(crows_count), text_color = color.white, text_size  = textSize)

    if estarTog
        t.cell(2,7, "Evening Star (ES)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(3,7, str.tostring(nz(e_star_per), format.percent), tooltip = "Pattern Count:" + str.tostring(e_star_count), text_color = color.white, text_size  = textSize)

    if bearhTog
        t.cell(2,8, "Bear Harami (H▼)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(3,8, str.tostring(nz(bear_harami_per), format.percent), tooltip = "Pattern Count:" + str.tostring(bear_harami_count), text_color = color.white, text_size  = textSize)

    if topTweezTog
        t.cell(2,9, "Tweezer Top (TT)", text_halign =  text.align_left, text_color = color.white, text_size  = textSize)
        t.cell(3,9, str.tostring(nz(tweezer_top_per), format.percent), tooltip = "Pattern Count:" + str.tostring(tweezer_top_count), text_color = color.white, text_size  = textSize)

//---------------------------------------------------------------------------------------------------------------------}
//Plots
//---------------------------------------------------------------------------------------------------------------------{
ma1 = plot(major_up, color = major_up_col, title = "Major Uptrend", style = plot.style_linebr, editable = false)
ma2 = plot(major_down, color = major_down_col, title = "Major Downtrend", style = plot.style_linebr, editable = false)

fill(ma1,ma2,
  math.max(major_up,major_down),
  math.min(major_up,major_down),
  major_bear ? color.new(major_color,90) : invis,
  major_bull ? color.new(major_color,90) : invis,
  display = showFill ? display.all : display.none)

barcolor(bcTog?minor_color:na)

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

Overview

Patterns are identified on the price chart and can be filtered using customizable major trend rules like SuperTrend, EMAs, or Donchian Channels. The script highlights structures using on-chart labels, optional candle coloring, gradient fills, and an information dashboard summarizing pattern activity.

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
Hammer           booltruehammerTog
Inverted Hammer   booltrueihammerTog
Bullish Engulfing    booltruebulleTog
Rising 3            booltruer3Tog
3 White Soldiers     booltruetwsTog
Morning Star        booltruemstarTog
Bullish Harami      booltruebullhTog
Tweezer Bottom    booltruebtmTweezTog
Hanging ManbooltruehmanTog
Shooting StarbooltruesstarTog
Bearish EngulfingbooltruebeareTog
Falling 3booltruef3Tog
Show all 32 settings
SettingTypeDefaultVariable
3 Black CrowsbooltruetbcTog
Evening StarbooltrueestarTog
Bearish HaramibooltruebearhTog
Tweezer TopbooltruetopTweezTog
Minor Trend Lengthint10minorDCLength
Major Trend MethodstringSuperTrendmajorTrendType
Swing Lengthint20majorSwingLength
Short EMA Lengthint50majorEma1Length
Long EMA Lengthint200majorEma2Length
Super Trend Factorfloat4majorSTFactor
Lengthint20majorSTLength
Donchian Channel Lengthint40majorDCLength
Color CandlesboolfalsebcTog
Bull Color  color#089981bullColor
Bear Colorcolor#f23645bearColor
Show GradientbooltrueshowFill
Label SizestringtinytxtSize
Show DashboardbooltrueshowDash
LocationstringBottom RightdashLoc
SizestringTinySize
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

Confluence Suite

by TamaraKGreen
47 stars

The Confluence Suite indicator draws multiple trading signals and tools directly on the price chart. It generates entry and exit signals based on selected modes and filters, with an AI signal classifier rating quality from 1-4. Additional features include smar

Indicator v5 TrendSMC / ICT / price action
Updated 2 months ago · None stated GitHub repository of Confluence Suite
32 stars

Ghost Channels fits dynamic parallel trend channels over a configurable lookback window using linear regression or pivot swing methods. It layers confirmation signals onto the channel geometry, detecting candlestick pattern reactions at the rails, volume-confi

Indicator v6 TrendBreakout
Updated 4 weeks ago · MIT GitHub repository of Ghost Channels [mph1nance]

TheStrat Suite

by 345-strategies
30 stars

This indicator implements Rob Smith's TheStrat price action methodology across up to six configurable timeframes. It classifies candles into inside, directional, and outside bars, identifies patterns like hammers, shooters, and failed 2s, and calculates magnit

Indicator v6 Candlestick patternsSupport & resistance Repaints
Updated 2 weeks ago · MPL-2.0 GitHub repository of TheStrat Suite
29 stars

MWM EMA x VWAP Engulfing is an intraday indicator that plots an exponential moving average against session VWAP to evaluate buyer and seller control. It identifies up to five entry setups confirmed by engulfing bodies, rejection wicks, momentum bars, or band t

Indicator v6 Moving averagesCandlestick patterns
Updated 6 weeks ago · MIT GitHub repository of MWM EMA x VWAP Engulfing

Pro Pattern Al-Sat

by MeridianAlgo
9 stars

This overlay indicator marks bullish and bearish chart patterns on the price chart and can hide either side. Optional filters require agreement from fast and slow EMAs, Supertrend, and ADX, plus volume, RSI, nearby pivot support or resistance, and a user-defin

Indicator v6 Candlestick patternsTrend
Updated 4 months ago · MIT GitHub repository of Pro Pattern Al-Sat

This indicator segments recent price bars into defined groups and visual boxes to serve as a visual chart ruler. It includes automated trend detection with configurable angle thresholds to plot uptrend, downtrend, and range segments directly on the price chart

Indicator v6 TrendSupport & resistance

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