Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © boitoki
- //@version=5
- // @description TODO: This library is a package of various MAs.
- library("ma_function")
- kama(xPrice, Length)=>
- xvnoise = math.abs(xPrice - xPrice[1])
- nfastend = 0.666
- nslowend = 0.0645
- nsignal = math.abs(xPrice - xPrice[Length])
- nnoise = math.sum(xvnoise, Length)
- nefratio = (nnoise != 0 ? nsignal / nnoise : 0)
- nsmooth = math.pow(nefratio * (nfastend - nslowend) + nslowend, 2)
- float nAMA = na
- nAMA := nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))
- zlema (src, length) =>
- zxLag = length/2==math.round(length/2) ? length/2 : (length - 1) / 2
- zxEMAData = (src + (src - src[zxLag]))
- ZLEMA = ta.ema(zxEMAData, length)
- mav (source, length) =>
- ((ta.sma(source, length)[1]*(length-1)) + source) / length
- dema (src, len) =>
- e = ta.ema(src, len)
- 2 * e - ta.ema(e, len)
- tema (src, len) =>
- e = ta.ema(src, len)
- 3 * (e - ta.ema(e, len)) + ta.ema(ta.ema(e, len), len)
- hma (src, len) =>
- ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len)))
- tma (source, length) =>
- ta.sma(ta.sma(source, math.ceil(length / 2)), math.floor(length / 2) + 1)
- // @function This function provides the MA specified in the argument.
- // @param name MA's name
- // @param source Source value
- // @param length Look back periods
- // @returns Ma value
- export ma_function (simple string name, float source, simple int length) =>
- switch name
- 'SMA' => ta.sma(source, length)
- 'EMA' => ta.ema(source, length)
- 'RMA' => ta.rma(source, length)
- 'WMA' => ta.wma(source, length)
- 'LSMA' => ta.linreg(source, length, 0)
- 'ALMA' => ta.alma(source, length, 0.85, 6)
- 'TMA' => tma(source, length)
- 'DEMA' => dema(source, length)
- 'TEMA' => tema(source, length)
- 'MAV' => mav(source, length)
- 'KAMA' => kama(source, length)
- 'ZZLEMA' => zlema(source, length)
- 'HMA' => hma(source, length)
- plot(ma_function('SMA', close, 10), color=color.red)
- plot(ma_function('MAV', close, 10), color=color.orange)
- plot(ma_function('KAMA', close, 10), color=color.blue)
- plot(ma_function('ZZLEMA', close, 10), color=color.green)
Advertisement
Add Comment
Please, Sign In to add comment