Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(title="Commodity Channel Index", shorttitle="CCI & ADX_by RM", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
- length = input.int(20, minval=1)
- src = input(hlc3, title="Source")
- ma = ta.sma(src, length)
- cci = (src - ma) / (0.015 * ta.dev(src, length))
- plot(cci, "CCI", color=#2962FF)
- band1 = hline(100, "Upper Band", color=#787B86, linestyle=hline.style_solid)
- bandmid0 = hline(0, "Middle 0 Band", color=#787B86, linestyle=hline.style_dashed)
- band0 = hline(-100, "Lower Band", color=#787B86, linestyle=hline.style_solid)
- bandupperreversal = hline(200, "Upper reversal Band", color=#787B86, linestyle=hline.style_dashed)
- bandlowerreversal = hline(-200, "Lower Reversal Band", color=#787B86, linestyle=hline.style_dashed)
- fill(band1, band0, color=color.rgb(33, 150, 243, 90), title="Background")
- ma(source, length, type) =>
- switch type
- "SMA" => ta.sma(source, length)
- "EMA" => ta.ema(source, length)
- "SMMA (RMA)" => ta.rma(source, length)
- "WMA" => ta.wma(source, length)
- "VWMA" => ta.vwma(source, length)
- typeMA = input.string(title = "Method", defval = "SMA", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Smoothing")
- smoothingLength = input.int(title = "Length", defval = 5, minval = 1, maxval = 100, group="Smoothing")
- smoothingLine = ma(cci, smoothingLength, typeMA)
- plot(smoothingLine, title="Smoothing Line", color=#f37f20, display=display.none)
- //@version=5
- //indicator("Average Directional Index", shorttitle="ADX", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
- adxlen = input(4, title="ADX Smoothing")
- dilen = input(4, title="DI Length")
- dirmov(len) =>
- up = ta.change(high)
- down = -ta.change(low)
- plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
- minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
- truerange = ta.rma(ta.tr, len)
- plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
- minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
- [plus, minus]
- adx(dilen, adxlen) =>
- [plus, minus] = dirmov(dilen)
- sum = plus + minus
- adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
- sig = adx(dilen, adxlen)
- plot(sig, color=color.yellow, title="ADX")
- adxthresholdlevel = input(30, title="ADX Threshold Imp Level") //ADX threshold level 25 above this indicates strong momentum.. below 25 may be rangebound
- ADXmylevel25 = hline(adxthresholdlevel, "ADX threshold level (25 or 30 above this indicates strong momentum, Below 25 or 30 price may stay rangebound)", color=#4CAF50, linestyle=hline.style_solid)
Advertisement
Add Comment
Please, Sign In to add comment