Indicator · Pine Script v4 · On the chart

Trendsignal + Zig Zag + Swing Highs/Lows Candle Patterns

by DaniilOkrug· code credited to icewalk

This indicator combines three analysis tools into a single chart overlay: a custom trend signal script, a ZigZag indicator, and a swing high and low pattern detector.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv4older, still runs
Lines of code250
Settings11inputs
LicenceMIT
Last update4 years ago15 Dec 2021

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

250 lines of Pine Script v4 from trendsignal + zig zag[LUX] + Swing HighsLows Candl Patterns[LUX].txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

trendsignal + zig zag[LUX] + Swing HighsLows Candl Patterns[LUX].txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © icewalk

//@version=4
study("trendsignal + zig zag[LUX] + Swing Highs/Lows Candl Patterns[LUX]", overlay=true, max_bars_back=1000)

//---INPUT---

RISK = input(3, title="RISK", type=input.integer)
Alert_Delay_In_Seconds = input(0, title="Alert_Delay_In_Seconds", type=input.integer)
alertsOn = input(false, title="Включить оповещения?", type=input.bool)

//---INPUT END---

bool isBuy = na

int SSP = 9
var int PrevAlertTime = 0
var float alertBar = 0

var int K = na
float Range = 0
float AvgRange = 0
var float smin = na
var float smax = na
var float SsMax = na
var float SsMin = na
var float price = na
var bool uptrend = na
var bool old = false

// var int limit = bar_index - counted_bars
// if counted_bars == 0
int limit = 1 + SSP

K := 33 - RISK
for shift = limit to 0
    for i = shift to (shift + SSP)
        AvgRange += high[i] - low[i]
        
    Range := AvgRange / (SSP + 1)
    
    SsMax := high[shift]
    SsMin := low[shift]
    for i = shift to (shift + SSP - 1)
        price := high[i]
        if SsMax < price
            SsMax := price
        price := low[i]
        if SsMin > price
            SsMin := price
            
    smin := SsMin + (SsMax - SsMin)*K/100
    smax := SsMax - (SsMax - SsMin)*K/100
    
    if close[shift] < smin
        uptrend := false
    
    if close[shift] > smax
        uptrend := true
    
    if uptrend != old and uptrend == true
        
        if bar_index > alertBar and shift == 0
            isBuy := true
            alertBar := bar_index
            PrevAlertTime := time
    
    if uptrend != old and uptrend == false and (time - PrevAlertTime > 1 * Alert_Delay_In_Seconds)
        
        if bar_index > alertBar and shift == 0  and (time - PrevAlertTime > 1 * Alert_Delay_In_Seconds)
            isBuy := false
            alertBar := bar_index
            PrevAlertTime := time
    
    old := uptrend

plotshape(isBuy == true, title="Buy", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(isBuy == false, title="Sell", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)

//---trendsignal END---


//------------------------------------------------------------------------------
length      = input(100)
extend      = input(true,'Extend To Last Bar')
show_ext    = input(true,'Show Extremities') 
show_labels = input(true,'Show Labels') 

//Style

upcol = input(#ff1100,'Upper Extremity Color',group='Style')
midcol = input(#ff5d00,'Zig Zag Color',group='Style')
dncol = input(#2157f3,'Lower Extremity Color',group='Style')
//------------------------------------------------------------------------------
os = 0
src = close
n = bar_index
var float valtop = na
var float valbtm = na

//------------------------------------------------------------------------------
upper = highest(src,length)
lower = lowest(src,length)
os := src[length] > upper ? 0 : src[length] < lower ? 1 : os[1]

btm = os == 1 and os[1] != 1
top = os == 0 and os[1] != 0

//------------------------------------------------------------------------------

btm_n = valuewhen(btm,n,0)
top_n = valuewhen(top,n,0)
len = abs(btm_n - top_n)

if btm
    max_diff_up = 0.
    max_diff_dn = 0.
    valbtm := low[length]
    
    for i = 0 to len-1
        point = low[length] + i/(len-1)*(valtop - low[length])
        max_diff_up := max(max(src[length+i],open[length+i]) - point,max_diff_up)
        max_diff_dn := max(point - min(src[length+i],open[length+i]),max_diff_dn)
        
    line.new(n[len+length],valtop,n[length],low[length],color=midcol)
    
    if show_ext
        line.new(n[len+length],valtop+max_diff_up,n[length],low[length]+max_diff_up
          ,color=upcol,style=line.style_dotted)
        line.new(n[len+length],valtop-max_diff_dn,n[length],low[length]-max_diff_dn
          ,color=dncol,style=line.style_dotted)
    if show_labels
        label.new(n[length],low[length],tostring(low[length],'#.####'),color=#00000000
          ,style=label.style_label_up,textcolor=dncol,textalign=text.align_left,size=size.small)

if top
    max_diff_up = 0.
    max_diff_dn = 0.
    valtop := high[length]
    
    for i = 0 to len-1
        point = high[length] + i/(len-1)*(valbtm - high[length])
        max_diff_up := max(max(src[length+i],open[length+i]) - point,max_diff_up)
        max_diff_dn := max(point - min(src[length+i],open[length+i]),max_diff_dn)
    
    line.new(n[len+length],valbtm,n[length],high[length],color=midcol)
    
    if show_ext
        line.new(n[len+length],valbtm+max_diff_up,n[length],high[length]+max_diff_up
          ,color=upcol,style=line.style_dotted)
        line.new(n[len+length],valbtm-max_diff_dn,n[length],high[length]-max_diff_dn
          ,color=dncol,style=line.style_dotted)
    if show_labels
        label.new(n[length],high[length],tostring(high[length],'#.####'),color=#00000000
          ,style=label.style_label_down,textcolor=upcol,textalign=text.align_left,size=size.small)

if barstate.islast and extend
    max_diff_up = 0.
    max_diff_dn = 0.  
    x1 = 0
    y1 = 0.
    
    if os == 1
        x1 := btm_n-length
        y1 := valbtm
        
        for i = 0 to n-btm_n+length-1
            point = src + i/(n-btm_n+length-1)*(valbtm - src)
            max_diff_up := max(max(src[i],open[i]) - point,max_diff_up)
            max_diff_dn := max(point - min(src[i],open[i]),max_diff_dn)

    else 
        x1 := top_n-length
        y1 := valtop
        
        for i = 0 to n-top_n+length-1
            point = src + i/(n-top_n+length-1)*(valtop - src)
            max_diff_up := max(max(src[i],open[i]) - point,max_diff_up)
            max_diff_dn := max(point - min(src[i],open[i]),max_diff_dn)
        
    line.delete(line.new(x1,y1,n,src,color=midcol,extend=extend.right)[1])
    
    if show_ext
        line.delete(line.new(x1,y1+max_diff_up,n,src+max_diff_up
          ,color=upcol,style=line.style_dotted,extend=extend.right)[1])
        line.delete(line.new(x1,y1-max_diff_dn,n,src-max_diff_dn
          ,color=dncol,style=line.style_dotted,extend=extend.right)[1])
          
//------------------------------------------------------------------------------
plot(btm ? low[length] : top ? high[length] : na,'Circles'
  ,color = btm ? dncol : upcol
  ,style=plot.style_circles
  ,offset=-length)

//---------------------------------------
lengthS = input(21)
//------------------------------------------------------------------------------
o = open[lengthS],h = high[lengthS]
l = low[lengthS],c = close[lengthS]
//------------------------------------------------------------------------------
ph = pivothigh(close,lengthS,lengthS)
pl = pivotlow(open,lengthS,lengthS)
valH = valuewhen(ph,c,0)
valL = valuewhen(pl,c,0)
valpH = valuewhen(ph,c,1)
valpL = valuewhen(pl,c,1)
//------------------------------------------------------------------------------
d = abs(c - o)
hammer = pl and min(o,c) - l > d and h - max(c,o) < d
ihammer = pl and h - max(c,o) > d and min(c,o) - l < d
bulleng = c > o and c[1] < o[1] and c > o[1] and o < c[1]
hanging = ph and min(c,o) - l > d and h - max(o,c) < d
shooting = ph and h - max(o,c) > d and min(c,o) - l < d
beareng = c > o and c[1] < o[1] and c > o[1] and o < c[1]
//------------------------------------------------------------------------------
//Descriptions
//------------------------------------------------------------------------------
hammer_ = "The hammer candlestick pattern is formed of a short body with a long lower wick, and is found at the bottom of a downward trend."
  + "\n" + "\n A hammer shows that although there were selling pressures during the day, ultimately a strong buying pressure drove the price back up." 
ihammer_ = "The inverted hammer is a similar pattern than the hammer pattern. The only difference being that the upper wick is long, while the lower wick is short."
  + "\n" + "\n It indicates a buying pressure, followed by a selling pressure that was not strong enough to drive the market price down. The inverse hammer suggests that buyers will soon have control of the market."
bulleng_ = "The bullish engulfing pattern is formed of two candlesticks. The first candle is a short red body that is completely engulfed by a larger green candle"
  + "\n" + "\n Though the second day opens lower than the first, the bullish market pushes the price up, culminating in an obvious win for buyers"
hanging_ = "The hanging man is the bearish equivalent of a hammer; it has the same shape but forms at the end of an uptrend."
  + "\n" + "It indicates that there was a significant sell-off during the day, but that buyers were able to push the price up again. The large sell-off is often seen as an indication that the bulls are losing control of the market."
shotting_ = "The shooting star is the same shape as the inverted hammer, but is formed in an uptrend: it has a small lower body, and a long upper wick."
  + "\n" + "Usually, the market will gap slightly higher on opening and rally to an intra-day high before closing at a price just above the open – like a star falling to the ground."
beareng_ = "A bearish engulfing pattern occurs at the end of an uptrend. The first candle has a small green body that is engulfed by a subsequent long red candle."
  + "\n" + "It signifies a peak or slowdown of price movement, and is a sign of an impending market downturn. The lower the second candle goes, the more significant the trend is likely to be."
//------------------------------------------------------------------------------
n_i = bar_index
label lbl = na
H = valH > valpH ? "HH" : valH < valpH ? "LH" : na
L = valL < valpL ? "LL" : valL > valpL ? "HL" : na
txt = hammer ? "Hammer" : ihammer ? "Inverse Hammer" :
  bulleng ? "Bullish Engulfing" : hanging ? "Hanging Man" :
  shooting ? "Shooting Star" : beareng ? "Bearish Engulfing" : "None"
des = hammer ? hammer_ : ihammer ? ihammer_ :
  bulleng ? bulleng_ : hanging ? hanging_ :
  shooting ? shotting_ : beareng ? beareng_ : ""
if ph
    lbl := label.new(n_i[lengthS],max(c,o),H + "\n" + txt,color=#ff1100,
      style=label.style_label_down,textcolor=color.white,tooltip=des)
    label.delete(lbl[1])
else if pl
    lbl := label.new(n_i[lengthS],min(c,o),L + "\n" + txt,color=#2157f3,
      style=label.style_label_up,textcolor=color.white,tooltip=des)
    label.delete(lbl[1])
//------------------------------------------------------------------------------

Overview

Trendsignal + Zig Zag + Swing Highs/Lows Candle Patterns calculates dynamic support and resistance thresholds based on high-low price ranges and a configurable risk input to generate buy and sell triangle shapes on trend transitions. Additionally, it computes rolling highest highs and lowest lows to construct ZigZag lines and highlight extremities directly on price action. Inputs allow customization of risk levels, ZigZag length, alerts, and visual style.

Details

Published by

DaniilOkrug on GitHub

Code credit

icewalk, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Trend, Support & resistance, Candlestick patterns

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
RISKint3RISK
Alert_Delay_In_Secondsint0Alert_Delay_In_Seconds
Включить оповещения?boolfalsealertsOn
lengthint100length
Extend To Last Barbooltrueextend
Show Extremitiesbooltrueshow_ext
Show Labelsbooltrueshow_labels
Upper Extremity Colorcolor#ff1100upcol
Zig Zag Colorcolor#ff5d00midcol
Lower Extremity Colorcolor#2157f3dncol
lengthSint21lengthS
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

Reversal Breakout System

by TamaraKGreen
46 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 7 weeks ago · None stated GitHub repository of Reversal Breakout System

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 overlay indicator detects tweezer tops and bottoms and kangaroo-tail pin bars, then draws supply and demand zones from those patterns. It scores each zone, decays freshness, merges overlapping zones, and can invalidate a zone after a close-through or afte

Indicator v6 Candlestick patternsSupport & resistance
Updated yesterday · MIT GitHub repository of Tweezer & Kangaroo Zones [WavesUnchained]
7 stars

This indicator plots Smart Money Concepts and price action components directly on the price chart. It highlights bullish and bearish order blocks, multi-timeframe pivot points, market structure swings with key Fibonacci retracement levels (0.618 and 0.786), zo

Indicator v5 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Cryptokazancev Strategy Pack

TheStrat Suite

by 345-strategies
5 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 days ago · MPL-2.0 GitHub repository of TheStrat Suite

Hercules Rewrite

by g-moe
3 stars

Hercules Rewrite is a signal and visual trade management indicator that overlays entry setups directly on the price chart. It detects candle setups based on minimum tick movement and engulfing patterns, filtering entries through parameters like moving averages

Indicator v5 Candlestick patternsTrend
Updated 5 months ago · None stated GitHub repository of Hercules Rewrite

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