Reputation: 25
I've tried to add alertcondition if area color is green/lime = buy and if red/maroon = sell, but since indicator is in v1 I can't find any doc nor know how to program very well in v1.
Could someone help me translate to v5 or put the alertconditions? thanks
study(shorttitle = "SQZMOM_LB", title="Squeeze Momentum Indicator", overlay=false)
length = input(20, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")
useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
// Calculate BB
source = close
basis = sma(source, length)
dev = multKC * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz = (sqzOn == false) and (sqzOff == false)
val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)),
lengthKC,0)
bcolor = iff( val > 0,
iff( val > nz(val[1]), lime, maroon),
iff( val < nz(val[1]), red, green))
scolor = noSqz ? blue : sqzOn ? black : gray
plot(val, color=bcolor, style=area, linewidth=4)
plot(0, color=scolor, style=cross, linewidth=2)
Upvotes: 0
Views: 376
Reputation: 1699
Note: some colors are different because of inherent differences between default colors in different Pine versions.
//@version=5
indicator(shorttitle = "SQZMOM_LB", title="Squeeze Momentum Indicator", overlay=false)
length = input.int(20, title="BB Length")
mult = input.float(2.0,title="BB MultFactor")
lengthKC=input.int(20, title="KC Length")
multKC = input.float(1.5, title="KC MultFactor")
useTrueRange = input.bool(true, title="Use TrueRange (KC)")
// Calculate BB
source = close
basis = ta.sma(source, length)
dev = multKC * ta.stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
// Calculate KC
ma = ta.sma(source, lengthKC)
_range = useTrueRange ? ta.tr : (high - low)
rangema = ta.sma(_range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz = (sqzOn == false) and (sqzOff == false)
val = ta.linreg(source - math.avg(math.avg(ta.highest(high, lengthKC), ta.lowest(low, lengthKC)), ta.sma(close,lengthKC)), lengthKC,0)
bcolor = val > 0 ?
val > nz(val[1]) ? color.lime : color.maroon :
val < nz(val[1]) ? color.red : color.green
scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray
plot(val, color=bcolor, style=plot.style_area, linewidth=4)
plot(0, color=scolor, style=plot.style_cross, linewidth=2)
Upvotes: 1