bilsebub

swinglibrary

bilsebub מעודכן   
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:
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)
הערות שחרור:
v2

Added:
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
ספריית Pine

ברוח TradingView אמיתית, המחבר פרסם את קוד Pine זה כספריית קוד פתוח כך שמתכנתי Pine אחרים מהקהילה שלנו יוכלו לעשות בו שימוש חוזר. כל הכבוד למחבר! אתה יכול להשתמש בספרייה זו באופן פרטי או בפרסומים אחרים בקוד פתוח, אך השימוש החוזר בקוד זה בפרסום כפוף לכללי הבית.

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.

רוצה להשתמש בספרייה זו?

העתק את השורה הבאה והדבק אותה בסקריפט שלך.