Code: Select all
//@version=5
//Created by Rajkumar on 13/8/2022
//Bar Color Based on Above/Below EMA...
/////////////////////////////////////////////////////////////////////////
ema1 = input.int(34, minval=1, maxval=300, title='EMA')
shema = input(true, title='Show EMA')
usedEma = ta.ema(close, ema1)
emaUpColor() =>hlc3 >= usedEma
emaDownColor() => hlc3 < usedEma
col = hlc3 >= usedEma ? #00ff00 : hlc3 < usedEma ? #ff0000 : color.white
plot(shema and usedEma ? usedEma : na, title='EMA', style=plot.style_line, linewidth=3, color=col)
emaDownColor_1 = emaDownColor()
barcolor(emaUpColor() ? #00ff00 : emaDownColor_1 ? #ff0000 : na, title='EMA Bar Color')
///////////////////////////////////////////////////////////////////////
// EMA 4x1
// 4 EMA en 1 Indicador
indicator(shorttitle='RAJKUMAR EMA 4x1', title='4 EMA en 1 Indicador', overlay=true)
m0 = input.int(14, minval=1, title='EMA 14')
m1 = input.int(50, minval=1,title='EMA 50')
m2 = input.int(80, minval=1,title='EMA 80')
m3 = input.int(100, minval=1,title='EMA 100')
src = input(close, title='Source')
media_0 = ta.ema(src, m0)
media_1 = ta.ema(src, m1)
media_2 = ta.ema(src, m2)
media_3 = ta.ema(src, m3)
plot(media_0, color=color.new(color.green, 0),title='EMA 14')
plot(media_1, color=color.new(color.green, 0),title='EMA 50')
plot(media_2, color=color.new(color.red, 0),title='EMA 80')
plot(media_3, color=color.new(color.blue, 0),title='EMA 100')
////////////////////////////////////////////////////////////////////
nLong = input.int(50, minval=1, maxval=300, title='Long SMA')
averagePrice = hlc3
longSMA = ta.sma(averagePrice, nLong)
plot(longSMA, color=color.new(color.green, 0), linewidth=3, title='SMA')
/////////////////////////////////////////////////////////////////////
//@version=5
// Color variables
upColor = #00FF00
midColor = #90bff9
downColor = #FF0000
// Range Multiplier
mult = input.float(defval=2.5, minval=0.1, title="Range Multiplier", group ="Range Filter")
// Sampling Period
per = input.int(defval=100, minval=1, title="Sampling Period")
// Source
src := input(defval=close, title="Source")
// Smooth Average Range
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng = smoothrng(src, per, mult)
// Range Filter
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r :
x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(src, smrng)
// Filter Direction
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1])
// Target Bands
hband = filt + smrng
lband = filt - smrng
// Colors
filtcolor = upward > 0 ? upColor : downward > 0 ? downColor : midColor
barcolor = src > filt and src > src[1] and upward > 0 ? upColor :
src > filt and src < src[1] and upward > 0 ? upColor :
src < filt and src < src[1] and downward > 0 ? downColor :
src < filt and src > src[1] and downward > 0 ? downColor : midColor
filtplot = plot(filt, color=filtcolor, linewidth=2, title="Range Filter")
barcolor( upward > 0 ? upColor : downward > 0 ? downColor : midColor, title='Bar Color(Range filter)')
// Break Outs
longCond = bool(na)
shortCond = bool(na)
longCond := src > filt and src > src[1] and upward > 0 or
src > filt and src < src[1] and upward > 0
shortCond := src < filt and src < src[1] and downward > 0 or
src < filt and src > src[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1
//Alerts
plotshape(longCondition, title="Buy Signal", text="Buy", textcolor=color.white, style=shape.labelup, size=size.small, location=location.belowbar, color=color.new(#008000, 20))
plotshape(shortCondition, title="Sell Signal", text="Sell", textcolor=color.white, style=shape.labeldown, size=size.small, location=location.abovebar, color=color.new(#FF0000, 20))
alertcondition(longCondition, title="Buy alert on Range Filter", message="Buy alert on Range Filter")
alertcondition(shortCondition, title="Sell alert on Range Filter", message="Sell alert on Range Filter")
alertcondition(longCondition or shortCondition, title="Buy and Sell alert on Range Filter", message="Buy and Sell alert on Range Filter")