Double CCI For ThinkOrSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hello , I like the double cci indicator in Trading view ..created
https://www.tradingview.com/script/4vIRtqeP/

Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OskarGallard
//@version=5
indicator("Double CCI", "Double CCI", overlay=false, format=format.price, precision=2, timeframe="", timeframe_gaps=false)
// Function to select the type of source
get_src(Type) =>
    if Type == 'VWAP'
        ta.vwap
    else if Type == 'Close'
        close
    else if Type == 'Open'
        open
    else if Type == 'HL2'
        hl2
    else if Type == 'HLC3'
        hlc3
    else if Type == 'OHLC4'
        ohlc4
    else if Type == 'High'
        high
    else if Type == 'Low'
        low
    else if Type == 'vwap(Close)'
        ta.vwap(close)
    else if Type == 'vwap(Open)'
        ta.vwap(open)
    else if Type == 'vwap(High)'
        ta.vwap(high)
    else if Type == 'vwap(Low)'
        ta.vwap(low)
    else if Type == 'AVG(vwap(H,L))'
        math.avg(ta.vwap(high), ta.vwap(low))
    else if Type == 'AVG(vwap(O,C))'
        math.avg(ta.vwap(open), ta.vwap(close))
    else if Type == 'HLCC4'
        hlcc4

// http://forex-indicators.net/momentum-indicators/cci
// https://school.stockcharts.com/doku.php?id=technical_indicators:commodity_channel_index_cci
// https://www.investopedia.com/terms/c/commoditychannelindex.asp
show_CCI      = input.bool(true, "═══════ Show Commodity Channel Index 1 ═══════")
length_CCI    = input.int(34,        "Length", minval=1, inline="cci1")
MA_Type       = input.string("ALMA", "Type", inline='cci1', options=['SMA', 'EMA', 'WMA', "DWMA", 'HMA', 'ALMA', 'LSMA', 'Wild', 'JMA', "COVWMA", "FRAMA", 'RMA', 'DEMA', 'TEMA', 'VWMA', "DVWMA", 'SWMA', 'KAMA', "Zero Lag", "Median"])
src_CCI       = input.string("vwap(Close)", "Source", inline='cci1', options=['Close', 'Open', 'VWAP', 'HL2', 'HLC3', 'OHLC4', 'HLCC4', 'High', 'Low', 'vwap(Close)', 'vwap(Open)', 'vwap(High)', 'vwap(Low)', 'AVG(vwap(H,L))', 'AVG(vwap(O,C))'])
show_cross    = input.bool(true, "Show crosses at line 100")
show_signal   = input.bool(false, "Show Signal", inline='signal')
length_signal = input.int(10,     "Length", minval=5, inline='signal')
MA_Type_Sig   = input.string("Wild", "Type", inline='signal', options=['SMA', 'EMA', 'WMA', "DWMA", 'HMA', 'ALMA', 'LSMA', 'Wild', 'JMA', "COVWMA", "FRAMA", 'RMA', 'DEMA', 'TEMA', 'VWMA', "DVWMA", 'SWMA', 'KAMA', "Zero Lag", "Median"])

// Based on "BEST Supertrend CCI" - Author: @Daveatt
// https://www.tradingview.com/script/sT01CTxB-BEST-Supertrend-CCI/
show_ST = input.bool(true, "SuperTrend Background?", inline='st1', group='SuperTrend')
ML      = input.int(0,     "CCI Midline Pivot", inline='st1', group='SuperTrend')
Factor  = input.float(3,   "ATR Factor", minval=1, maxval=100, step=0.1, inline='st2', group='SuperTrend')
Pd      = input.int(3,     "ATR Period", minval=1, maxval=100, inline='st2', group='SuperTrend')

// Based on "Coloured CCI Histogram V2.0" - Author: @JustUncleL
// https://www.tradingview.com/script/d9naGmH3-Coloured-CCI-Histogram-V2-0-by-JustUncleL/
show_CCI2   = input.bool(false, "═══════ Show Commodity Channel Index 2 ═══════")
length_CCI2 = input.int(14,        "Length", minval=1, inline='cci2')
MA_Type2    = input.string("SMA",  "Type", inline='cci2', options=['SMA', 'EMA', 'WMA', "DWMA", 'HMA', 'ALMA', 'LSMA', 'Wild', 'JMA', "COVWMA", "FRAMA", 'RMA', 'DEMA', 'TEMA', 'VWMA', "DVWMA", 'SWMA', 'KAMA', "Zero Lag", "Median"])
src_CCI2    = input.string("HLC3", "Source", inline='cci2', options=['Close', 'Open', 'VWAP', 'HL2', 'HLC3', 'OHLC4', 'HLCC4', 'High', 'Low', 'vwap(Close)', 'vwap(Open)', 'vwap(High)', 'vwap(Low)', 'AVG(vwap(H,L))', 'AVG(vwap(O,C))'])
uTrad       = input.bool(true, "Use Traditional Formula of @JustUncleL")
mLevel      = input.int(100, "Mid Level Trigger Lines +/-", minval=10)
hLevel      = input.int(200, "High Level Trigger Lines +/-", minval=10)

// Kaufman's Adaptive Moving Average
fast = 0.666  // KAMA Fast End
slow = 0.0645  // KAMA Slow End
kama(x, t) =>
    dist = math.abs(x[0] - x[1])
    signal = math.abs(x - x[t])
    noise = math.sum(dist, t)
    effr = noise != 0 ? signal / noise : 1
    sc = math.pow(effr * (fast - slow) + slow, 2)
    kama = x
    kama := nz(kama[1]) + sc * (x - nz(kama[1]))
    kama

// Jurik Moving Average of @everget
jma(src, length, power, phase) =>
    phaseRatio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : phase / 100 + 1.5
    beta = 0.45 * (length - 1) / (0.45 * (length - 1) + 2)
    alpha = math.pow(beta, power)
    jma = 0.0
    e0 = 0.0
    e0 := (1 - alpha) * src + alpha * nz(e0[1])
    e1 = 0.0
    e1 := (src - e0) * (1 - beta) + beta * nz(e1[1])
    e2 = 0.0
    e2 := (e0 + phaseRatio * e1 - nz(jma[1])) * math.pow(1 - alpha, 2) + math.pow(alpha, 2) * nz(e2[1])
    jma := e2 + nz(jma[1])
    jma

// ZLEMA: Zero Lag
zema(_src, _len) =>
    alpha = (_len - 1) / 2
    zlema0 = _src + _src - _src[alpha]
    zlemaF = ta.ema(zlema0, _len)
    zlemaF

// COVWMA - Coefficient of Variation Weighted Moving Average of @DonovanWall
covwma(a, b) =>
    cov    = ta.stdev(a, b) / ta.sma(a, b)
    cw     = a*cov
    covwma = math.sum(cw, b) / math.sum(cov, b)

// FRAMA - Fractal Adaptive Moving Average of @DonovanWall
w = -4.6 // "Coefficient (if FRAMA)"
frama(a, b) =>
    frama = 0.0
    n3    = (ta.highest(high, b) - ta.lowest(low, b))/b
    hd2   = ta.highest(high, b/2)
    ld2   = ta.lowest(low, b/2)
    n2    = (hd2 - ld2)/(b/2)
    n1    = (hd2[b/2] - ld2[b/2])/(b/2)
    dim   = (n1 > 0) and (n2 > 0) and (n3 > 0) ? (math.log(n1 + n2) - math.log(n3))/math.log(2) : 0
    alpha = math.exp(w*(dim - 1))
    sc    = (alpha < 0.01 ? 0.01 : (alpha > 1 ? 1 : alpha))
    frama := ta.cum(1)<=2*b ? a : (a*sc) + nz(frama[1])*(1 - sc)
    frama

ma(MAType, MASource, MAPeriod) =>
    if MAPeriod > 0
        if MAType == 'SMA'
            ta.sma(MASource, MAPeriod)
        else if MAType == 'EMA'
            ta.ema(MASource, MAPeriod)
        else if MAType == 'WMA'
            ta.wma(MASource, MAPeriod)
        else if MAType == 'RMA'
            ta.rma(MASource, MAPeriod)
        else if MAType == 'HMA'
            ta.hma(MASource, MAPeriod)
        else if MAType == 'DEMA'
            e = ta.ema(MASource, MAPeriod)
            2 * e - ta.ema(e, MAPeriod)
        else if MAType == 'TEMA'
            e = ta.ema(MASource, MAPeriod)
            3 * (e - ta.ema(e, MAPeriod)) + ta.ema(ta.ema(e, MAPeriod), MAPeriod)
        else if MAType == 'VWMA'
            ta.vwma(MASource, MAPeriod)
        else if MAType == 'ALMA'
            ta.alma(MASource, MAPeriod, .85, 6)
        else if MAType == 'KAMA'
            kama(MASource, MAPeriod)
        else if MAType == 'SWMA'
            ta.swma(MASource)
        else if MAType == 'JMA'
            jma(MASource, MAPeriod, 2, 50)
        else if MAType == 'LSMA'
            ta.linreg(MASource, MAPeriod, 0)
        else if MAType == 'Wild'
            wild = MASource
            wild := nz(wild[1]) + (MASource - nz(wild[1])) / MAPeriod
            wild
        else if MAType == "Median"
            ta.median(MASource, MAPeriod)
        else if MAType == "DWMA" // Double Weighted Moving Average
            ta.wma(ta.wma(MASource, MAPeriod), MAPeriod)
        else if MAType == "DVWMA" // Double Volume-Weighted Moving Average
            ta.vwma(ta.vwma(MASource, MAPeriod), MAPeriod)
        else if MAType == "Zero Lag"
            zema(MASource, MAPeriod)
        else if MAType == "COVWMA"
            covwma(MASource, MAPeriod)
        else if MAType == "FRAMA"
            frama(MASource, MAPeriod)

media = ma(MA_Type, get_src(src_CCI), length_CCI)
cci = (get_src(src_CCI) - media) / (0.015 * ta.dev(get_src(src_CCI), length_CCI))
signal_cci = ma(MA_Type_Sig, cci, length_signal)

media2 = ma(MA_Type2, get_src(src_CCI2), length_CCI2)
cciNT = (get_src(src_CCI2) - media2) / (0.015 * ta.dev(get_src(src_CCI2), length_CCI2))
cciT = (get_src(src_CCI2) - media2) / (0.015 * ta.dev(math.abs(get_src(src_CCI2) - media2), length_CCI2))
cci2 = uTrad ? cciT : cciNT

f_supertrend(factor, pd) =>
    Up = hl2 - factor * ta.atr(pd)
    Dn = hl2 + factor * ta.atr(pd)
    TrendUp = 0.0
    TrendUp := cci[1] > ML ? math.max(Up, TrendUp[1]) : Up
    TrendDown = 0.0
    TrendDown := cci[1] < ML ? math.min(Dn, TrendDown[1]) : Dn
    Trend = 0.0
    Trend := cci > ML ? 1 : cci < ML ? -1 : nz(Trend[1], 1)
    Trailingsl = Trend == 1 ? TrendUp : TrendDown
    Trailingsl

SuperTrend = f_supertrend(Factor, Pd)
color_super = open >= SuperTrend ? color.new(#00FE00, 90) : color.new(#FF0000, 90)
cci_Dn = cci2 < -hLevel ? #FF8080 : cci2 < -mLevel ? #FF3333 : #A30000
cci_Up = cci2 >  hLevel ? #8080FF : cci2 >  mLevel ? #3333FF : #0000A3
color_cci2 = cci2 >= 0 ? cci_Up : cci_Dn
UPshape = cci > 100 ? cci : na
DNshape = cci < -100 ? cci : na
color_cci = cci >= 0 ? color.new(#80FF00, 5) : color.new(#FF4000, 5)
color_signal = signal_cci > signal_cci[1] ? color.white : color.gray
cross_dn = cci[0] <  100 and cci[1] >  100
cross_up = cci[0] > -100 and cci[1] < -100

plot(show_CCI ? cci : na, "CCI", color_cci, 2)
plot(show_CCI ? UPshape : na, "UP Shape",   color.new(#407F00, 25), 4, plot.style_circles)
plot(show_CCI ? DNshape : na, "DOWN Shape", color.new(#7F2000, 25), 4, plot.style_circles)
plotshape(show_cross ? cross_dn : na, "100 Cross Down", shape.diamond, location.top,    color.new(#FF4000, 0))
plotshape(show_cross ? cross_up : na, "100 Cross Up",   shape.diamond, location.bottom, color.new(#80FF00, 0))
plot(show_signal ? signal_cci : na, "Signal(CCI)", color_signal, 2)
bgcolor(show_ST ? color_super : na, title='SuperTrend Background')

plot(show_CCI2 ? cci2 : na, "CCI Histogram", color_cci2, 2, plot.style_columns)
hUp2 = hline(show_CCI2 ? hLevel : na, "High Upper Band", color.new(#FF0000, 0), hline.style_dotted)
hUp1 = hline(show_CCI2 or show_CCI ? mLevel : na, "Mid Upper Band", color.new(#FF8080, 0), hline.style_dashed)
hline(show_CCI ? ML : na, "CCI Midline Pivot", color.silver, hline.style_dotted)
hDn2 = hline(show_CCI2 or show_CCI ? -mLevel : na, 'Mid Lower Band', color.new(#8080FF, 0), hline.style_dashed)
hDn1 = hline(show_CCI2 ? -hLevel : na, 'High Lower Band', color.new(#4FC0E8, 0), hline.style_dotted)
https://www.tradingview.com/script/4vIRtqeP/

Its a free indicator . Can anyone help me to convert this to TOS script ? Please
check this .

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © OskarGallard
#indicator("Double CCI", "Double CCI", overlay=false,
# Converted by Sam4COK@Samer800    - 05/2023
declare lower;
input show_CCI = yes;#, "═══════ Show Commodity Channel Index 1 ═══════")
input length_CCI = 34;#,        "Length"
input MA_Type    = {SMA, EMA, SMMA, VAWMA, WMA, VWMA, RMS, DEMA, TEMA, ZLSMA, ZLDEMA, ZLTEMA, McGinley, HMA, default ALMA, SWMA, Gaussian, TRAEM, KAMA, MAV, AMA, LSMA, WILD};
input source_CCI = {"Close", "Open", "VWAP", "HL2", "HLC3", "OHLC4", "HLCC4", "High", "Low", default "vwap(Close)", "vwap(Open)", "vwap(High)", "vwap(Low)", "AVG(vwap(H,L))", "AVG(vwap(O,C))"};
input show_cross    = yes;    # "Show crosses at line 100")
input show_signal   = no;     # "Show Signal"
input length_signal = 10;     # "Length"
input MA_Type_Sig   = {SMA, EMA, SMMA, VAWMA, WMA, VWMA, RMS, DEMA, TEMA, ZLSMA, ZLDEMA, ZLTEMA, McGinley, HMA, ALMA, SWMA, Gaussian, TRAEM, KAMA, MAV, AMA, LSMA, default WILD};
input show_ST = yes;#(true, "SuperTrend Background?", inline='st1', group='SuperTrend')
input ML      = 0;#,     "CCI Midline Pivot", inline='st1', group='SuperTrend')
input Factor  = 3;#,   "ATR Factor", minval=1, maxval=100, step=0.1, inline='st2', group='SuperTrend')
input Pd      = 3;#,     "ATR Period", minval=1, maxval=100, inline='st2', group='SuperTrend')
input show_CCI2   = no;#false, "═══════ Show Commodity Channel Index 2 ═══════")
input length_CCI2 = 14;#,        "Length", minval=1, inline='cci2')
input MA_Type2    = {default SMA, EMA, SMMA, VAWMA, WMA, VWMA, RMS, DEMA, TEMA, ZLSMA, ZLDEMA, ZLTEMA, McGinley, HMA, ALMA, SWMA, Gaussian, TRAEM, KAMA, MAV, AMA, LSMA, MAMA, WILD};
input source_CCI2 = {"Close", "Open", "VWAP", "HL2", default "HLC3", "OHLC4", "HLCC4", "High", "Low", "vwap(Close)", "vwap(Open)", "vwap(High)", "vwap(Low)", "AVG(vwap(H,L))", "AVG(vwap(O,C))"};
input uTrad       = yes;#(true, "Use Traditional Formula of @JustUncleL")
input mLevel      = 100;#, "Mid Level Trigger Lines +/-", minval=10)
input hLevel      = 200;#, "High Level Trigger Lines +/-", minval=10)

def na = Double.NaN;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def last = isNaN(close);
#--- Color.
DefineGlobalColor("Red1" , CreateColor(255, 128, 128));
DefineGlobalColor("Red2" , CreateColor(255, 51, 51));
DefineGlobalColor("Red3" , CreateColor(163, 0, 0));
DefineGlobalColor("blue1" , CreateColor(128, 128, 255));
DefineGlobalColor("blue2" , CreateColor(51, 51, 255));
DefineGlobalColor("blue3" , CreateColor(0, 0, 163));
#export f_Vwap(simple string tf, float src, float src_v) =>
script f_Vwap {
    input src = close;
    def today = GetDay();
    def tf = today != today[1];
    def src_v = volume;
    def start0 = tf - tf[1];
    def sumSrc0 = src * src_v;
    def sumVol0 = src_v;
    def sumSrc2 = src_v * Sqr(src);
    def sumSrc1 = CompoundValue(1, if start0 then sumSrc0 else sumSrc0 + sumSrc1[1], sumSrc0);
    def sumVol1 = CompoundValue(1, if start0 then sumVol0 else sumVol0 + sumVol1[1], sumVol0);
    def sumVol2 = CompoundValue(1, if start0 then sumSrc2 else sumSrc2 + sumVol2[1], sumSrc2);
    def Vwap = sumSrc1 / sumVol1;
    plot wap = Vwap;
}
#pine_dev(source, length) =>
script dev {
    input source = close;
    input length = 10;
    def mean = Average(source, length);
    def sum = fold i = 0 to length with p do
            p + AbsValue(source[i] - mean);
    def dev = sum / length;
    plot out = dev;
}
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if !IsNaN(data) then data else repl;
    plot return = ret_val;
}

#ama (source, length, fast, slow) =>
script ama {
    input source = close;
    input length = 14;
    input fast   = 2;
    input slow   = 30;
    def fastAlpha = 2 / (fast + 1);
    def slowAlpha = 2 / (slow + 1);
    def hh = Highest(high, length + 1);
    def ll = Lowest(low, length + 1);
    def mltp = if (hh - ll) != 0 then AbsValue(2 * source - ll - hh) / (hh - ll) else 0;
    def ssc = mltp * (fastAlpha - slowAlpha) + slowAlpha;
    def ama;
    ama = CompoundValue(1, ama[1] + Power(ssc, 2) * (source - ama[1]), source);
    plot return = ama;
}
#rms(source, length)=>
script rms {
    input source = close;
    input length = 14;
    def rms = Sqrt(Sum(Power(source, 2), length) / length);
    plot return = rms;
}
#mav (source, length) =>
script mav {
    input source = close;
    input length = 14;
    def mav = ((SimpleMovingAvg(source, length)[1] * (length - 1)) + source) / length;
    plot return = mav;
}
#kama(xPrice, Length)=>
script kama {
    input xPrice = close;
    input Length = 14;
    def xvnoise = AbsValue(xPrice - xPrice[1]);
    def nfastend = 0.666;
    def nslowend = 0.0645;
    def nsignal = AbsValue(xPrice - xPrice[Length]);
    def nnoise = Sum(xvnoise, Length);
    def nefratio = if nnoise != 0 then nsignal / nnoise else 0;
    def nsmooth = Power(nefratio * (nfastend - nslowend) + nslowend, 2);
    def nAMA;
    nAMA = CompoundValue(1, nAMA[1] + nsmooth * (xPrice - nAMA[1]), xPrice);
    plot returen = nAMA;
}
#Gaussianma(values, length) =>
script Gaussian {
    input values = close;
    input length = 20;
    def stddev = length / 4;
    def indices = length - 1;
    def weights = Exp(-0.5 * (Power((indices - length), 2) / Power(stddev, 2)));
    def sum = Sum(values * weights, length);
    def gMA = sum / Sum(weights, length);
    plot return = gMA;
}
#pine_swma(source) =>
script swma {
    input source = close;
    def swma = source[3] * 1 / 6 + source[2] * 2 / 6 +  source[1] * 2 / 6 + source[0] * 1 / 6;
    plot retun = swma;
}
#export zlSma(float src, simple int len) =>
script zlSma {
    input src = close;
    input len = 14;
    def lsma = Inertia(src, len);
    def lsma2 = Inertia(lsma, len);
    def eq = lsma - lsma2;
    def zlsma = lsma + eq;
    plot return = zlsma;
}
#export zlDema(float src, simple int len) =>
script zlDema {
    input src = close;
    input len = 14;
    def zdema1 = ExpAverage(src, len);
    def zdema2 = ExpAverage(zdema1, len);
    def dema1 = 2 * zdema1 - zdema2;
    def zdema12 = ExpAverage(dema1, len);
    def zdema22 = ExpAverage(zdema12, len);
    def zldema = 2 * zdema12 - zdema22;
    plot return = zldema;
}
#export zlTema(float src, simple int len) =>
script zlTema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema1 = 3 * (ema1 - ema2) + ema3;
    def ema1a = ExpAverage(tema1, len);
    def ema2a = ExpAverage(ema1a, len);
    def ema3a = ExpAverage(ema2a, len);
    def zltema = 3 * (ema1a - ema2a) + ema3a;
    plot return = zltema;
}
#pine_alma(series, windowsize, offset, sigma) =>
script ALMA {
    input series = close;
    input windowsize = 9;
    input Offset = 0.85;
    input Sigma = 6;
    def m = Offset * (windowsize - 1);
    def s = windowsize / Sigma;
    def norm  = fold z = 0 to windowsize with CW do
         CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
    def sum  = fold y = 0 to windowsize with WS do
         WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(series, windowsize - 1 - y);
    plot ALMA = sum  / norm ;
}
#export mcginley(float src, simple int len)=>
script mcginley {
    input src = close;
    input len = 14;
    def mg;
    def t = ExpAverage(src, len);
    mg = CompoundValue(1 , if IsNaN(mg[1]) then t else mg[1] + (src - mg[1]) / (len * Power(src / mg[1], 4)), t);
    plot return = mg;
}
# vawma(len, src = hlc3, len = na, startingWeight = 1) =>
script vawma {
    input src = hlc3;
    input len = 5;
    input startingWeight = 1;
    def last = len - 1;
    def vol = fold i1 = 0 to last with p1 do
              p1 + volume[i1] * (last - i1 + startingWeight);
    def sum = fold i2 = 0 to last with p2 do
              p2 + (src[i2] * volume[i2] * (last - i2 + startingWeight));
    def vawma = if vol == 0 then Double.NaN else sum / vol;
    plot out = vawma;
}
#vwma(source, length)
script VWMA {
    input src = close;
    input len = 15;
    def v = volume;
    def VWMA = SimpleMovingAvg(src * nz(v, 1), len) / SimpleMovingAvg(nz(v, 1), len);
    plot result = VWMA;
}
#trAdjEma(lengthy) =>
script trAdjEma {
    input src = close;
    input length = 60;
    input mult = 1;
    def tr = TrueRange(high, close, low);
    def alpha = 2.0 / (length + 1);
    def trL = Lowest(tr, length);
    def trH = Highest(tr, length);
    def trAdj = if (trH - trL) != 0 then (tr - trL) / (trH - trL) else 0;
    def trEMA = ExpAverage(src, length);
    def trAdjEma;
    trAdjEma = CompoundValue(1, trAdjEma[1] + (alpha * (1 + (trAdj * mult)) * (src - trAdjEma[1])), trEMA);
    plot trAdEma = trAdjEma;
}

#export multiMa(float source, simple int length, string type) =>
script ma {
    input type = "SMA";
    input source = close;
    input length = 14;
    input multForTraem = 1;
    input lsma_offset = 0;
    def w = WMA(source, length);
    def wild = CompoundValue(1, wild[1] + (source - wild[1]) / length, source);

    def multiMa =
        if type == "WILD"  then  wild else
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then CompoundValue(1, if IsNaN(w[1]) then Average(source, length) else
                                 (w[1] * (length - 1) + source) / length,  Average(source, length)) else
        if type == "WMA"    then WMA(source, length) else
        if type == "KAMA"   then KAMA(source, length) else
        if type == "MAV"   then MAV(source, length) else
        if type == "AMA"   then AMA(source, length) else
        if type == "VWMA"   then vwma(source, length) else
        if type == "DEMA"   then DEMA(source, length) else
        if type == "VAWMA"   then VAWMA(source, length) else
        if type == "TEMA"   then TEMA(source, length) else
        if type == "LSMA"   then Inertia(source[-lsma_offset], length) else
        if type == "RMS"   then RMS(source, length) else
        if type == "ZLSMA"  then zlSma(source, length) else
        if type == "ZLDEMA" then zlDema(source, length) else
        if type == "ZLTEMA" then zlTema(source, length) else
        if type == "McGinley" then mcginley(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "SWMA" then SWMA(source) else
        if type == "Gaussian"   then Gaussian(source, length) else
        if type == "TRAEM"   then trAdjEma(source, length, multForTraem) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
def src_CCI;
switch (source_CCI) {
case "vwap(Close)" :
         src_CCI = f_vwap(close);       
case "VWAP" :
        src_CCI = Vwap();
case "Close" :
        src_CCI = close;
case "Open" :
        src_CCI = open;
case "HL2":
        src_CCI = hl2;
case "HLC3" :
        src_CCI = hlc3;
case "OHLC4" :
        src_CCI = ohlc4;
case "High" :
        src_CCI = high;
case "Low" :
        src_CCI = low;
case "vwap(Open)" :
        src_CCI = f_Vwap(open);
case "vwap(High)" :
        src_CCI = f_vwap(high);
case "vwap(Low)" :
        src_CCI = f_vwap(low);
case "AVG(vwap(H,L))" :
        src_CCI = (f_vwap(high) + f_vwap(low)) / 2;
case "AVG(vwap(O,C))" :
        src_CCI = (f_vwap(open) + f_vwap(close)) / 2;
case "HLCC4" :
        src_CCI = (high+Low+Close*2) / 4;
}
def src_CCI2;
switch (source_CCI2) {
case "vwap(Close)" :
         src_CCI2 = f_vwap(close);       
case "VWAP" :
        src_CCI2 = Vwap();
case "Close" :
        src_CCI2 = close;
case "Open" :
        src_CCI2 = open;
case "HL2":
        src_CCI2 = hl2;
case "HLC3" :
        src_CCI2 = hlc3;
case "OHLC4" :
        src_CCI2 = ohlc4;
case "High" :
        src_CCI2 = high;
case "Low" :
        src_CCI2 = low;
case "vwap(Open)" :
        src_CCI2 = f_Vwap(open);
case "vwap(High)" :
        src_CCI2 = f_vwap(high);
case "vwap(Low)" :
        src_CCI2 = f_vwap(low);
case "AVG(vwap(H,L))" :
        src_CCI2 = (f_vwap(high) + f_vwap(low)) / 2;
case "AVG(vwap(O,C))" :
        src_CCI2 = (f_vwap(open) + f_vwap(close)) / 2;
case "HLCC4" :
        src_CCI2 = (high+Low+Close*2) / 4;
}
def media = ma(MA_Type, src_CCI, length_CCI);
def cci = (src_CCI - media) / (0.015 * dev(src_CCI, length_CCI));
def signal_cci = ma(MA_Type_Sig, cci, length_signal);

def media2 = ma(MA_Type2, src_CCI2, length_CCI2);
def cciNT = (src_CCI2 - media2) / (0.015 * dev(src_CCI2, length_CCI2));
def cciT = (src_CCI2 - media2) / (0.015 * dev(AbsValue(src_CCI2 - media2), length_CCI2));
def cci2 = if uTrad then cciT else cciNT;

def Up = hl2 - Factor * ATR(LENGTH = Pd);
def Dn = hl2 + Factor * ATR(LENGTH = Pd);
def TrendUp = if cci[1] > ML then Max(Up, TrendUp[1]) else Up;
def TrendDown = if cci[1] < ML then Min(Dn, TrendDown[1]) else Dn;
def Trend;
def Trend_ = if Trend[1] == 0 then 1 else Trend[1];
Trend = if cci > ML then 1 else if cci < ML then -1 else Trend_;
def Trailingsl = if Trend == 1 then TrendUp else TrendDown;
def SuperTrend = Trailingsl;
def color_super = open >= SuperTrend;

def cci_Dn = if cci2 < -hLevel then -1 else if cci2 < -mLevel then -2 else -3;
def cci_Up = if cci2 >  hLevel then 1 else if cci2 >  mLevel then 2 else 3;
def color_cci2 = if cci2 >= 0 then cci_Up else cci_Dn;
def UPshape = if cci > 100 then cci else na;
def DNshape = if cci < -100 then cci else na;
def color_cci = cci >= 0;# ? color.new(#80FF00, 5) : color.new(#FF4000, 5)
def color_signal = signal_cci > signal_cci[1];# ? color.white : color.gray
def cross_dn = cci[0] <  100 and cci[1] >  100;
def cross_up = cci[0] > -100 and cci[1] < -100;

plot cciPlot = if show_CCI then cci else na;#, "CCI", color_cci, 2)
plot UP_Shape = if show_CCI then UPshape else na;#, "UP Shape",   color.new(#407F00, 25), 4, plot.style_circles)
plot DN_Shape = if show_CCI then DNshape else na;#, "DOWN Shape", color.new(#7F2000, 25), 4, plot.style_circles)

cciPlot.SetLineWeight(2);
UP_Shape.SetLineWeight(3);
DN_Shape.SetLineWeight(3);
cciPlot.AssignValueColor(if color_cci then Color.GREEN else Color.RED);
UP_Shape.SetDefaultColor(Color.LIME);
DN_Shape.SetDefaultColor(Color.PINK);
UP_Shape.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
DN_Shape.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

plot CrossDn = if show_cross then if cross_dn then 300 else na else na;#, "100 Cross Down", shape.diamond, location.top,    color.new(#FF4000, 0))
plot CrossUp = if show_cross then if cross_up then 300 else na else na;#, "100 Cross Up",   shape.diamond, location.bottom, color.new(#80FF00, 0))
plot cciSignal = if show_signal then signal_cci else na;#, "Signal(CCI)", color_signal, 2)
cciSignal.AssignValueColor(if color_signal then Color.WHITE else Color.DARK_GRAY);
CrossDn.SetPaintingStrategy(PaintingStrategy.SQUARES);
CrossUp.SetPaintingStrategy(PaintingStrategy.SQUARES);
CrossDn.SetDefaultColor(Color.MAGENTA);
CrossUp.SetDefaultColor(Color.CYAN);
AddCloud(if show_ST then if color_super then pos else neg else na, if color_super then neg else pos, Color.DARK_GREEN, Color.DARK_RED);#title='SuperTrend Background')

plot hist_CCI = if show_CCI2 then cci2 else na;        #, "CCI Histogram"
hist_CCI.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
hist_CCI.AssignValueColor(if color_cci2==-1 then GlobalColor("Red1") else
                          if color_cci2==-2 then GlobalColor("Red2") else
                          if color_cci2==-3 then GlobalColor("Red3") else
                          if color_cci2== 1 then GlobalColor("blue1") else
                          if color_cci2== 2 then GlobalColor("blue2") else GlobalColor("blue3"));

plot hUp2 = if show_CCI2 and !last then hLevel else na;                # "High Upper Band"
plot hUp1 = if (show_CCI2 or show_CCI) and !last then mLevel else na;    # "Mid Upper Band",
plot hline = if show_CCI and !last then ML else na;                    # "CCI Midline Pivot"
plot hDn2 = if (show_CCI2 or show_CCI) and !last then -mLevel else na;   # 'Mid Lower Band'
plot hDn1 = if show_CCI2 and !last then -hLevel else na;               # 'High Lower Band'

hUp2.SetDefaultColor(Color.MAGENTA);
hUp1.SetDefaultColor(Color.PLUM);
hline.SetDefaultColor(Color.GRAY);
hDn2.SetDefaultColor(Color.VIOLET);
hDn1.SetDefaultColor(Color.CYAN);

hUp2.SetPaintingStrategy(PAintingStrategy.DASHES);
hDn1.SetPaintingStrategy(PAintingStrategy.DASHES);

#--- END of CODE
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
448 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top