JayRogers

MTF Standard Deviation Bands Medley

Description:
  • A veritable banquet of MA basis calculations to choose from.
  • 3 separate sets of bands to tinker with.
  • Optional toggle-able time resolution.
  • Optional breakout shapes with their own separate multiplier.
  • A fart, some love and kisses. ...and I may have dribbled a bit. Sorry.

Go on. Have a tinker. You know you want to.
Usuń z Ulubionych Skryptów Dodaj do Ulubionych Skryptów
//@version=2

study(title="MTF Standard Deviation Bands Medley", shorttitle="SDBM", overlay=true)

// Revision:    1
// Author:      JayRogers
//
// Description:
//  - A veritable banquet of MA basis calculations to choose from.
//  - 3 seperate sets of bands to tinker with.
//  - Optional breakout shapes with their own seperate multiplier.
//  - A fart, some love and kisses. ...and I may have dribbled a bit. Sorry.

// - INPUTS START
useRes  = input(defval=false, title="Use Fixed Resolution?")
setRes  = input(defval="15", title="Select Resolution", type=resolution)
maType  = input(defval="VWMA", title="Basis Calculation: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, LSMA ( case sensitive )", type=string)
maSrc   = input(defval=close, title="Source", type=source)
maLen   = input(defval=20, title="Period", minval=1)
maOff   = input(defval=0, title="Offset", minval=0)
multA   = input(defval=2, title="Deviation A", minval=0, step=0.05)
multB   = input(defval=2.5, title="Deviation B", minval=0, step=0.05)
multC   = input(defval=3, title="Deviation C", minval=0, step=0.05)
showB   = input(defval=false, title="Disable Bands B?")
showC   = input(defval=false, title="Disable Bands C?")
multBr  = input(defval=3.5, title="Breakout Deviation", minval=0, step=0.05)
highBr  = input(defval=high, title="Break Up Source", type=source)
lowBr   = input(defval=low, title="Break Down Source", type=source)
showBr  = input(defval=false, title="Enable Breakout Markers?")
lsmaOff = input(defval=4, title="Offset for LSMA", minval=0)
// - INPUTS END

// - FUNCTIONS
// Returns chosen MA input calculation, default to SMA if blank or typo.
variant(type, src, len, lsma) =>
    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
    v9 = linreg(src, len, lsma)                                         // Least Squares
    type=="EMA"?v2 : type=="WMA"?v3 : type=="VWMA"?v4 : type=="SMMA"?v5 : type=="DEMA"?v6 : type=="TEMA"?v7 : type=="HullMA"?v8 : type=="LSMA"?v9 : v1
// Return selected resolution series, or use current
reso(exp, use, res) => use ? security(tickerid, res, exp) : exp
// - FUNCTIONS END

// - SERIES VARIABLES
// Basis and deviation
basis       = reso(variant(maType, maSrc[maOff], maLen, lsmaOff), useRes, setRes)
devA        = multA * reso(stdev(maSrc, maLen), useRes, setRes)
devB        = multB * reso(stdev(maSrc, maLen), useRes, setRes)
devC        = multC * reso(stdev(maSrc, maLen), useRes, setRes)
// Breakouts
devBreak    = multBr * reso(stdev(maSrc, maLen), useRes, setRes)
highBreak   = showBr and highBr >= (basis + devBreak)
lowBreak    = showBr and lowBr <= (basis - devBreak)
// - SERIES VARIABLES END

// - PLOTTING
// Basis
plot(basis, title="basis", color=#999999, linewidth=2, transp=50)
// Upper bands
plot(basis + devA, title="Upper Band A", color=#006666, linewidth=2, transp=50)
plot(showB ? na : (basis + devB), title="Upper Band B", color=#009999, linewidth=2, transp=50)
plot(showC ? na : (basis + devC), title="Upper Band C", color=#00CCCC, linewidth=2, transp=50)
// Lower bands
plot(basis - devA, title="Lower band A", color=#006666, linewidth=2, transp=50)
plot(showB ? na : (basis - devB), title="Lower band B", color=#009999, linewidth=2, transp=50)
plot(showC ? na : (basis - devC), title="Lower band C", color=#00CCCC, linewidth=2, transp=50)
// Breakout shapes
plotshape(highBreak, title="High Break", style=shape.diamond, location=location.abovebar, size=size.tiny, color=#FF0000, transp=50)
plotshape(lowBreak, title="Low Break", style=shape.diamond, location=location.belowbar, size=size.tiny, color=#00FF00, transp=50)
// - PLOTTING END
Thanks a lot Jay. I really like these bands. Is there a way to change the color of the top, middle and bottom bands as they change direction?
Odpowiedź
Strona główna Skaner akcji Skaner Forex Skaner Krypto Kalendarz ekonomiczny Show Jak to działa Funkcje wykresów Cena Dobre Praktyki Moderatorzy Rozwiązania internetowe i brokerskie Widżety Wykresy Lekka Biblioteka Wykresów Centrum Pomocy Poleć przyjaciela Zgłoś dodatkową funkcjonalność Blog i wiadomości Twitter
Profil Ustawienia profilu Konto i płatności Poleć przyjaciela Wiadomości do działu obsługi Centrum Pomocy Opublikowane Pomysły Obserwujący Lista obserwowanych Wiadomość prywatna Czat Wyloguj