ZigZag Library [TradingFinder]


The "Zig Zag" indicator is an analytical tool that emerges from pricing changes. Essentially, it connects consecutive high and low points in an oscillatory manner. This method helps decipher price changes and can also be useful in identifying traditional patterns.

By sifting through partial price changes, "Zig Zag" can effectively pinpoint price fluctuations within defined time intervals.

🔵Key Features

1.Drawing the Zig Zag based on Pivot points:

The algorithm is based on pivots that operate consecutively and alternately (switch between high and low swing). In this way, zigzag lines are connected from a swing high to a swing low and from a swing low to a swing high.

Also, with a very low probability, it is possible to have both low pivots and high pivots in one candle. In these cases, the algorithm tries to make the best decision to make the most suitable choice.

You can control what period these decisions are based on through the "PiPe" parameter.

2.Naming and labeling each pivot based on its position as "Higher High" (HH), "Lower Low" (LL), "Higher Low" (HL), and "Lower High" (LH).

Additionally, classic patterns such as HH, LH, LL, and HL can be recognized. All traders analyzing financial markets using classic patterns and Elliot Waves can benefit from the "zigzag" indicator to facilitate their analysis.

"HH": When the price is higher than the previous peak (Higher High).
"HL": When the price is higher than the previous low (Higher Low).
"LH": When the price is lower than the previous peak (Lower High).
"LL": When the price is lower than the previous low (Lower Low).

🔵How to Use

First, you can add the library to your code as shown in the example below.
import TFlab/ZigZagLibrary_TradingFinder/1 as ZZ

Function "ZigZag" Parameters:

🟣Logical Parameters

1.HIGH: You should place the "high" value here. High is a float variable.

2.LOW: You should place the "low" value here. Low is a float variable.

3.BAR_INDEX: You should place the "bar_index" value here. Bar_index is an integer variable.

4.PiPe: The desired pivot period for plotting Zig Zag is placed in this parameter. For example, if you intend to draw a Zig Zag with a Swing Period of 5, you should input 5.
PiPe is an integer variable.


Apart from the "PiPe" indicator, which is part of the customization capabilities of this indicator, you can create a multi-time frame mode for the indicator using 3 parameters "High", "Low" and "BAR_INDEX". In this way, instead of the data of the current time frame, use the data of other time frames.

Note that it is better to use the current time frame data, because using the multi-time frame mode is associated with challenges that may cause bugs in your code.

🟣Setting Parameters

5.SHOW_LINE: It's a boolean variable. When true, the Zig Zag line is displayed, and when false, the Zig Zag line display is disabled.

6.STYLE_LINE: In this variable, you can determine the style of the Zig Zag line. You can input one of the 3 options: line.style_solid, line.style_dotted, line.style_dashed. STYLE_LINE is a constant string variable.

7.COLOR_LINE: This variable takes the input of the line color.

8.WIDTH_LINE: The input for this variable is a number from 1 to 3, which is used to adjust the thickness of the line that draws the Zig Zag. WIDTH_LINE is an integer variable.

9.SHOW_LABEL: It's a boolean variable. When true, labels are displayed, and when false, label display is disabled.

10.COLOR_LABEL: The color of the labels is set in this variable.

11.SIZE_LABEL: The size of the labels is set in this variable. You should input one of the following options:, size.tiny, size.small, size.normal, size.large, size.huge.

12.Show_Support: It's a boolean variable that, when true, plots the last support line, and when false, disables its plotting.

13.Show_Resistance: It's a boolean variable that, when true, plots the last resistance line, and when false, disables its plotting.

You can use the following code snippet to import Zig Zag into your code for time efficiency.

//import Library
import TFlab/ZigZagLibrary_TradingFinder/1 as ZZ

// Input and Setting
// Zig Zag Line
ShZ = input.bool(true , 'Show Zig Zag Line', group = 'Zig Zag') //Show Zig Zag

PPZ = ,'Pivot Period Zig Zag Line' , group = 'Zig Zag') //Pivot Period Zig Zag

ZLS = input.string(line.style_dashed , 'Zig Zag Line Style' , options = [line.style_solid ,line.style_dotted , line.style_dashed], group = 'Zig Zag' )

//Zig Zag Line Style
ZLC = input.color(color.rgb(0, 0, 0) , 'Zig Zag Line Color' , group = 'Zig Zag')  //Zig Zag Line Color
ZLW = , 'Zig Zag Line Width' , group = 'Zig Zag')//Zig Zag Line Width 

// Label
ShL = input.bool(true , 'Label', group = 'Label') //Show Label 
LC =  input.color(color.rgb(0, 0, 0) , 'Label Color' , group = 'Label')//Label Color
LS =  input.string(size.tiny , 'Label size' , options = [, size.tiny, size.small, size.normal, size.large, size.huge], group = 'Label' )//Label size

Show_Support= input.bool(false, 'Show Last Support',
 tooltip = 'Last Support' , group = 'Support and Resistance')
Show_Resistance = input.bool(false, 'Show Last Resistance',
 tooltip = 'Last Resistance' , group = 'Support and Resistance')

//Call Function
ZZ.ZigZag(high ,low ,bar_index ,PPZ , ShZ ,ZLS , ZLC, ZLW ,ShL , LC , LS , Show_Support , Show_Resistance )

파인 라이브러리

트레이딩뷰 정신에 따라 오써는 이 파인 코드를 오픈 소스 라이브러리로 퍼블리쉬하여 당사 커뮤니티의 다른 파인 프로그래머들이 쓸 수 있도록 하였습니다. 오써에게 찬사를! 여러분은 이 라이브러리를 프라이빗 또는 오픈 소스 퍼블리케이션에 쓸 수 있지만 퍼블리케이션에 재사용은 하우스룰을 따릅니다.


이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

이 라이브러리를 쓰시겠습니까?

텍스트를 클립보드에 카피한 뒤 님의 스크립트에 붙여 넣기.