//@version=3 //https://www.tradingview.com/u/tradingwithnoobreinier/ study("Cluster Algorithm II (Clone)", shorttitle="Cluster Algorithm II (Clone)") //inputs length = input(title="Length", type=integer, defval=14) overboughtlevel = input(title="Overbought Level", type=integer, defval=70) oversoldlevel = input(title="Oversold Level", type=integer, defval=30) src = input(title="Source", type=source, defval=hlc3) //calculations f8 = 100 * src f10 = nz(f8[1]) v8 = f8 - f10 f18 = 3 / (length + 2) f20 = 1 - f18 f28 = 0.0 f28 := f20 * nz(f28[1]) + f18 * v8 f30 = 0.0 f30 := f18 * f28 + f20 * nz(f30[1]) vC = f28 * 1.5 - f30 * 0.5 f38 = 0.0 f38 := f20 * nz(f38[1]) + f18 * vC f40 = 0.0 f40 := f18 * f38 + f20 * nz(f40[1]) v10 = f38 * 1.5 - f40 * 0.5 f48 = 0.0 f48 := f20 * nz(f48[1]) + f18 * v10 f50 = 0.0 f50 := f18 * f48 + f20 * nz(f50[1]) v14 = f48 * 1.5 - f50 * 0.5 f58 = 0.0 f58 := f20 * nz(f58[1]) + f18 * abs(v8) f60 = 0.0 f60 := f18 * f58 + f20 * nz(f60[1]) v18 = f58 * 1.5 - f60 * 0.5 f68 = 0.0 f68 := f20 * nz(f68[1]) + f18 * v18 f70 = 0.0 f70 := f18 * f68 + f20 * nz(f70[1]) v1C = f68 * 1.5 - f70 * 0.5 f78 = 0.0 f78 := f20 * nz(f78[1]) + f18 * v1C f80 = 0.0 f80 := f18 * f78 + f20 * nz(f80[1]) v20 = f78 * 1.5 - f80 * 0.5 f88_ = 0.0 f90_ = 0.0 f88 = 0.0 f90_ := nz(f90_[1]) == 0 ? 1 : nz(f88[1]) <= nz(f90_[1]) ? nz(f88[1]) + 1 : nz(f90_[1]) + 1 f88 := nz(f90_[1]) == 0 and (length - 1 >= 5) ? length - 1 : 5 f0 = f88 >= f90_ and f8 != f10 ? 1 : 0 f90 = f88 == f90_ and f0 == 0 ? 0 : f90_ v4_ = f88 < f90 and v20 > 0 ? (v14 / v20 + 1) * 50 : 50 rsx = v4_ > 100 ? 100 : v4_ < 0 ? 0 : v4_ current = rsx[0] previous = rsx[1] //plot the rsx line plot(rsx, title="RSX Line", linewidth=2, color=current > previous ? #0ebb23 : #ff0000, transp=10) transparent = color(white, 100) //plot the lines maximumlevelline = hline(100, title="Maximum Level", color=transparent) minimumlevelline = hline(0, title="Minimum Level", color=transparent) overboughtlevelline = hline(overboughtlevel, title="Overbought Level", linestyle=dashed) oversoldlevelline = hline(oversoldlevel, title="Oversold Level", linestyle=dashed) //ovebought oversold area color conditions overboughtfillcolor = rsx > overboughtlevel ? red : transparent oversoldfillcolor = rsx < oversoldlevel ? green : transparent //fill the ovebought oversold areas fill(maximumlevelline, overboughtlevelline, color=overboughtfillcolor, transp=60) fill(minimumlevelline, oversoldlevelline, color=oversoldfillcolor, transp=60)