PINE LIBRARY
업데이트됨 swinglibrary

Library "swinglibrary"
This library is for calculating non-repainting swings for further calculation on them.
These swings can later be drawn, but drawing is not part of this library, only the calculation.
What do I need to use the library?
You better include the following constants into your script using this library:
Pine Script®
Choosing the function, that fits your needs
This library contains 4 functions for calculating swings, the difference between them are the data you get for every swing point and additional average values for length and duration:
The naming scheme of these functions is the following:
The base version swings() is only for the swings containing the following swingPoint type:
swingPoint
Fields:
x (integer): bar index
y (float): price
hilo (integer) 1 -> high, -1 -> low
and the return type:
swingReturn
Fields:
swings (array<swingPoint>): array of the last x swing points
newSwingHigh (integer): flag to detect changes for swing highs see constants (SWING_NO_ACTION, SWING_FLIP_NEW_SWING, SWING_FLIP_UPDATED)
newSwingLow (integer): flag to detect changes for swing lows see constants (SWING_NO_ACTION, SWING_FLIP_NEW_SWING, SWING_FLIP_UPDATED)
The R in swingsR() stands for relation where the previously shown types do also contain the relation between the swings of the same swing type (highs and lows respectively).
The same goes for L in swingsL() for length containing the price difference between the current and previous swing point in ticks.
And in the following version swingsLDR() there is also the duration between the current and previous point included.
The parameters for the other functions and type definitions include only the ones, that are needed, the "full" version of the function is described here:
swingsLDR(swingSize, dtbStrength, init, SWING_HISTORY_NUM)
Parameters:
swingSize (int) This parameter defines the size of the swings to look after, meaning higher values will lead to bigger swings
dtbStrength (int) Value between 0 and 100 is a factor (%) to the ATR that is used to calculate equal highs/lows (double tops / bottoms).
Higher values will result in a higher tolerance of price difference between the swings.
init (bool) This value is usually set to false on default.
It has a special use case, where we need to reduce memory usage and calculation time on the script using this library by start calculating at x bars back instead of the beginning of the chart.
In this case, we set init = true on the first bar we start calculating the swings on to perform the correct initialization.
SWING_HISTORY_NUM (int) This is the max number of swings that are stored in the array, so only the last SWING_HISTORY_NUM swings are stored in the array to reduce the memory usage.
New ones remove the oldest ones like in a ring buffer.
This is also influencing the average duration and average swing length.
swingPointLDR
Fields:
x (integer): bar index
y (float): price
hilo (integer): 1 -> high, -1 -> low
length (float): price difference to the previous swing point in ticks
duration (integer): duration difference to the previous swing point in number of bars
relation (integer): see constants RELATION_HIGHER, RELATION_EQUAL, RELATION_LOWER: reelation to the previous swing points of the same type (previous high or previous low respectively)
swingReturnLDR
Fields:
swings (array<swingPointLDR>): array of the last x swing points
newSwingHigh (integer): flag to detect changes for swing highs see constants (SWING_NO_ACTION, SWING_FLIP_NEW_SWING, SWING_FLIP_UPDATED)
newSwingLow (integer): flag to detect changes for swing lows see constants (SWING_NO_ACTION, SWING_FLIP_NEW_SWING, SWING_FLIP_UPDATED)
avSwLength (float): average swing length for the last x swings (depending on the max number of swings)
avSwingDuration (float): average swing duration for the last x swings (depending on the max number of swings)
This library is for calculating non-repainting swings for further calculation on them.
These swings can later be drawn, but drawing is not part of this library, only the calculation.
What do I need to use the library?
You better include the following constants into your script using this library:
int SWING_NO_ACTION = 0
int SWING_FLIP = 1
int SWING_FLIP_NEW_SWING = 2
int SWING_FLIP_UPDATED = 3
int RELATION_HIGHER = 1
int RELATION_EQUAL = 0
int RELATION_LOWER = -1
Choosing the function, that fits your needs
This library contains 4 functions for calculating swings, the difference between them are the data you get for every swing point and additional average values for length and duration:
- swings()
- swingsR()
- swingsL()
- swingsLDR()
The naming scheme of these functions is the following:
The base version swings() is only for the swings containing the following swingPoint type:
swingPoint
Fields:
x (integer): bar index
y (float): price
hilo (integer) 1 -> high, -1 -> low
and the return type:
swingReturn
Fields:
swings (array<swingPoint>): array of the last x swing points
newSwingHigh (integer): flag to detect changes for swing highs see constants (SWING_NO_ACTION, SWING_FLIP_NEW_SWING, SWING_FLIP_UPDATED)
newSwingLow (integer): flag to detect changes for swing lows see constants (SWING_NO_ACTION, SWING_FLIP_NEW_SWING, SWING_FLIP_UPDATED)
The R in swingsR() stands for relation where the previously shown types do also contain the relation between the swings of the same swing type (highs and lows respectively).
The same goes for L in swingsL() for length containing the price difference between the current and previous swing point in ticks.
And in the following version swingsLDR() there is also the duration between the current and previous point included.
The parameters for the other functions and type definitions include only the ones, that are needed, the "full" version of the function is described here:
swingsLDR(swingSize, dtbStrength, init, SWING_HISTORY_NUM)
Parameters:
swingSize (int) This parameter defines the size of the swings to look after, meaning higher values will lead to bigger swings
dtbStrength (int) Value between 0 and 100 is a factor (%) to the ATR that is used to calculate equal highs/lows (double tops / bottoms).
Higher values will result in a higher tolerance of price difference between the swings.
init (bool) This value is usually set to false on default.
It has a special use case, where we need to reduce memory usage and calculation time on the script using this library by start calculating at x bars back instead of the beginning of the chart.
In this case, we set init = true on the first bar we start calculating the swings on to perform the correct initialization.
SWING_HISTORY_NUM (int) This is the max number of swings that are stored in the array, so only the last SWING_HISTORY_NUM swings are stored in the array to reduce the memory usage.
New ones remove the oldest ones like in a ring buffer.
This is also influencing the average duration and average swing length.
swingPointLDR
Fields:
x (integer): bar index
y (float): price
hilo (integer): 1 -> high, -1 -> low
length (float): price difference to the previous swing point in ticks
duration (integer): duration difference to the previous swing point in number of bars
relation (integer): see constants RELATION_HIGHER, RELATION_EQUAL, RELATION_LOWER: reelation to the previous swing points of the same type (previous high or previous low respectively)
swingReturnLDR
Fields:
swings (array<swingPointLDR>): array of the last x swing points
newSwingHigh (integer): flag to detect changes for swing highs see constants (SWING_NO_ACTION, SWING_FLIP_NEW_SWING, SWING_FLIP_UPDATED)
newSwingLow (integer): flag to detect changes for swing lows see constants (SWING_NO_ACTION, SWING_FLIP_NEW_SWING, SWING_FLIP_UPDATED)
avSwLength (float): average swing length for the last x swings (depending on the max number of swings)
avSwingDuration (float): average swing duration for the last x swings (depending on the max number of swings)
릴리즈 노트
v2Added:
new swing function that supports different swing types:
swingsRTyped(swingStyleType, swingSizeFloat, dtbStrength, ignoreInsideBars, useBreakouts, SWING_HISTORY_NUM)
Parameters:
swingStyleType (string) (Standard, Gann, Ticks, Percent)
swingSizeFloat (float) See v1 description
dtbStrength (int) See v1 description
ignoreInsideBars (bool) Special Setting for Gann Swings
useBreakouts (bool) Special Setting for Gann Swings
SWING_HISTORY_NUM (int) See v1 description
릴리즈 노트
v3Added:
new swing function with more information for each point:
- timeStamp
- percent
- volume
- cvd
swingsLDRTPVCTyped(swingStyleType, swingSizeFloat, dtbStrength, ignoreInsideBars, useBreakouts, SWING_HISTORY_NUM, cdHigh, cdLow)
Parameters:
swingStyleType (string)
swingSizeFloat (float)
dtbStrength (int)
ignoreInsideBars (bool)
useBreakouts (bool)
SWING_HISTORY_NUM (int)
cdHigh (float)
cdLow (float)
swingPointLDRTPVC
Fields:
x (series int)
y (series float)
hilo (series int)
relation (series int)
length (series float)
duration (series int)
timeStamp (series int)
percent (series float)
vol (series float)
cumDelta (series float)
swingReturnLDRTPVC
Fields:
swings (array<swingPointLDRTPVC>)
newSwingHigh (series int)
newSwingLow (series int)
avSwLength (series float)
avSwingDuration (series float)
릴리즈 노트
v4Added:
swingsRTypedCustom(swingStyleType, swingSizeFloat, dtbStrength, ignoreInsideBars, useBreakouts, SWING_HISTORY_NUM, highs, lows)
Parameters:
swingStyleType (string)
swingSizeFloat (float)
dtbStrength (int)
ignoreInsideBars (bool)
useBreakouts (bool)
SWING_HISTORY_NUM (int)
highs (float)
lows (float)
릴리즈 노트
v5릴리즈 노트
v6Updated:
swingsLDRTPVCTyped(swingStyleType, swingSizeFloat, dtbStrength, init, ignoreInsideBars, useBreakouts, SWING_HISTORY_NUM, cdHigh, cdLow, useNewSwingCloseConfirmation)
Parameters:
swingStyleType (string)
swingSizeFloat (float)
dtbStrength (int)
init (bool)
ignoreInsideBars (bool)
useBreakouts (bool)
SWING_HISTORY_NUM (int)
cdHigh (float)
cdLow (float)
useNewSwingCloseConfirmation (bool)
릴리즈 노트
v7fix swing size bug
릴리즈 노트
v8fix historic buffer issue
파인 라이브러리
진정한 트레이딩뷰 정신에 따라 작성자는 이 파인 코드를 오픈 소스 라이브러리로 공개하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 건배! 이 라이브러리는 개인적으로 또는 다른 오픈 소스 출판물에서 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰의 적용을 받습니다.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
파인 라이브러리
진정한 트레이딩뷰 정신에 따라 작성자는 이 파인 코드를 오픈 소스 라이브러리로 공개하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 건배! 이 라이브러리는 개인적으로 또는 다른 오픈 소스 출판물에서 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰의 적용을 받습니다.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.