Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Daniel_Ge
- //@version=5
- indicator(title="Donchian Channels Strength", shorttitle="DC Strength", overlay=false, timeframe="", timeframe_gaps=true)
- // Input
- src = input(close, "Source", inline = "Source")
- include_wicks = input.bool(false, "Include Wicks", inline = "Source")
- length = input.int(13, "Length", minval=2)
- maTypeInput = input.string("SMMA (RMA)", title="MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
- signal_length = input.int(9, "Signal Length")
- // MA Switch
- 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)
- // Calculations
- lower = ta.lowest(src, length)
- upper = ta.highest(src, length)
- if include_wicks
- lower := ta.lowest(low, length)
- upper := ta.highest(high, length)
- basis = math.avg(upper, lower)
- dif = src - basis
- ma_dif = ma(dif, length, maTypeInput)
- ma_dif_abs = ma(math.abs(dif), length, maTypeInput)
- dc_strength = ma_dif / ma_dif_abs * 50 + 50
- // Lines
- hline(15, linestyle = hline.style_dotted, display = display.none)
- hline(50, linestyle = hline.style_solid)
- hline(85, linestyle = hline.style_dotted, display = display.none)
- // Plots
- p_50 = plot(50, editable = false, display = display.none) // only used for filling
- p_strength = plot(dc_strength, "DC Strength", color = dc_strength > 50 ? color(#00cbff) : color(#ff0099))
- plot(ta.ema(dc_strength, signal_length), "Signal", color = color(#d1d4dc))
- // Filling
- fill(p_strength, p_50, 80, 50, color.new(#00cbff, 70), na, title = "Upper Filling")
- fill(p_50, p_strength, 50, 20, na, color.new(#ff0099, 70), title = "Lower Filling")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement