Library "MovingAveragesLibrary" This is a library allowing one to select between many different Moving Average formulas to smooth out any float variable.
You can use this library to apply a Moving Average function to any series of data as long as your source is a float.
The default application would be for applying Moving Averages onto your chart. However, the scope of this library is beyond that. Any indicator or strategy you are building can benefit from this library.
You can apply different types of smoothing and moving average functions to your indicators, momentum oscillators, average true range calculations, support and resistance zones, envelope bands, channels, and anything you can think of to attempt to smooth out noise while finding a delicate balance against lag.
If you are developing an indicator, you can use the 'ave_func' to allow your users to select any Moving Average for any function or variable by creating an input string with the following structure:
Where you would add after options the strings I have included for you at the top of the PineScript for your convenience.
Then for the output you desire, simply call 'ave_func' like so:
ma = ave_func(source, length, i_ma_type)
Now the plotted Moving Average will be the same as what you or your users select from the Input.
ema(src, len) Exponential Moving Average. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: Float value.
sma(src, len) Simple Moving Average. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: Float value.
rma(src, len) Relative Moving Average. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: Float value.
wma(src, len) Weighted Moving Average. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: Float value.
dv2(len) Donchian V2 function. Parameters: len: Lookback length to use. Returns: Open + Close / 2 for the selected length.
ModFilt(src, len) Modular Filter smoothing function. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: Float value.
EDSMA(src, len) Ehlers Dynamic Smoothed Moving Average. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: EDSMA smoothing.
dema(x, t) Double Exponential Moving Average. Parameters: x: Series to use ('close' is used if no argument is supplied). t: Lookback length to use. Returns: DEMA smoothing.
tema(src, len) Triple Exponential Moving Average. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: TEMA smoothing.
smma(x, t) Smoothed Moving Average. Parameters: x: Series to use ('close' is used if no argument is supplied). t: Lookback length to use. Returns: SMMA smoothing.
vwma(x, t) Volume Weighted Moving Average. Parameters: x: Series to use ('close' is used if no argument is supplied). t: Lookback length to use. Returns: VWMA smoothing.
hullma(x, t) Hull Moving Average. Parameters: x: Series to use ('close' is used if no argument is supplied). t: Lookback length to use. Returns: Hull smoothing.
covwma(x, t) Coefficient of Variation Weighted Moving Average. Parameters: x: Series to use ('close' is used if no argument is supplied). t: Lookback length to use. Returns: COVWMA smoothing.
frama(x, t) Fractal Reactive Moving Average. Parameters: x: Series to use ('close' is used if no argument is supplied). t: Lookback length to use. Returns: FRAMA smoothing.
kama(x, t) Kaufman's Adaptive Moving Average. Parameters: x: Series to use ('close' is used if no argument is supplied). t: Lookback length to use. Returns: KAMA smoothing.
donchian(len) Donchian Calculation. Parameters: len: Lookback length to use. Returns: Average of the highest price and the lowest price for the specified look-back period.
tma(src, len) Triangular Moving Average. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: TMA smoothing.
VAMA(src, len) Volatility Adjusted Moving Average. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: VAMA smoothing.
Jurik(src, len) Jurik Moving Average. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: JMA smoothing.
MCG(src, len) McGinley smoothing. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: McGinley smoothing.
zlema(series, length) Zero Lag Exponential Moving Average. Parameters: series: Series to use ('close' is used if no argument is supplied). length: Lookback length to use. Returns: ZLEMA smoothing.
xema(src, len) Optimized Exponential Moving Average. Parameters: src: Series to use ('close' is used if no argument is supplied). len: Lookback length to use. Returns: XEMA smoothing.
EhlersSuperSmoother(src, lower) Ehlers Super Smoother. Parameters: src: Series to use ('close' is used if no argument is supplied). lower: Smoothing value to use. Returns: Ehlers Super smoothing.
EhlersEmaSmoother(sig, smoothK, smoothP) Ehlers EMA Smoother. Parameters: sig: Series to use ('close' is used if no argument is supplied). smoothK: Lookback length to use. smoothP: Smothing value to use. Returns: Ehlers EMA smoothing.
ave_func(in_src, in_len, in_type) Returns the source after running it through a Moving Average function. Parameters: in_src: Series to use ('close' is used if no argument is supplied). in_len: Lookback period to be used for the Moving Average function. in_type: Type of Moving Average function to use. Must have a string input to select the options from that MUST match the type-casing in the function below. Returns: The source as a float after running it through the Moving Average function.
In pieno spirito TradingView, l'autore ha pubblicato questo codice Pine come libreria open-source in modo che altri programmatori Pine della nostra comunità possano riutilizzarlo. Un saluto all'autore! È possibile utilizzare questa libreria privatamente o in altre pubblicazioni open-source, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento.
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.