PINE LIBRARY
Aggiornato

ma_library

28
Title: Library: Advanced Moving Average Collection

Description:
This library provides a comprehensive set of Moving Average algorithms, ranging from standard filters (SMA, EMA) to adaptive trendlines (KAMA, FRAMA) and experimental smoothers (ALMA, JMA).
It has been fully optimized for Pine Script v6, ensuring efficient execution and strict robustness against na (missing) values. Unlike standard implementations that propagate na values, these functions dynamically recalculate weights to maintain continuity in disjointed datasets.

🧩 Library Features

Robustness: Non-recursive filters ignore na values within the lookback window. Recursive filters maintain state to prevent calculation breaks.

Optimization: Logic updated to v6 standards, utilizing efficient loops and var persistence.

Standardization: All functions utilize a consistent f_ prefix and standardized parameters for easy integration.

Scope: Contains over 35 different smoothing algorithms.

📊 Input Requirements

Source (src): The data series to smooth (usually close, hl2, etc.).

Length (length): The lookback period (must be a simple int).

Specifics: Some adaptive MAs (like f_evwma) require volume data, while others (like f_alma) require offset/sigma settings.

🛠️ Integration Example

You can import the library and call functions directly, or use the built-in f_selector to create dynamic inputs for your users.

code
Pine
download
content_copy
expand_less
//version=6
indicator("MA Library Demo", overlay=true)

// Import the library
import YourUsername/ma_/1 as ma

// --- Example 1: Direct Function Call ---
// calculating Jurik Moving Average (JMA)
float jma_val = ma.f_jma(close, 14)
plot(jma_val, "JMA", color=color.yellow, linewidth=2)

// --- Example 2: User Selector ---
// Allowing the user to choose the MA type via settings
string selected_type = input.string("ALMA", "MA Type", options=["SMA", "EMA", "ALMA", "KAMA", "ZLEMA", "VIDYA"])
int length = input.int(20, "Length")

// Using the generic selector function
float dynamic_ma = ma.f_selector(close, length, selected_type)

plot(dynamic_ma, "Dynamic MA", color=color.aqua)
📋 Included Algorithms

The following methods are available (prefixed with f_):

Standard: SMA, EMA, WMA, VWMA, RMA

Adaptive: KAMA (Kaufman), FRAMA (Fractal), VIDYA (Chande/VARMA), VAMA (Vol. Adjusted)

Low Lag: ZLEMA (Zero Lag), HMA (Hull), JMA (Jurik), DEMA, TEMA

Statistical/Math: LSMA (Least Squares), GMMA (Geometric Mean), FLSMA (Fisher Least Squares)

Advanced/Exotic:

ALMA (Arnaud Legoux)

EIT (Ehlers Instantaneous Trend)

ESD (Ehlers Simple Decycler)

AHMA (Ahrens)

BMF (Blackman Filter)

CMA (Corrective)

DSWF (Damped Sine Wave)

EVWMA (Elastic Vol. Weighted)

HCF (Hybrid Convolution)

LMA (Leo)

MD (McGinley Dynamic)

MF (Modular Filter)

MM (Moving Median)

QMA (Quick)

RPMA (Repulsion)

RSRMA (Right Sided Ricker)

SMMA (Smoothed)

SSMA (Shapeshifting)

SWMA (Sine Weighted)

TMA (Triangular)

TSF (True Strength Force)

VBMA (Variable Band)
Note di rilascio
Title: Library: Advanced Moving Average Collection

Description:
This library provides a comprehensive set of Moving Average algorithms, fully optimized for Pine Script v6. It goes beyond standard libraries by implementing strict Robustness Protocols and Dynamic Length Support.

Every function in this library has been written from scratch to handle na (missing) values intelligently. Unlike built-in ta.* functions which often propagate na values (breaking the indicator line), these algorithms dynamically recalculate weights or maintain state to ensure continuity in disjointed datasets.

🚀 Key Features

Strict Robustness:

Window-based MAs (SMA, WMA, VWMA, etc.): Use efficient loops to strictly ignore na values within the lookback period, re-normalizing weights on the fly.

Recursive MAs (EMA, RMA, JMA, etc.): Maintain their internal state. If the current source is na, the MA holds its previous value rather than breaking the series.

Function Overloading (Dynamic Lengths):

Every export function includes an overload to accept series int length.

This allows you to pass variable lengths (e.g., based on volatility, cycle period, or volume) instead of just fixed constant integers.

Custom Implementations:

Includes custom, robust versions of VWMA and RMA, replacing the standard ta.vwma and ta.rma to ensure behavior consistency across the entire library.

📊 Input Requirements

Source (src): The data series to smooth.

Length (length): Supports both simple int (fixed) and series int (dynamic/variable).

Volume (vol): Required for volume-weighted calculations (VWMA, EVWMA).

🛠️ Integration Example
code
Pine
download
content_copy
expand_less
//version=6
indicator("MA Library Demo", overlay=true)

// Import the library
import YourUsername/ma_/1 as ma

// --- Example 1: Robust VWMA (Custom) ---
// Uses the custom f_vwma which handles missing volume/price data gracefully
float my_vwma = ma.f_vwma(close, 20, volume)
plot(my_vwma, "Robust VWMA", color=color.orange)

// --- Example 2: Dynamic Length Support ---
// Calculating a length based on volatility (ATR)
int dynamic_len = int(math.max(10, 50 - ta.atr(14) * 100))

// The library accepts this 'series int' length automatically due to overloading
float adaptive_sma = ma.f_sma(close, dynamic_len)
plot(adaptive_sma, "Dynamic SMA", color=color.aqua)
📋 Included Algorithms

All functions are prefixed with f_ and support dynamic lengths:

Standard (Robust): SMA, EMA, WMA, RMA (Wilder's), VWMA (Vol. Weighted)

Adaptive: KAMA (Kaufman), FRAMA (Fractal), VIDYA (Chande/VARMA), VAMA (Vol. Adjusted)

Low Lag: ZLEMA (Zero Lag), HMA (Hull), JMA (Jurik), DEMA, TEMA

Statistical/Math: LSMA (Least Squares), GMMA (Geometric Mean), FLSMA (Fisher Least Squares)

Advanced/Exotic:

ALMA (Arnaud Legoux)

EIT (Ehlers Instantaneous Trend)

ESD (Ehlers Simple Decycler)

AHMA (Ahrens)

BMF (Blackman Filter)

CMA (Corrective)

DSWF (Damped Sine Wave)

EVWMA (Elastic Vol. Weighted)

HCF (Hybrid Convolution)

LMA (Leo)

MD (McGinley Dynamic)

MF (Modular Filter)

MM (Moving Median)

QMA (Quick)

RPMA (Repulsion)

RSRMA (Right Sided Ricker)

SMMA (Smoothed)

SSMA (Shapeshifting)

SWMA (Sine Weighted)

TMA (Triangular)

TSF (True Strength Force)

VBMA (Variable Band)

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.