Advertisement
xmd79

Donchian Channels Strength

Jan 2nd, 2024
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © Daniel_Ge
  3.  
  4. //@version=5
  5. indicator(title="Donchian Channels Strength", shorttitle="DC Strength", overlay=false, timeframe="", timeframe_gaps=true)
  6.  
  7. // Input
  8. src = input(close, "Source", inline = "Source")
  9. include_wicks = input.bool(false, "Include Wicks", inline = "Source")
  10. length = input.int(13, "Length", minval=2)
  11. maTypeInput = input.string("SMMA (RMA)", title="MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
  12. signal_length = input.int(9, "Signal Length")
  13.  
  14. // MA Switch
  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. // Calculations
  24. lower = ta.lowest(src, length)
  25. upper = ta.highest(src, length)
  26.  
  27. if include_wicks
  28. lower := ta.lowest(low, length)
  29. upper := ta.highest(high, length)
  30.  
  31. basis = math.avg(upper, lower)
  32. dif = src - basis
  33. ma_dif = ma(dif, length, maTypeInput)
  34. ma_dif_abs = ma(math.abs(dif), length, maTypeInput)
  35. dc_strength = ma_dif / ma_dif_abs * 50 + 50
  36.  
  37. // Lines
  38. hline(15, linestyle = hline.style_dotted, display = display.none)
  39. hline(50, linestyle = hline.style_solid)
  40. hline(85, linestyle = hline.style_dotted, display = display.none)
  41.  
  42. // Plots
  43. p_50 = plot(50, editable = false, display = display.none) // only used for filling
  44. p_strength = plot(dc_strength, "DC Strength", color = dc_strength > 50 ? color(#00cbff) : color(#ff0099))
  45. plot(ta.ema(dc_strength, signal_length), "Signal", color = color(#d1d4dc))
  46.  
  47. // Filling
  48. fill(p_strength, p_50, 80, 50, color.new(#00cbff, 70), na, title = "Upper Filling")
  49. fill(p_50, p_strength, 50, 20, na, color.new(#ff0099, 70), title = "Lower Filling")
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement