// Close to Close Volatility f_coc(x, period, sqrtAnnual) => mean = ta.sma(x, period) s = array.new_float(0) for i = 0 to period - 1 by 1 array.push(s, math.pow(x - mean, 2)) sqrtAnnual * math.sqrt(array.sum(s) / (period - 1)) //
// Mean Absolute Deviation (Adjusted) f_mad(source, period, sqrtAnnual) => var SQRT_HALF_PI = math.sqrt(math.asin(1)) mean = ta.sma(source, period) S = array.new_float(0) for i = 0 to period - 1 by 1 array.push(S, math.abs(source - mean)) sumS = array.sum(S) sqrtAnnual * (sumS / period) * SQRT_HALF_PI
// Median Absolute Deviation f_mead(source, period, sqrtAnnual) => median = ta.percentile_nearest_rank(source, period, 50) E = 0.0 for i = 0 to period - 1 by 1 E += math.abs(source - median) E sqrtAnnual * math.sqrt(2) * (E / period)
// Round Function Round(src, digits) => p = math.pow(10, digits) math.round(math.abs(src) * p) / p * math.sign(src)
//Options for Inputs ON = 'On' OFF = 'Off' CTC = 'Close to Close' PKS = 'Parkinson' GK = 'Garman Klass' RS = 'Rogers Satchell' GKYZ = 'Garman Klass Yang Zhang Extension' YZ = 'Yang Zhang' EWMA = 'EWMA' MAD = 'Mean Absolute Deviation' MAAD = 'Median Absolute Deviation' L = 'Line' SL = 'StepLine' Ar = 'Area' CL = 'Columns'
// Settings H = EWMA period = 10 Annual = 365 a = 1.34 Plen = 365 Pco = ON sma = ON malen = 55 bsg = OFF stl = CL lT = 3 i_invert = OFF bg = OFF sp = OFF
// Historical Volatiity Models Hv = if H == CTC f_coc(logr, period, sqrtAnnual) else if H == PKS f_park(period, sqrtAnnual) else if H == RS f_rsv(period, sqrtAnnual) else if H == GK f_gk(period, sqrtAnnual) else if H == GKYZ f_gkyz(period, sqrtAnnual) else if H == EWMA f_ewma(logr, period, sqrtAnnual) else if H == YZ f_yz(a, period, sqrtAnnual) else if H == MAD f_mad(logr, period, sqrtAnnual) else // H == "Median Absolute Deviation" f_mead(logr, period, sqrtAnnual)
//Custrom MAS maa = avgHV / 100 * 140 mab = avgHV / 100 * 180 mac = avgHV / 100 * 240 mad = avgHV / 100 * 60 mae = avgHV / 100 * 20
// Auto Sensivity Volatility Band Settings
float volatility = 0.0
if Hv < maa and Hv > avgHV // ilk band ust volatility := 3.15 else if Hv < mab and Hv > maa // ikinci band ust volatility := 3.5 else if Hv < mac and Hv > mab // ucuncu band ust volatility := 3.6 else if Hv > mac // volatilite en ust degerde volatility := 4 else if Hv < maa and Hv > mad // altdaki ilk band volatility := 3 else if Hv < mad and Hv > mae // altdaki ikinci band volatility := 2.85 else if Hv < mae // volatilite butun bandlarin anltinda volatility := 3