OPEN-SOURCE SCRIPT

KayVee Buy Sell Gold Indicator

//version=6
indicator(title="KayTest", overlay=true)

// Input Parameters
src = input(defval=close, title="Source")
per = input.int(defval=100, minval=1, title="Sampling Period")
mult = input.float(defval=3.0, minval=0.1, title="Range Multiplier")

// Smooth Range Function
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothVal = ta.ema(avrng, wper) * m
smoothVal

// Compute Smooth Range
smrng = smoothrng(src, per, mult)

// Range Filter Function
rngfilt(x, r) =>
filtVal = x
filtVal := x > nz(filtVal[1]) ? (x - r < nz(filtVal[1]) ? nz(filtVal[1]) : x - r) : (x + r > nz(filtVal[1]) ? nz(filtVal[1]) : x + r)
filtVal

// Apply Filter
filt = rngfilt(src, smrng)

// Trend Detection
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])

// Bands
hband = filt + smrng
lband = filt - smrng

// Colors
filtcolor = upward > 0 ? color.lime : downward > 0 ? color.red : color.orange
barcolor = src > filt and src > src[1] and upward > 0 ? color.lime :
src > filt and src < src[1] and upward > 0 ? color.green :
src < filt and src < src[1] and downward > 0 ? color.red :
src < filt and src > src[1] and downward > 0 ? color.maroon : color.orange

// Plot Indicators
plot(filt, color=filtcolor, linewidth=3, title="Range Filter")
plot(hband, color=color.new(color.aqua, 90), title="High Target")
plot(lband, color=color.new(color.fuchsia, 90), title="Low Target")

// Fill the areas between the bands and filter line
fill1 = plot(hband, color=color.new(color.aqua, 90), title="High Target")
fill2 = plot(filt, color=color.new(color.aqua, 90), title="Range Filter")
fill(fill1, fill2, color=color.new(color.aqua, 90), title="High Target Range")

fill3 = plot(lband, color=color.new(color.fuchsia, 90), title="Low Target")
fill4 = plot(filt, color=color.new(color.fuchsia, 90), title="Range Filter")
fill(fill3, fill4, color=color.new(color.fuchsia, 90), title="Low Target Range")

barcolor(barcolor)

// Buy and Sell Conditions (adjusting for correct line continuation)
longCond1 = (src > filt) and (src > src[1]) and (upward > 0)
longCond2 = (src > filt) and (src < src[1]) and (upward > 0)
longCond = longCond1 or longCond2

shortCond1 = (src < filt) and (src < src[1]) and (downward > 0)
shortCond2 = (src < filt) and (src > src[1]) and (downward > 0)
shortCond = shortCond1 or shortCond2

// Initialization of Condition
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]

// Long and Short Signals
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1

// Plot Signals
plotshape(longCondition, title="Buy Signal", text="Buy", textcolor=color.white, style=shape.labelup, size=size.normal, location=location.belowbar, color=color.green)
plotshape(shortCondition, title="Sell Signal", text="Sell", textcolor=color.white, style=shape.labeldown, size=size.normal, location=location.abovebar, color=color.red)

// Alerts
alertcondition(longCondition, title="Buy Alert", message="BUY")
alertcondition(shortCondition, title="Sell Alert", message="SELL")
Trend Analysis

Script de código abierto

Siguiendo fielmente el espíritu de TradingView, el autor de este script lo ha publicado en código abierto, permitiendo que otros traders puedan entenderlo y verificarlo. ¡Olé por el autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la reutilización de este código en la publicación se rige por las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

¿Quiere utilizar este script en un gráfico?

Exención de responsabilidad