Hello Fam! I'm having an issue on tradingview. I merged two scripts together to make it one indicator. The bottom indicator merges with the top indicator (4 MAs).
Does anyone know how to stop that from happening? thanks!
//@version=4
study("4 EMA Crossover" , overlay=true)
len1 = input(8, minval=1, title="MA1")
len2 = input(13, minval=1, title="MA2")
len3 = input(21, minval=1, title="MA3")
len4 = input(55, minval=1, title="MA4")
ma1 = ema(close, len1)
ma2 = ema(close, len2)
ma3 = ema(close, len3)
ma4 = ema(close, len4)
plot(ma1, title="MA1", color=color.blue)
plot(ma2, title="MA2", color=color.red)
plot(ma3, title="MA3", color=color.green)
plot(ma4, title="MA4", color=color.orange)
longCond = bool(na)
shortCond = bool(na)
longCond := ma1 > ma4 and ma2 > ma4 and ma3 > ma4
shortCond := ma1 < ma4 and ma2 < ma4 and ma3 < ma4
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1
plotshape(longCondition, title="Buy Signal", text="B", textcolor=color.white, style=shape.labelup, size=size.tiny, location=location.belowbar, color=color.green, transp=0)
plotshape(shortCondition, title="Short Signal", text="S", textcolor=color.white, style=shape.labeldown, size=size.tiny, location=location.abovebar, color=color.red, transp=0)
alertcondition(longCondition, title='EMA Cross UP', message='EMA Cross UP')
alertcondition(shortCondition, title='EMA Cross DOWN', message='EMA Cross DOWN')
periodK = input(title="K", minval=1, defval=14)
periodD = input(title="D", minval=1, defval=3)
smoothK = input(title="Smooth", minval=1, defval=3)
src = input(title="Source", type=input.source, defval=close)
obLevel = input(title="Overbought Level", type=input.integer, defval=80)
osLevel = input(title="Oversold Level", type=input.integer, defval=20)
maxLevel = input(title="Max Level", type=input.integer, defval=100)
minLevel = input(title="Min Level", type=input.integer, defval=0)
showHistogram = input(title="Show Histogram ?", type=input.bool, defval=false)
highlightBreakouts = input(title="Highlight Overbought/Oversold Breakouts ?", type=input.bool, defval=true)
highlightCrossovers = input(title="Highlight K/D Crossovers ?", type=input.bool, defval=true)
highlightMiddleCrossovers = input(title="Highlight Middle Line Crossovers ?", type=input.bool, defval=true)
applyRibbonFilling = input(title="Apply Ribbon Filling ?", type=input.bool, defval=true)
k = sma(stoch(src, high, low, periodK), smoothK)
d = sma(k, periodD)
trendColor = k > d ? #0ebb23 : color.red
kColor = applyRibbonFilling ? trendColor : #ff3e7d
dColor = applyRibbonFilling? trendColor : #3c78d8
kPlot = plot(k, title="%K", color=kColor, transp=0)
dPlot = plot(d, title="%D", color=dColor, transp=0)
hist = k - d
histColor = hist >= 0 ? hist[1] < hist ? #26A69A : #B2DFDB : hist[1] < hist ? #FFCDD2 : #EF5350
plot(showHistogram ? hist : na, title="Histogram", style=plot.style_columns, color=histColor, transp=0)
var color noneColor = color.new(color.white, 100)
maxLevelPlot = hline(maxLevel, title="Max Level", linestyle=hline.style_dotted, color=noneColor)
obLevelPlot = hline(obLevel, title="Overbought Level", linestyle=hline.style_dotted, color=#00796b)
hline(50, title="Middle Level", linestyle=hline.style_dotted, color=#989898)
osLevelPlot = hline(osLevel, title="Oversold Level", linestyle=hline.style_dotted, color=#f57f17)
minLevelPlot = hline(minLevel, title="Min Level", linestyle=hline.style_dotted, color=noneColor)
fill(obLevelPlot, osLevelPlot, title="Middle Zone", color=color.purple, transp=95)
obFillColor = k > obLevel and highlightBreakouts ? color.green : na
osFillColor = k < osLevel and highlightBreakouts ? color.red : na
fill(maxLevelPlot, obLevelPlot, title="Upper Band Breakout", color=obFillColor, transp=85)
fill(minLevelPlot, osLevelPlot, title="Lower Band Breakout", color=osFillColor, transp=85)
fillColor = applyRibbonFilling ? trendColor : na
fill(kPlot, dPlot, title="Ribbon", color=fillColor, transp=70)
middleCrossBgColor = highlightMiddleCrossovers ? (k > 50 ? color.green : color.red) : na
bgcolor(middleCrossBgColor, transp=90)
plotshape(highlightCrossovers and crossover(k, d) ? k : na, title="K/D Crossover", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(highlightCrossovers and crossunder(k, d) ? k : na, title="K/D Crossunder", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)