Indicator · Pine Script v4 · On the chart

Custom ZZ v1.0

by WISEPLAT· code credited to dmdman

This indicator plots a custom ZigZag line connecting extreme high and low points on the price chart whenever price reverses by more than a specified percentage.

View on GitHub

GitHub stars2on the repository
Pine versionv4older, still runs
Lines of code116
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago20 Jun 2023

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

116 lines of Pine Script v4 from ZigZag - ishod/custom_zz_v1.0 - Lines - Lines - 7.pine.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

custom_zz_v1.0 - Lines - Lines - 7.pine.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dmdman
// This is my attempt of Zig Zag indicator (combined with support and resistance levels based on zig zag points).
// Arrays are used in this version.
// Calculations are based on close price.
// There is an option to choose length for highest and lowest points to reduce volatility noise.
// Zig Zag indicator plots points on the chart whenever prices reverse by a percentage greater than a pre-chosen variable. 
// This indicator is used to identify price trends.
//
//@version=4
study("custom_zz_v1.0",overlay=true,max_lines_count=500)

//input options
change1         =   input(title="change from last extreme point(%)",   defval=5.,              minval=0.01)
len1            =   input(title="highest/lowest points length (bars)", defval=20,              minval=1)
width1          =   input(title="zigzag width",                        defval=2,               minval=1,   maxval=5)
clr1            =   input(title="zigzag color",                        defval=color.black)
bShowHlines     =   input(title="show horizontal s/r lines",           defval=true,            type=input.bool)
bShowSlines     =   input(title="show sloping s/r lines",              defval=true,            type=input.bool)

//declare variables
var b1          =   0
var zzX         =   bar_index
var zzY         =   close
var arrY        =   array.new_float(1,close)
var arrX        =   array.new_int(1,bar_index)
var arrYh       =   array.new_float(1,close)
var arrXh       =   array.new_int(1,bar_index)
var arrYl       =   array.new_float(1,close)
var arrXl       =   array.new_int(1,bar_index)

//conditions for extreme points
c1  = (close-zzY)/close*100 > change1   and b1!=1   and   close==highest(close,len1)
c2  = (zzY-close)/zzY*100   > change1   and b1!=-1  and   close==lowest(close,len1)

//part for extreme points update
zzY :=
   b1==1? max(close[1],zzY):
   b1==-1?min(close[1],zzY):
   zzY
zzX :=
   change(zzY)?
   bar_index[1]:
   zzX
if c1 == true or c2 == true                                     
    array.push(arrY,zzY)
    array.push(arrX,zzX) 
    if c1 == true
        b1:=1 
        array.push(arrYl,zzY)
        array.push(arrXl,zzX)
    if c2 == true
        b1:=-1
        array.push(arrYh,zzY)
        array.push(arrXh,zzX)

    // part for zig zag line
    if array.size(arrX)>1
        line3 =
           line.new(
           x1 = array.get(arrX,array.size(arrX)-2),
           y1 = array.get(arrY,array.size(arrY)-2),
           x2 = array.get(arrX,array.size(arrX)-1),
           y2 = array.get(arrY,array.size(arrY)-1),
           color=clr1,
           width=width1
           )

    // part for horizontal support and resistanse lines
    if bShowHlines == true
        if c1 == true
            line1 =       
               line.new(
               x1 = zzX-1,
               y1 = zzY,
               x2 = zzX,
               y2 = zzY,
               color=color.green,
               extend=extend.right
               ) 
        if c2 == true
            line2 =
               line.new(
               x1 = zzX-1,
               y1 = zzY,
               x2 = zzX,
               y2 = zzY,
               color=color.red,
               extend=extend.right
               )  
    
    //part for sloping support and resistanse lines
    if bShowSlines == true
        if array.size(arrXl)>1 and c1 == true
            lineH =
               line.new(
               x1 = array.get(arrXl,array.size(arrXl)-2),
               y1 = array.get(arrYl,array.size(arrYl)-2),
               x2 = array.get(arrXl,array.size(arrXl)-1),
               y2 = array.get(arrYl,array.size(arrYl)-1),
               color=color.green,
               width=1,
               extend=extend.right
               )
        if array.size(arrXh)>1 and c2 == true
            lineL=
               line.new(
               x1 = array.get(arrXh,array.size(arrXh)-2),
               y1 = array.get(arrYh,array.size(arrYh)-2),
               x2 = array.get(arrXh,array.size(arrXh)-1),
               y2 = array.get(arrYh,array.size(arrYh)-1),
               color=color.red,
               width=1,
               extend=extend.right
               )
    zzY:=close

Overview

Custom ZZ v1.0 uses arrays to track these points based on close prices and a chosen lookback length. The script additionally draws horizontal support/resistance lines at zigzag highs and sloping lines connecting them. Main settings control the reversal percentage threshold, highest/lowest points length, line width and color, plus toggles for showing horizontal and sloping support lines. It draws directly on the price chart with lines.

Details

Published by

WISEPLAT on GitHub

Code credit

dmdman, as written in the script's header

Type

Indicator, Pine Script v4

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.

Settings

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

SettingTypeDefaultVariable
change from last extreme point(%)input5.change1
highest/lowest points length (bars)int20len1
zigzag widthint2width1
zigzag colorcolorcolor.blackclr1
show horizontal s/r linesbooltruebShowHlines
show sloping s/r linesbooltruebShowSlines
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

575 stars

This indicator detects equal highs and lows by comparing prices within user-defined left and right bars using a tolerance percentage. It plots horizontal lines on the price chart for equal highs in one color and lows in another. A screener allows input of mult

Indicator v5 Support & resistanceTrend
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows with Screener

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - Linear Regression

AI Trend

by dearvn
257 stars

AI Trend is an indicator that plots pivot points, trend lines, and support and resistance levels directly on the price chart. It marks high and low pivots based on user-defined length, draws trend lines that check for violations at specified points, and identi

Indicator v5 TrendSupport & resistance
Updated 7 weeks ago · None stated GitHub repository of AI Trend

Dynamic Linear Regression

by TradersPost
228 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

Ichimoku Cloud

by harryguiacorn
220 stars

This indicator plots Ichimoku Cloud elements on the price chart, including Tenkan-sen, Kijun-sen, Senkou Span A and B lines with optional Chikou Span. It signals trend changes via Tenkan-sen and Kijun-sen crosses and places arrows at Kijun-sen direction shifts

Indicator v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ichimoku Cloud
219 stars

This indicator identifies local swing highs and swing lows to construct a Zig Zag pattern on the main price chart. It evaluates pivot points based on a customizable number of surrounding left and right bars. Using persistent variables, the script tracks previo

Indicator v4 Support & resistanceTrend Repaints
Updated 5 years ago · None stated GitHub repository of Teaching: Finding Highs and Lows 6

More Trend 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