I have a script in Pine Script and I have a problem because at some point my drawn lines BB and MACD do not overlap the chart candles, so I get an error when I want to check the price above the Bollinger line
//@version=4
// Bollinger Bands on MACD
study(title="Bollinger Bands on MACD", shorttitle="BB on MACD", scale=scale.none, overlay=true)
src = input(close, title="Source")
// 1 - Compute MACD
fastLength = input(12, minval=1, title="MACD Fast EMA Length")
slowLength=input(26, minval=1, title="MACD slow EMA Length")
signalSmoothing=input(9, minval=1, title="MACD Signal Smoothing")
fastEMA = ema(src, fastLength)
slowEMA = ema(src, slowLength)
macd = fastEMA - slowEMA
signal = ema(macd, signalSmoothing)
hist = macd - signal
// 2 - Compute Bollinger Bands on MACD
lengthBB = input(20, minval=1, title="BB Length")
basis = sma(macd, lengthBB)
mult = input(2.0, minval=0.001, maxval=50, title="BB Std Dev Mult. Factor")
upperBB = basis + (mult * stdev(macd, lengthBB))
lowerBB = basis - (mult * stdev(macd, lengthBB))
// Plot colors
bar_grow_above = #26A69A
bar_grow_below = #FFCDD2
bar_fall_above = #B2DFDB
bar_fall_below = #EF5350
bar_macd = #0094ff
bar_signal = #ff6a00
// 3 - Plotting
// 3.1 - Bollinger Bands on MACD
plot(basis, color= color.green, style=plot.style_line, title="BB base line" )
p1 = plot(upperBB, color= color.green, style=plot.style_line, title="BB Upper")
p2 = plot(lowerBB, color= color.lime, style=plot.style_line, title="BB Lower")
fill(p1, p2, color=#9932CC, title="BB Background", transp=95)
// 3.2 - MACD
plot(hist, title="MACD Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? bar_grow_above : bar_fall_above) : (hist[1] < hist ? bar_grow_below : bar_fall_below) ), transp=75 ) // "Deep Pink" color
plot(signal, color= color.orange, style=plot.style_line, title="Signal")
plot(macd, color= color.blue, style=plot.style_line, title="MACD") // "Deep Sky Blue" color
bbCondition= close < lowerBB
plotshape( bbCondition, title="SYGNA?", location=location.top, color=color.red, transp=0, style=shape.triangledown, text="Do something")
Am i doing something wrong? how can I fix it?
My condition is:
bbCondition = close <lowerBB
plotshape (bbCondition, title = "SIGNAL", location = location.top, color = color.red, transp = 0, style = shape.triangledown, text = "Do something")
unfortunately does not work
question from:
https://stackoverflow.com/questions/66062018/why-dont-the-bollinger-bb-lines-overlap-the-candles