PINE LIBRARY
Zaktualizowano MovingAverages

Library "MovingAverages"
A collection of O(1) numerically stable moving averages that support anchors and fractional lengths up to 100k bars.
Pine Script has a robust set of moving averages suitable for a majority of cases, making these alternatives useful only if you need anchoring, fractional lengths, or more than 5k bars. Included are the classic SMA, EMA, RMA, WMA, VWMA, VWAP, HMA, SWMA, Linear Regression, and ATR. The common parameters are:
ANCHORING
This is the libraries first and primary benefit. Akin to the built-in VWAP, anchoring is managed by passing a series bool into the function. For sessional anchoring, the included new_session() returns true on the first bar of intraday sessions, and stabilize_anchor() helps reduce near-anchor volatility. When no length is provided, the series continues indefinitely until a new anchor is set. Values during the warmup period are returned.
Pine Script®
STREAMING UPDATES
Rather than naively using loops to recalculate the whole series on each bar, linear interpolation (aka. "lerping") is used to incrementally update and translate between values. The canonical formula being: a + (b - a) * t. This formula is effectively an EMA, but it's applicable to nearly all averaging equations. Coupling this technique with a circular buffer captures 3 of the 5 benefits this library offers: O(1) computation, fractional lengths, and 100k bars.
NUMERIC STABILITY
The last benefit is how the library minimizes floating point errors. When possible, Pine Script functions are used for mathematical parity. Otherwise Kahan summation error compensation is used when calculating an average. Not only does this keep custom implementations stable throughout the series, it also helps keep them within 1.0e-10 of the built-in functions. Automatically defaulting to the built-in functions can be disabled by setting parity to false.
A collection of O(1) numerically stable moving averages that support anchors and fractional lengths up to 100k bars.
Pine Script has a robust set of moving averages suitable for a majority of cases, making these alternatives useful only if you need anchoring, fractional lengths, or more than 5k bars. Included are the classic SMA, EMA, RMA, WMA, VWMA, VWAP, HMA, SWMA, Linear Regression, and ATR. The common parameters are:
- source (float): Series of values to process.
- length (simple float): Number of bars. Optional.
- anchor (bool): The condition that triggers a calculation reset. Optional.
- parity (simple bool): Sets if built-in function should be used. Optional.
ANCHORING
This is the libraries first and primary benefit. Akin to the built-in VWAP, anchoring is managed by passing a series bool into the function. For sessional anchoring, the included new_session() returns true on the first bar of intraday sessions, and stabilize_anchor() helps reduce near-anchor volatility. When no length is provided, the series continues indefinitely until a new anchor is set. Values during the warmup period are returned.
source = close
length = 9.5
anchor = ma.new_session() // Assumes library is imported as "ma"
swma = ma.swma(source, length, anchor).stabilize_anchor(source, length, anchor)
STREAMING UPDATES
Rather than naively using loops to recalculate the whole series on each bar, linear interpolation (aka. "lerping") is used to incrementally update and translate between values. The canonical formula being: a + (b - a) * t. This formula is effectively an EMA, but it's applicable to nearly all averaging equations. Coupling this technique with a circular buffer captures 3 of the 5 benefits this library offers: O(1) computation, fractional lengths, and 100k bars.
NUMERIC STABILITY
The last benefit is how the library minimizes floating point errors. When possible, Pine Script functions are used for mathematical parity. Otherwise Kahan summation error compensation is used when calculating an average. Not only does this keep custom implementations stable throughout the series, it also helps keep them within 1.0e-10 of the built-in functions. Automatically defaulting to the built-in functions can be disabled by setting parity to false.
Informacje o Wersji
v2Removed thumbnail code form library.
Biblioteka Pine
W zgodzie z duchem TradingView autor opublikował ten kod Pine jako bibliotekę open-source, aby inni programiści Pine z naszej społeczności mogli go ponownie wykorzystać. Ukłony dla autora. Można korzystać z tej biblioteki prywatnie lub w innych publikacjach open-source, jednak ponowne wykorzystanie tego kodu w publikacjach podlega Zasadom serwisu.
Discord: discord.gg/bPAPhwUeud
Website: liquid-trader.com
Website: liquid-trader.com
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Biblioteka Pine
W zgodzie z duchem TradingView autor opublikował ten kod Pine jako bibliotekę open-source, aby inni programiści Pine z naszej społeczności mogli go ponownie wykorzystać. Ukłony dla autora. Można korzystać z tej biblioteki prywatnie lub w innych publikacjach open-source, jednak ponowne wykorzystanie tego kodu w publikacjach podlega Zasadom serwisu.
Discord: discord.gg/bPAPhwUeud
Website: liquid-trader.com
Website: liquid-trader.com
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.