fikira

X

fikira Wizard Zaktualizowano   
Library "X"
a collection of 'special' methods/functions ('special' at the time of conception)
Initial functions includes:
• count of a given number in a given array
• array.get() but option added to use negative index
• sum of all digits until the output < 10
• slope/angle calculation of lines

method count_num_in_array(arr, num)
  counts how many times a given number is present in a given array (0 when not present)
  Namespace types: int
  Parameters:
    arr (int): Array (int, float)
    num (int): Number that needs to be counted (int, float)
  Returns: count of number in array (0 when not present)

method count_num_in_array(arr, num)
  Namespace types: float
  Parameters:
    arr (float)
    num (float)

method get_(arr, idx)
  array.get() but you can use negative index (-1 is last of array, -2 is second last,...)
  Namespace types: int
  Parameters:
    arr (int): Array (int, float, string, bool, label, line, box, color)
    idx (int): Index
  Returns: value/object at index, 'na' if index is outside array

method get_(arr, idx)
  Namespace types: float
  Parameters:
    arr (float)
    idx (int)

method get_(arr, idx)
  Namespace types: string
  Parameters:
    arr (string)
    idx (int)

method get_(arr, idx)
  Namespace types: bool
  Parameters:
    arr (bool)
    idx (int)

method get_(arr, idx)
  Namespace types: label
  Parameters:
    arr (label)
    idx (int)

method get_(arr, idx)
  Namespace types: line
  Parameters:
    arr (line)
    idx (int)

method get_(arr, idx)
  Namespace types: box
  Parameters:
    arr (box)
    idx (int)

method get_(arr, idx)
  Namespace types: color
  Parameters:
    arr (color)
    idx (int)

method sumAllNumbers_till_under_10(num)
  sums all separate digit numbers, it repeats the process until sum < 10
  Namespace types: series int, simple int, input int, const int
  Parameters:
    num (int): Number (int, float)
  Returns: value between 0 and 9

method sumAllNumbers_till_under_10(num)
  Namespace types: series float, simple float, input float, const float
  Parameters:
    num (float)

method XYaxis(width)
  Global function to calculate Yaxis, which is used in calculate_slope() method
  Namespace types: series int, simple int, input int, const int
  Parameters:
    width (int): Amount of bars for reference X-axis
  Returns: Yaxis

method calculate_slope(width, XYratio, Yaxis, x1, y1, x2, y2)
  Returns a normalised slope
  Namespace types: series int, simple int, input int, const int
  Parameters:
    width (int): Amount of bars to calculate height
    XYratio (float): Ratio to calculate height (from width) normalised_slope calculation
    Yaxis (float): Y-axis from XYaxis() method
    x1 (int): x1 of line
    y1 (float): y1 of line
    x2 (int): x2 of line
    y2 (float): y2 of line
  Returns: Tuple of -> slope = price difference per bar
Informacje o Wersji:
v2

Update -> examples
Informacje o Wersji:
v3

DETAILS:

count_num_in_array()
Typically, we use loops for counting how many values an array contains. With count_num_in_array(), we don't use a loop, but the build-in functions array.sort(), array.includes(), array.lastindexof() and array.indexof()
This should give us better performance due to using less loops
-> Seen on chart at right label: 4 is x times in array -> 2, from array (3, 4, 3, 0, 1 , 2, 3, 4)

get_()
array.get() can only be used with a positive index, indexes as -1, -2, ... are not allowed.
For the ones who want to, the get_() function is able to use negative indexes
-> Seen on chart at right label: array.get(-3) -> 2, from array (3, 4, 3, 0, 1 , 2, 3, 4)

sumAllNumbers_till_under_10()
There are people who believe in the power of certain numbers between 0 and 9, they count every digit until they end up with a number between 0 and 9
For example -> count every digit of 123456 -> 1+2+3+4+5+6 = 21, if the sum is higher then 9, repeat -> 2+1 = 3
It was not so easy to create a function which uses as less string manipulation as possible (more string manupulation is greater risk for memory errors)
I finally ended up with sumAllNumbers_till_under_10()
-> Seen on chart at right label: Sum digits of close price until number < 10.


XYaxis(), calculate_slope()
Angle / slope calculation is tricky due to different units in X and Y axis (bar_index vs. price)
Also, certain techniques give very different result when comparing historical data, due to price fluctuations.
With the techniques in XYaxis() and calculate_slope() I tried to create angles / slopes which are rather similar on all bars.
Importantly, XYaxis() always needs to be placed globally, calculate_slope() can be placed locally.
The XYratio can be useful for finetuning, since every user has other habits regarding zooming in on the chart. Zooming in/out doesn't
change bars/price, but it does change our angle perspective. Therefore XYratio can be very useful (for example as input.float(3, '', minval=0, maxval=10))
-> Seen on chart as purple lines + labels with slope/angle
Informacje o Wersji:
v4

Added namespace & description for each overload

Updated:
method count_num_in_array(arr, num)
  counts how many times a given number is present in a given array (0 when not present)
  Namespace types: float
  Parameters:
    arr (float): array
    num (float): Number that needs to be counted (int, float)
  Returns: count of number in array (0 when not present)

method get_(arr, idx)
  array.get() but you can use negative index (-1 is last of array, -2 is second last,...)
  Namespace types: color
  Parameters:
    arr (color): array
    idx (int): Index
  Returns: value/object at index, 'na' if index is outside array

method sumAllNumbers_till_under_10(num)
  sums all separate digit numbers, it repeats the process until sum < 10
  Namespace types: series float, simple float, input float, const float
  Parameters:
    num (float): Number (float)
  Returns: value between 0 and 9
Informacje o Wersji:
v5

Added:

method testMa(iType, src, len)
  Returns a ma with simple int length (for comparison against xma() which can use series int length )
  Namespace types: series string, simple string, input string, const string
  Parameters:
    iType (string): Type of ma (ema, dema, tema, rma, hullMa or linreg)
    src (float): Source
    len (simple int): Length
  Returns: Moving Average

method wma_arr(source, len)
  Returns a wma, used in HullMa (in xma() )
  Namespace types: float
  Parameters:
    source (float): array of source
    len (int): Length
  Returns: WMA

method xma(xma, type, src, len)
  Returns a ma with series int length (for comparison against testMa() which can use simple int length )
  Namespace types: xma
  Parameters:
    xma (xma): UDT object -> xma.new()
    type (string)
    src (float): Source
    len (int): Length
  Returns: Moving Average

xma
  Fields:
    ma1 (series__float)
    ma2 (series__float)
    ma3 (series__float)
    ma4 (series__float)
    xma (series__float)
    aSrc (array__float)
    aXma (array__float)
Informacje o Wersji:
v6 + example testMa and array MA (xma)
Informacje o Wersji:
v7

Added:
isDark()
  Returns a boolean output, true when the chart background is dark, false if otherwise

method round_sig(number, round_to, only_R)
  Returns a rounded number after isolating x significant numbers
  Namespace types: series float, simple float, input float, const float
  Parameters:
    number (float): number to round
    round_to (int): round to x sign. figures
    only_R (bool): if enabled, when number > 1 only the values at the right of decimal point are considered
  Returns: Rounded number to x significant figures
Informacje o Wersji:
v8

Small bugfix in "examples"

LuxAlgo Dev: www.luxalgo.com
PineCoder: www.pinecoders.com

- We cannot control our emotions,
but we can control our keyboard -
Biblioteka Pine

Działając zgodnie z prawdziwym duchem TradingView, autor opublikował ten kod Pine jako bibliotekę o otwartym kodzie źródłowym, aby inni programiści Pine z naszej społeczności mogli go ponownie wykorzystać. Brawa dla niego! Możesz korzystać z tej biblioteki prywatnie lub w innych publikacjach typu open source, ale ponowne wykorzystanie tego kodu w publikacji podlega Regulaminowi.

Wyłączenie odpowiedzialności

Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.

Chcesz skorzystać z tej biblioteki?

Skopiuj poniższy wiersz i wklej go w swoim skrypcie.