Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- study(title="MA Ribbon R1 by JustUncleL", shorttitle="MA_RIBBON R1", overlay = true)
- //
- // Revision: R1
- // Revision Author: JustUncleL
- //
- // Description:
- //
- // References:
- //
- // Modifications:
- // R1 - Original
- //
- // Use Alternate Anchor TF for MAs
- anchor = input(0,minval=0,maxval=1440,title="Use Alternate Anchor TimeFrame (0=none, max=1440mins)")
- // Fast MA - type, length
- type1 = input(defval="EMA", title="Fast MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
- len1 = input(defval=8, title="Fast - Length", minval=1)
- // Medium MA - type, length
- type2 = input(defval="EMA", title="Medium MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
- len2 = input(defval=21, title="Medium - Length", minval=2)
- //
- ma_src = input(close,title="Source")
- sBars = input(false,title="Show Coloured Bars")
- // - INPUTS END
- // - FUNCTIONS
- // Returns MA input selection variant, default to SMA if blank or typo.
- variant(type, src, len) =>
- v1 = sma(src, len) // Simple
- v2 = ema(src, len) // Exponential
- v3 = wma(src, len) // Weighted
- v4 = vwma(src, len) // Volume Weighted
- v5 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len // Smoothed
- v6 = 2 * v2 - ema(v2, len) // Double Exponential
- v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
- v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) // Hull
- v11 = sma(sma(src,len),len) // Triangular
- // SuperSmoother filter
- // © 2013 John F. Ehlers
- a1 = exp(-1.414*3.14159 / len)
- b1 = 2*a1*cos(1.414*3.14159 / len)
- c2 = b1
- c3 = (-a1)*a1
- c1 = 1 - c2 - c3
- v9 = c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
- // Zero Lag Exponential
- ema1 = ema(src, len)
- ema2 = ema(ema1, len)
- v10 = ema1+(ema1-ema2)
- // return variant, defaults to SMA if input invalid.
- type=="EMA"?v2 : type=="WMA"?v3 : type=="VWMA"?v4 : type=="SMMA"?v5 : type=="DEMA"?v6 : type=="TEMA"?v7 : type=="HullMA"?v8 : type=="SSMA"?v9 : type=="ZEMA"?v10 : type=="TMA"? v11: v1
- // - FUNCTIONS END
- // Make sure we have minimum channel spread.
- Length2_ = (len2-len1)<1?len1+1:len2
- // If this is 5min or less Time Frame select EMAs
- mult = not isintraday or anchor==0 or interval<=0 or interval>=anchor? 1 : round(anchor/interval)>1? round(anchor/interval) : 1
- Length1 = mult==1 ? len1 : (len1*mult)
- Length2 = mult==1 ? Length2_ : (Length2_*mult)
- // Get the two MAs
- ma1 = variant(type1,ma_src, Length1)
- ma2 = variant(type2,ma_src, Length2)
- //Plot the Ribbon
- ma1_=plot( ma1,color=rising(ma1,2)?green:red,linewidth=2,transp=20,title="ma1")
- ma2_=plot( ma2,color=rising(ma2,2)?green:red,linewidth=2,transp=20,title="ma2")
- fcolor = ma1>ma2?green:red
- fill(ma1_,ma2_,color=fcolor,transp=80)
- bc = not sBars? na : close>ma1 and close>ma2? green: close<ma1 and close<ma2? red : yellow
- barcolor(bc,title="Bar Colours")
- //eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement