PINE LIBRARY
업데이트됨 lib_no_delay

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.
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.
릴리즈 노트
v2Added:
stdev(source, length)
Parameters:
source (float)
length (simple int)
bb(source, length, mult)
Parameters:
source (float)
length (simple int)
mult (simple float)
릴리즈 노트
v3Added:
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
릴리즈 노트
v4Added:
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).
릴리즈 노트
v5 added Hull Moving Average FunctionsAdded:
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
릴리즈 노트
v6 fixed bug in THMA calculation릴리즈 노트
v7 performance improvement of HMA functions릴리즈 노트
v8 using enums for get_maUpdated:
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
릴리즈 노트
v9 - removed label that caused 'side effects' error on request security call
- added HTF example
릴리즈 노트
v10 update to pine v6릴리즈 노트
v11 added no delay versions of ta.stoch, ta.macd, ta.stc and a speed optimized version of ta.stdevAdded:
stdev_fast(src, length)
Parameters:
src (float)
length (simple int)
macd_custom(source, fast, slow, signal, osc_ma, sig_ma)
MACD (moving average convergence/divergence). It is supposed to reveal changes in the strength, direction, momentum, and duration of a trend in a stock's price.\n\nReturns\nTuple of three MACD series: MACD line, signal line and histogram line. This adapted version extends ta.macd to start without delay at first bar and deliver usable data instead of na. It also allows to use custom moving average algorithms
Parameters:
source (float): (simple int) optional
fast (simple int): (simple int) optional
slow (simple int): (simple int) optional
signal (simple int): (simple int) optional
osc_ma (simple MovingAverage): (simple MovingAverage) optional select a custom function for the MACD calculation
sig_ma (simple MovingAverage): (simple MovingAverage) optional select a custom function for the MACD signal calculation
macd(source, fast, slow, signal)
MACD (moving average convergence/divergence). It is supposed to reveal changes in the strength, direction, momentum, and duration of a trend in a stock's price.\n\nReturns\nTuple of three MACD series: MACD line, signal line and histogram line. This adapted version extends ta.macd to start without delay at first bar and deliver usable data instead of na.
Parameters:
source (float): (simple int) optional
fast (simple int): (simple int) optional
slow (simple int): (simple int) optional
signal (simple int): (simple int) optional
stoch(source, h, l, length)
Stochastic. It is calculated by a formula: 100 * (close - lowest(low, length)) / (highest(high, length) - lowest(low, length)). This adapted version extends ta.stoch to start without delay at first bar and deliver usable data instead of na.
Parameters:
source (float)
h (float)
l (float)
length (int)
stc(source, fast, slow, cycle, d1, d2)
Calculates the value of the Schaff Trend Cycle indicator. This adapted version extends ta.stc to start without delay at first bar and deliver usable data instead of na.
Parameters:
source (float): (series int/float) optional Series of values to process. (default: close)
fast (simple int): (simple int) optional Length for the MACD fast smoothing parameter calculation. (default: 26)
slow (simple int): (simple int) optional Length for the MACD slow smoothing parameter calculation. (default: 50)
cycle (simple int): (simple int) optional Number of bars for the Stochastic values (length). (default: 12)
d1 (simple int): (simple int) optional Length for the initial %D smoothing parameter calculation. (default: 3)
d2 (simple int): (simple int) optional Length for the final %D smoothing parameter calculation. (default: 3)
Returns: (float) The oscillator value.
stc_fast(source, fast, slow, cycle, scale)
Returns the Schaff Trend Cycle (STC) (similar to MACD, but faster). This adapted version extends ta.stc to start without delay at first bar and deliver usable data instead of na.
Parameters:
source (float): (series int/float) optional allows to calculate STC for another symbol or timeframe by passing its close series (obtain with request.security) (default: close)
fast (simple int): (simple int) optional fast moving average length (default: 23)
slow (simple int): (simple int) optional slow moving average length (default: 50)
cycle (simple int): (simple int) optional stochastic length (default: 10)
scale (simple float): (simple float) optional if you want to tweak the speed the trend changes. (default: 0.5)
Returns: float stc
릴리즈 노트
v12 added directional movement indexAdded:
dmi(di_length, adx_smoothing)
The dmi function returns the directional movement index. This adapted version extends ta.dmi to start without delay at first bar and deliver usable data instead of na (will converge with builtin version at difference of max 0.1 amongst all values).
Parameters:
di_length (simple int)
adx_smoothing (simple int)
Returns: Tuple of three DMI series: Positive Directional Movement (+DI), Negative Directional Movement (-DI) and Average Directional Movement Index (ADX).
릴리즈 노트
v13 improved sma and wma on first bar(s) , added mean deviation, fixed stdev on first bar(s), added missing display toggle for DMIAdded:
dev(source, length)
Measure of difference (averaged) between the series and it's ta.sma. This adapted version extends ta.dev 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: Deviation of source for length bars back.
릴리즈 노트
v14 fixed bug in dev, allowing for float length in ema릴리즈 노트
v15 added Directional Volume IndexAdded:
dvi(di_length, advx_smoothing)
The dvi function returns the directional volume index (DVI). This adapted version uses volume as base of the directional index (DI), unlike the Directional Movement Index (DMI) which uses price.
Parameters:
di_length (simple int): lookback period for the average volume for comparison with the directional volume (DV) to calculate the directional volume index (DVI)
advx_smoothing (simple int): smoothing distance for the average directional volume index (ADVX)
Returns: Tuple of three DVI series: Positive Directional Movement (+DVI), Negative Directional Movement (-DVI) and Average Directional Movement Index (ADVX).
Updated:
dmi(di_length, adx_smoothing)
The dmi function returns the directional movement index (DMI). This adapted version extends ta.dmi to start without delay at first bar and deliver usable data instead of na (will converge with builtin version at difference of max 0.1 amongst all values).
Parameters:
di_length (simple int): lookback period for the average true range (ATR) for comparison with the current true range (TR) to calculate the directional index (DI)
adx_smoothing (simple int): smoothing distance for the average directional index (ADX)
Returns: Tuple of three DMI series: Positive Directional Movement (+DI), Negative Directional Movement (-DI) and Average Directional Movement Index (ADX).
릴리즈 노트
v16 fixed a rounding error in thma for length < 6릴리즈 노트
v17 added linreg and linreg_values (including slope and intercept to draw a regression line over last 'length' bars (with optional offset)Added:
linreg_values(source, length, offset)
Linear regression curve. A line that best fits the prices specified over a user-defined time period. It is calculated using the least squares method. The result of this function is calculated using the formula: linreg = intercept + slope * (length - 1 - offset), where intercept and slope are the values calculated with the least squares method on source series. This adapted version extends ta.linreg 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)
offset (simple int): Offset.
Returns: a tuple of [regression_line, slope, intercept] (for a straight regression line over a measured amount of data (bars) use x1: bar_index[length+offset] y1: intercept + slope * bar_index[length+offset] x2: bar_index[offset] y2: regression_line)
linreg(source, length, offset)
Linear regression curve. A line that best fits the prices specified over a user-defined time period. It is calculated using the least squares method. The result of this function is calculated using the formula: linreg = intercept + slope * (length - 1 - offset), where intercept and slope are the values calculated with the least squares method on source series. This adapted version extends ta.linreg 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).
offset (simple int): Offset. (according to default implementation this using offset bar_indexes for current value calculation ... not sure that's intended, expected behavior would be an x shift so I can use it to calculate a regression line for a past range of candles -> use linreg_values for that)
Returns: The regression line (to receive slope and intercept values as well, call linreg_values)
릴리즈 노트
v18 updated examples릴리즈 노트
v19 added variance / variance_fast파인 라이브러리
진정한 트레이딩뷰 정신에 따라 작성자는 이 파인 코드를 오픈 소스 라이브러리로 공개하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 건배! 이 라이브러리는 개인적으로 또는 다른 오픈 소스 출판물에서 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰의 적용을 받습니다.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
파인 라이브러리
진정한 트레이딩뷰 정신에 따라 작성자는 이 파인 코드를 오픈 소스 라이브러리로 공개하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 건배! 이 라이브러리는 개인적으로 또는 다른 오픈 소스 출판물에서 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰의 적용을 받습니다.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.