PINE LIBRARY

lib_no_delay

Actualizado
Library "lib_no_delay"
This library contains modifications to standard functions that return na before reaching the bar of their 'length' parameter.

That is because they do not compromise speed at current time for correct results in the past. This is good for live trading in short timeframes but killing applications on Monthly / Weekly timeframes if instruments, like in crypto, do not have extensive history (why would you even trade the monthly on a meme coin ... not my decision).

Also, some functions rely on source[1] (value at previous bar), which is not available on bar 1 and therefore cascading to a na value up to the last bar ... which in turn leads to a non displaying indicator and waste of time debugging this)

Anyway ... there you go, let me know if I should add more functions.

sma(source, length)
  Parameters:
    source (float): Series of values to process.
    length (simple int): Number of bars (length).
  Returns: Simple moving average of source for length bars back.

ema(source, length)
  Parameters:
    source (float): Series of values to process.
    length (simple int): Number of bars (length).
  Returns: (float) The exponentially weighted moving average of the source.

rma(source, length)
  Parameters:
    source (float): Series of values to process.
    length (simple int): Number of bars (length).
  Returns: Exponential moving average of source with alpha = 1 / length.

atr(length)
  Function atr (average true range) returns the RMA of true range. True range is max(high - low, abs(high - close[1]), abs(low - close[1])). This adapted version extends ta.atr to start without delay at first bar and deliver usable data instead of na by averaging ta.tr(true) via manual SMA.
  Parameters:
    length (simple int): Number of bars back (length).
  Returns: Average true range.

rsi(source, length)
  Relative strength index. It is calculated using the ta.rma() of upward and downward changes of source over the last length bars. This adapted version extends ta.rsi to start without delay at first bar and deliver usable data instead of na.
  Parameters:
    source (float): Series of values to process.
    length (simple int): Number of bars back (length).
  Returns: Relative Strength Index.
Notas de prensa
v2

Added:
stdev(source, length)
  Parameters:
    source (float)
    length (simple int)

bb(source, length, mult)
  Parameters:
    source (float)
    length (simple int)
    mult (simple float)
Notas de prensa
v3

Added:
wma(source, length)
  Parameters:
    source (float)
    length (simple int)

vwma(source, length)
  Parameters:
    source (float)
    length (simple int)

get_ma(select_ma, source, length)
  Common Moving Average Selection. This function uses only adapted no-delay versions that start without delay at first bar and deliver usable data instead of na.
  Parameters:
    select_ma (simple string): function selector, one of SMA/EMA/RMA/WMA/VWMA
    source (float): Series of values to process.
    length (simple int): Number of bars back (length).
  Returns: selected Moving Average of source

Updated:
stdev(source, length)
  Standard deviation. It is calculated using the ta.stdev(). This adapted version extends ta.stdev to start without delay at first bar and deliver usable data instead of na.
  Parameters:
    source (float): Series of values to process.
    length (simple int): Number of bars back (length).
  Returns: Standard deviation

bb(source, length, mult)
  Bollinger Bands. A Bollinger Band is a technical analysis tool defined by a set of lines plotted two standard deviations (positively and negatively) away from a simple moving average (SMA) of the security's price, but can be adjusted to user preferences. This adapted version extends ta.stdev to start without delay at first bar and deliver usable data instead of na.
  Parameters:
    source (float): Series of values to process.
    length (simple int): Number of bars back (length).
    mult (simple float): Standard deviation factor.
  Returns: Standard deviation
Notas de prensa
v4

Added:
get_signal_once_per_bar(condition)
  Parameters:
    condition (bool): a condition that should only return true once per bar, (e.g. ta.crossover(ema7, ema200))
  Returns: a tuple of [bool triggered_this_bar, bool triggered_this_tick], to allow for accurate plotting (triggered this bar) as well as alert triggering (triggered this tick).
Notas de prensa
v5 added Hull Moving Average Functions

Added:
hma(source, length)
  The hma function returns the Hull Moving Average.
  Parameters:
    source (float): Series of values to process.
    length (simple int): Number of bars back (length).

ehma(source, length)
  The ehma function returns the Exponential Hull Moving Average.
  Parameters:
    source (float): Series of values to process.
    length (simple int): Number of bars back (length).

thma(source, length)
  The thma function returns the Triple Exponential Hull Moving Average.
  Parameters:
    source (float): Series of values to process.
    length (simple int): Number of bars back (length).

Updated:
get_ma(select_ma, source, length)
  Common Moving Average Selection. This function uses only adapted no-delay versions that start without delay at first bar and deliver usable data instead of na.
  Parameters:
    select_ma (simple string): function selector, one of SMA/EMA/RMA/WMA/VWMA/HMA/EHMA/THMA
    source (float): Series of values to process.
    length (simple int): Number of bars back (length).
  Returns: selected Moving Average of source
Notas de prensa
v6 fixed bug in THMA calculation
Notas de prensa
v7 performance improvement of HMA functions
Notas de prensa
v8 using enums for get_ma

Updated:
get_ma(select_ma, source, length)
  Common Moving Average Selection. This function uses only adapted no-delay versions that start without delay at first bar and deliver usable data instead of na.
  Parameters:
    select_ma (simple MovingAverage): function selector, one of SMA/EMA/RMA/WMA/VWMA/HMA/EHMA/THMA
    source (float): Series of values to process.
    length (simple int): Number of bars back (length).
  Returns: selected Moving Average of source
Notas de prensa
v9
  • removed label that caused 'side effects' error on request security call
  • added HTF example
ATRatr2MATHmoving_averagerma2rsi2sma2techindicator

Biblioteca Pine

Siguiendo fielmente el espíritu TradingView, el autor ha publicado este código Pine como una biblioteca de código abierto, permitiendo que otros programadores de Pine en nuestra comunidad lo utilicen de nuevo. ¡Olé por el autor! Puede utilizar esta biblioteca de forma privada o en otras publicaciones de código abierto, pero tenga en cuenta que la reutilización de este código en una publicación se rige por las Normas internas.

Exención de responsabilidad