Conversion of Bollinger Bands x3 with Fill

Forums ProRealTime English forum ProBuilder support Conversion of Bollinger Bands x3 with Fill

  • This topic has 1 reply, 2 voices, and was last updated 3 days ago by avatarJS.
Viewing 2 posts - 1 through 2 (of 2 total)
  • #247783

    Please can anyone convert the following indicator:

    //@version=6
    indicator(shorttitle=”BBx3″, title=”Bollinger Bands x3 with Fill + HMA + Dynamic Width Colors”, overlay=true, timeframe=””, timeframe_gaps=true)

    // === Inputs ===
    length = input.int(20, minval=1, title=”Length”)
    maType = input.string(“SMA”, “Basis MA Type”, options=[“SMA”, “EMA”, “SMMA (RMA)”, “WMA”, “VWMA”, “HMA”])
    src = input(close, title=”Source”)

    mult1 = input.float(1.0, minval=0.001, maxval=50, title=”StdDev Multiplier Band 1″)
    mult2 = input.float(2.0, minval=0.001, maxval=50, title=”StdDev Multiplier Band 2″)
    mult3 = input.float(3.0, minval=0.001, maxval=50, title=”StdDev Multiplier Band 3″)

    fillColor1 = input.color(color.new(color.blue, 85), “Fill Color Between Band 1 & 2 (Expanding)”)
    fillColor2 = input.color(color.new(color.purple, 85), “Fill Color Between Band 2 & 3 (Expanding)”)
    fillColorNarrow = input.color(color.new(color.gray, 85), “Fill Color (Narrowing)”)

    showBand1 = input.bool(true, “Show Band 1 (±1σ)”)
    showBand2 = input.bool(true, “Show Band 2 (±2σ)”)
    showBand3 = input.bool(true, “Show Band 3 (±3σ)”)
    showFill12 = input.bool(true, “Fill Between Band 1 & 2”)
    showFill23 = input.bool(true, “Fill Between Band 2 & 3”)

    offset = input.int(0, “Offset”, minval = -500, maxval = 500, display = display.data_window)

    // === MA Functions ===
    hma(src, len) =>
    wma1 = ta.wma(src, len)
    wma2 = ta.wma(src, len / 2)
    ta.wma(2 * wma2 – wma1, math.round(math.sqrt(len)))

    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)
    “HMA” => hma(source, length)

    // === Calculations ===
    basis = ma(src, length, maType)
    dev = ta.stdev(src, length)

    upper1 = basis + mult1 * dev
    lower1 = basis – mult1 * dev

    upper2 = basis + mult2 * dev
    lower2 = basis – mult2 * dev

    upper3 = basis + mult3 * dev
    lower3 = basis – mult3 * dev

    // === Band Widths ===
    width1 = upper1 – lower1
    width2 = upper2 – lower2
    width3 = upper3 – lower3

    // === Narrowing Flags ===
    narrowing1 = width1 < width1[1]
    narrowing2 = width2 < width2[1]
    narrowing3 = width3 < width3[1]

    // === Dynamic Line Colors ===
    colorU1 = narrowing1 ? color.gray : color.lime
    colorL1 = narrowing1 ? color.gray : color.lime

    colorU2 = narrowing2 ? color.gray : color.orange
    colorL2 = narrowing2 ? color.gray : color.orange

    colorU3 = narrowing3 ? color.gray : color.red
    colorL3 = narrowing3 ? color.gray : color.red

    // === Dynamic Fill Colors ===
    fillColorBand12 = narrowing2 ? fillColorNarrow : fillColor1
    fillColorBand23 = narrowing3 ? fillColorNarrow : fillColor2

    // === Plot Lines ===
    plot(basis, “Basis”, color=#000000, offset=offset)

    pU1 = plot(showBand1 ? upper1 : na, “Upper 1σ”, color=showBand1 ? colorU1 : na, offset=offset)
    pL1 = plot(showBand1 ? lower1 : na, “Lower 1σ”, color=showBand1 ? colorL1 : na, offset=offset)

    pU2 = plot(showBand2 ? upper2 : na, “Upper 2σ”, color=showBand2 ? colorU2 : na, offset=offset)
    pL2 = plot(showBand2 ? lower2 : na, “Lower 2σ”, color=showBand2 ? colorL2 : na, offset=offset)

    pU3 = plot(showBand3 ? upper3 : na, “Upper 3σ”, color=showBand3 ? colorU3 : na, offset=offset)
    pL3 = plot(showBand3 ? lower3 : na, “Lower 3σ”, color=showBand3 ? colorL3 : na, offset=offset)

    // === Fill Zones with Dynamic Color ===
    fill(pU1, pU2, color=showFill12 ? fillColorBand12 : na, title=”Fill Upper 1↔2σ”)
    fill(pL1, pL2, color=showFill12 ? fillColorBand12 : na, title=”Fill Lower 1↔2σ”)
    fill(pU2, pU3, color=showFill23 ? fillColorBand23 : na, title=”Fill Upper 2↔3σ”)
    fill(pL2, pL3, color=showFill23 ? fillColorBand23 : na, title=”Fill Lower 2↔3σ”)

    #247786
    JS

    This is the basis of the indicator without the dynamic colors…

    You can choose from 8 different average…

     

    3 users thanked author for this post.
Viewing 2 posts - 1 through 2 (of 2 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login