xmd79

Commodity Channel Index

Jun 14th, 2022
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. //@version=5
  2. indicator(title="Commodity Channel Index", shorttitle="CCI & ADX_by RM", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
  3. length = input.int(20, minval=1)
  4. src = input(hlc3, title="Source")
  5. ma = ta.sma(src, length)
  6. cci = (src - ma) / (0.015 * ta.dev(src, length))
  7. plot(cci, "CCI", color=#2962FF)
  8. band1 = hline(100, "Upper Band", color=#787B86, linestyle=hline.style_solid)
  9. bandmid0 = hline(0, "Middle 0 Band", color=#787B86, linestyle=hline.style_dashed)
  10. band0 = hline(-100, "Lower Band", color=#787B86, linestyle=hline.style_solid)
  11. bandupperreversal = hline(200, "Upper reversal Band", color=#787B86, linestyle=hline.style_dashed)
  12. bandlowerreversal = hline(-200, "Lower Reversal Band", color=#787B86, linestyle=hline.style_dashed)
  13. fill(band1, band0, color=color.rgb(33, 150, 243, 90), title="Background")
  14.  
  15. ma(source, length, type) =>
  16. switch type
  17. "SMA" => ta.sma(source, length)
  18. "EMA" => ta.ema(source, length)
  19. "SMMA (RMA)" => ta.rma(source, length)
  20. "WMA" => ta.wma(source, length)
  21. "VWMA" => ta.vwma(source, length)
  22.  
  23. typeMA = input.string(title = "Method", defval = "SMA", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Smoothing")
  24. smoothingLength = input.int(title = "Length", defval = 5, minval = 1, maxval = 100, group="Smoothing")
  25.  
  26. smoothingLine = ma(cci, smoothingLength, typeMA)
  27. plot(smoothingLine, title="Smoothing Line", color=#f37f20, display=display.none)
  28.  
  29.  
  30. //@version=5
  31. //indicator("Average Directional Index", shorttitle="ADX", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
  32. adxlen = input(4, title="ADX Smoothing")
  33. dilen = input(4, title="DI Length")
  34. dirmov(len) =>
  35. up = ta.change(high)
  36. down = -ta.change(low)
  37. plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
  38. minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
  39. truerange = ta.rma(ta.tr, len)
  40. plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
  41. minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
  42. [plus, minus]
  43. adx(dilen, adxlen) =>
  44. [plus, minus] = dirmov(dilen)
  45. sum = plus + minus
  46. adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
  47. sig = adx(dilen, adxlen)
  48. plot(sig, color=color.yellow, title="ADX")
  49.  
  50. adxthresholdlevel = input(30, title="ADX Threshold Imp Level") //ADX threshold level 25 above this indicates strong momentum.. below 25 may be rangebound
  51. 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)
  52.  
Advertisement
Add Comment
Please, Sign In to add comment