necesito me ayudes a combinar estos 3 indicadores para usarlos en traiding view. primero…
- User
necesito me ayudes a combinar estos 3 indicadores para usarlos en traiding view. primero este: //Defaults to current timeframe Ability to change to different timeframe, or plot two RSI's on different timeframes.
study(title="CM_Stochastic_MTF", shorttitle="CM_Stoch_MTF")
len = input(14, minval=1, title="Length for Main Stochastic")
smoothK = input(3, minval=1, title="SmoothK for Main Stochastic")
smoothD = input(3, minval=1, title="SmoothD for Main Stochastic")
upLine = input(80, minval=50, maxval=90, title="Upper Line Value?")
lowLine = input(20, minval=10, maxval=50, title="Lower Line Value?")
sml = input(true, title="Show Mid Line?")
sbh = input(false, title="Show Back Ground Highlights When Stoch is Above/Below High/Low Lines?")
sch = input(true, title="Show Back Ground Highlights When Stoch Cross - Strict Criteria - K Greater/LesThan High/Low Line - Crosses D ?")
sl = input(true, title="Show 'B' and 'S' Letters When Stoch Crosses High/Low Line & D?")
sac = input(false, title="Show Back Ground Highlights When Stoch Cross - Any Cross?")
sacl = input(false, title="Show 'B' and 'S' Letters When Stoch Crosses - Any Cross?")
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="60")
ssStoch = input(false, title="Show 2nd Stoch?")
resCustom2 = input(title="Use 2nd Stoch? Check Box Above", type=resolution, defval="D")
useCurrentRes2 = input(false, title="Use 2nd Stoch Plot On Samet Timeframe?")
len2 = input(14, minval=1, title="2nd Stoch Length")
smoothK2 = input(3, minval=1, title="SmoothK for 2nd Stoch")
smoothD2 = input(3, minval=1, title="SmoothD for 2nd Stoch")
//Resolutioon for MTF
res = useCurrentRes ? period : resCustom
res2 = useCurrentRes2 ? period : resCustom2
//Stoch formula
k = sma(stoch(close, high, low, len), smoothK)
d = sma(k, smoothD)
outK = security(tickerid, res, k)
outD = security(tickerid, res, d)
//Optional 2nd Stoch for additional plot
k2 = sma(stoch(close, high, low, len2), smoothK2)
d2 = sma(k2, smoothD2)
outK2 = security(tickerid, res2, k2)
outD2 = security(tickerid, res2, d2)
//definitions for Cross
aboveLine = outK > upLine ? 1 : 0
belowLine = outK < lowLine ? 1 : 0
crossUp = (outK[1] < outD[1] and outK[1] < lowLine[1]) and (outK > outD) ? 1 : 0
crossDn = (outK[1] > outD[1] and outK[1] > upLine[1]) and (outK < outD) ? 1 : 0
//Definition for Cross that doesn't have to be above or below High and Low line.
crossUpAll = (outK[1] < outD[1] and outK > outD) ? 1 : 0
crossDownAll = (outK[1] > outD[1] and outK < outD) ? 1 : 0
//BackGroound Color Plots
bgcolor(sbh and aboveLine ? red : na, transp=70)
bgcolor(sbh and belowLine ? lime : na, transp=70)
bgcolor(sch and crossUp ? lime : na, transp=40)
bgcolor(sch and crossDn ? red : na, transp=40)
//plots for Cross with no filter
bgcolor(sac and crossUpAll ? lime : na, transp=40)
bgcolor(sac and crossDownAll ? red : na, transp=40)
//Plot main Stochastic
plot(outK, title="Stoch K", style=line, linewidth=3, color=lime)
plot(outD, title="Stoch D", style=line, linewidth=3, color=red)
//Ability to plot 2nd Stoch
plot(ssStoch and outK2 ? outK2 : na, title="2nd Stoch K - Different TimeFrame", style=line, linewidth=3, color=orange)
plot(ssStoch and outD2 ? outD2 : na, title="2nd Stoch D - Different TimeFrame", style=line, linewidth=3, color=yellow)
p1 = plot(upLine, title= "Upper Line", style=solid, linewidth=3, color=red)
p2 = plot(lowLine, title= "Lower Line", style=solid, linewidth=3, color=lime)
plot(sml and 50 ? 50 : na, title="Mid Line", style=linebr, linewidth=2, color=gray)
plotchar(sl and crossUp ? crossUp : na, title="Buy Signal Strict Criteria", char='B', location=location.bottom, color=lime, transp=0, offset=0)
plotchar(sl and crossDn ? crossDn : na, title="Sell Signal Strict Criteria", char='S', location=location.top, color=red, transp=0, offset=0)
plotchar(sacl and crossUpAll ? crossUpAll : na, title="Buy Signal Any Cross Up", char='B', location=location.bottom, color=lime, transp=0, offset=0)
plotchar(sacl and crossDownAll ? crossDownAll : na, title="Sell Signal Any Cross Down", char='S', location=location.top, color=red, transp=0, offset=0)
fill(p1, p2, color=silver, transp=70) segundo este: study("WMAMulti", overlay=true)
tf1 = input(title="time frame 1", defval="15")
tf2 = input(title="time frame 2", defval="30")
tf3 = input(title="time frame 3", defval="60")
length = input(title="length", defval=20)
ma1 = security(tickerid, tf1, wma(hl2, length))
ma2 = security(tickerid, tf2, wma(hl2, length))
ma3 = security(tickerid, tf3, wma(hl2, length))
getcolor (avg, tf) =>
prev = security(tickerid, tf, wma(hl2, length)[1]) avg >= prev ? green : redplot(ma3, color=getcolor(ma3, tf3), style=line, linewidth=3)
plot(ma2, color=getcolor(ma2, tf2), style=line, linewidth=3)
plot(ma1, color=getcolor(ma1, tf1), style=line, linewidth=3) y tercero este: study(shorttitle = "SQZMOM_LB", title="Squeeze Momentum Indicator [LazyBear]", 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, green), iff( val < nz(val[1]), red, maroon))scolor = noSqz ? blue : sqzOn ? black : gray
plot(val, color=bcolor, style=histogram, linewidth=4)
plot(0, color=scolor, style=cross, linewidth=2)
- Assistant
Para combinar los tres indicadores que has proporcionado, podemos combinar el código de cada uno en un solo script de Pine Script para TradingView. Aquí te muestro cómo hacerlo, asegurándome de conservar la funcionalidad de cada indicador y evitando conflictos de nombres y variables.
A continuación, fusiono las tres partes en uno solo:
//@version=5 indicator("Combined Indicators", overlay=false) // --- CM_Stochastic_MTF --- len = input(14, minval=1, title="Length for Main Stochastic") smoothK = input(3, minval=1, title="SmoothK for Main Stochastic") smoothD = input(3, minval=1, title="SmoothD for Main Stochastic") upLine = input(80, minval=50, maxval=90, title="Upper Line Value?") lowLine = input(20, minval=10, maxval=50, title="Lower Line Value?") sml = input(true, title="Show Mid Line?") sbh = input(false, title="Show Back Ground Highlights When Stoch is Above/Below High/Low Lines?") sch = input(true, title="Show Back Ground Highlights When Stoch Cross - Strict Criteria - K Greater/LesThan High/Low Line - Crosses D?") sl = input(true, title="Show 'B' and 'S' Letters When Stoch Crosses High/Low Line & D?") sac = input(false, title="Show Back Ground Highlights When Stoch Cross - Any Cross?") sacl = input(false, title="Show 'B' and 'S' Letters When Stoch Crosses - Any Cross?") useCurrentRes = input(true, title="Use Current Chart Resolution?") resCustom = input.timeframe("60", title="Use Different Timeframe? Uncheck Box Above") ssStoch = input(false, title="Show 2nd Stoch?") resCustom2 = input.timeframe("D", title="Use 2nd Stoch? Check Box Above") len2 = input(14, minval=1, title="2nd Stoch Length") smoothK2 = input(3, minval=1, title="SmoothK for 2nd Stoch") smoothD2 = input(3, minval=1, title="SmoothD for 2nd Stoch") // Resolution for MTF res = useCurrentRes ? timeframe.period : resCustom k = ta.sma(ta.stoch(close, high, low, len), smoothK) d = ta.sma(k, smoothD) outK = request.security(syminfo.tickerid, res, k) outD = request.security(syminfo.tickerid, res, d) k2 = ta.sma(ta.stoch(close, high, low, len2), smoothK2) d2 = ta.sma(k2, smoothD2) outK2 = request.security(syminfo.tickerid, resCustom2, k2) outD2 = request.security(syminfo.tickerid, resCustom2, d2) // Definitions for Cross crossUp = (outK[1] < outD[1]) and (outK > outD) crossDn = (outK[1] > outD[1]) and (outK < outD) // Plot main Stochastic plot(outK, title="Stoch K", color=color.lime, linewidth=3) plot(outD, title="Stoch D", color=color.red, linewidth=3) // --- WMAMulti --- tf1 = input("15", title="time frame 1") tf2 = input("30", title="time frame 2") tf3 = input("60", title="time frame 3") length = input(20, title="length") ma1 = request.security(syminfo.tickerid, tf1, ta.wma(hl2, length)) ma2 = request.security(syminfo.tickerid, tf2, ta.wma(hl2, length)) ma3 = request.security(syminfo.tickerid, tf3, ta.wma(hl2, length)) getcolor(avg, tf) => prev = request.security(syminfo.tickerid, tf, ta.wma(hl2, length)[1]) avg >= prev ? color.green : color.red // Plot WMA plot(ma1, color=getcolor(ma1, tf1), linewidth=3) plot(ma2, color=getcolor(ma2, tf2), linewidth=3) plot(ma3, color=getcolor(ma3, tf3), linewidth=3) // --- SQZMOM_LB --- 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=input.bool) // 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 = not sqzOn and not sqzOff val = ta.linreg(source - math.avg(math.highest(high, lengthKC), math.lowest(low, lengthKC)), lengthKC, 0) bcolor = val > 0 ? (val > nz(val[1]) ? color.lime : color.green) : (val < nz(val[1]) ? color.red : color.maroon) scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray plot(val, color=bcolor, style=plot.style_histogram, linewidth=4) plot(0, color=scolor, style=plot.style_cross, linewidth=2)Descripción del Código:
- CM_Stochastic_MTF: Calcula el indicador estocástico en múltiples marcos de tiempo y proporciona señales de compra y venta basadas en cruzamientos.
- WMAMulti: Calcula las medias móviles ponderadas (WMA) en tres marcos de tiempo diferentes y cambia de color si el valor del WMA actual es mayor que el anterior.
- SQZMOM_LB: Calcula el Squeeze Momentum Indicator y representa el valor como un histograma, además de delinear la presión de compresión con BB y KC.
Cómo Usar:
- Copia el código anterior en el editor de Pine Script en TradingView.
- Ajusta los parámetros según sea necesario en la configuración del indicador.
- Guarda y aplica el indicador en tu gráfico.
Este script combina las funcionalidades de los tres indicadores que proporcionaste, y debes poder ver todos ellos en tu gráfico de TradingView. Puedes personalizar los colores y otros parámetros según tus preferencias.
- User
hola
- Assistant
¡Hola! ¿En qué puedo ayudarte hoy?
- User
en este indicador combinado puedes agregarle que me emita alertas con alguna figura cuando en los 3 coincidan sus alertas? //@version=5 indicator("Combined Indicators", overlay=false)
// --- CM_Stochastic_MTF --- len = input(14, minval=1, title="Length for Main Stochastic") smoothK = input(3, minval=1, title="SmoothK for Main Stochastic") smoothD = input(3, minval=1, title="SmoothD for Main Stochastic") upLine = input(80, minval=50, maxval=90, title="Upper Line Value?") lowLine = input(20, minval=10, maxval=50, title="Lower Line Value?") sml = input(true, title="Show Mid Line?") sbh = input(false, title="Show Back Ground Highlights When Stoch is Above/Below High/Low Lines?") sch = input(true, title="Show Back Ground Highlights When Stoch Cross - Strict Criteria - K Greater/LesThan High/Low Line - Crosses D?") sl = input(true, title="Show 'B' and 'S' Letters When Stoch Crosses High/Low Line & D?") sac = input(false, title="Show Back Ground Highlights When Stoch Cross - Any Cross?") sacl = input(false, title="Show 'B' and 'S' Letters When Stoch Crosses - Any Cross?") useCurrentRes = input(true, title="Use Current Chart Resolution?") resCustom = input.timeframe("60", title="Use Different Timeframe? Uncheck Box Above") ssStoch = input(false, title="Show 2nd Stoch?") resCustom2 = input.timeframe("D", title="Use 2nd Stoch? Check Box Above") len2 = input(14, minval=1, title="2nd Stoch Length") smoothK2 = input(3, minval=1, title="SmoothK for 2nd Stoch") smoothD2 = input(3, minval=1, title="SmoothD for 2nd Stoch")
// Resolution for MTF res = useCurrentRes ? timeframe.period : resCustom k = ta.sma(ta.stoch(close, high, low, len), smoothK) d = ta.sma(k, smoothD) outK = request.security(syminfo.tickerid, res, k) outD = request.security(syminfo.tickerid, res, d)
k2 = ta.sma(ta.stoch(close, high, low, len2), smoothK2) d2 = ta.sma(k2, smoothD2) outK2 = request.security(syminfo.tickerid, resCustom2, k2) outD2 = request.security(syminfo.tickerid, resCustom2, d2)
// Definitions for Cross crossUp = (outK[1] < outD[1]) and (outK > outD) crossDn = (outK[1] > outD[1]) and (outK < outD)
// Plot main Stochastic plot(outK, title="Stoch K", color=color.lime, linewidth=3) plot(outD, title="Stoch D", color=color.red, linewidth=3)
// --- WMAMulti --- tf1 = input("15", title="time frame 1") tf2 = input("30", title="time frame 2") tf3 = input("60", title="time frame 3") length = input(20, title="length")
ma1 = request.security(syminfo.tickerid, tf1, ta.wma(hl2, length)) ma2 = request.security(syminfo.tickerid, tf2, ta.wma(hl2, length)) ma3 = request.security(syminfo.tickerid, tf3, ta.wma(hl2, length))
getcolor(avg, tf) => prev = request.security(syminfo.tickerid, tf, ta.wma(hl2, length)[1]) avg >= prev ? color.green : color.red
// Plot WMA plot(ma1, color=getcolor(ma1, tf1), linewidth=3) plot(ma2, color=getcolor(ma2, tf2), linewidth=3) plot(ma3, color=getcolor(ma3, tf3), linewidth=3)
// --- SQZMOM_LB --- 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=input.bool)
// 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 = not sqzOn and not sqzOff
val = ta.linreg(source - math.avg(math.highest(high, lengthKC), math.lowest(low, lengthKC)), lengthKC, 0)
bcolor = val > 0 ? (val > nz(val[1]) ? color.lime : color.green) : (val < nz(val[1]) ? color.red : color.maroon) scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray
plot(val, color=bcolor, style=plot.style_histogram, linewidth=4) plot(0, color=scolor, style=plot.style_cross, linewidth=2)
- Assistant
Para agregar alertas en tu indicador combinado que se activen cuando todos los indicadores (Stochastic, WMA y Squeeze Momentum) coincidan en sus señales, necesitaríamos establecer condiciones específicas que indiquen esta coincidencia y luego emitir una alerta basada en esas condiciones.
A continuación, te muestro cómo puedes modificar tu script para incluir esas alertas. En este caso, consideraremos que las alertas se activarán cuando el Stochastic muestre un cruce hacia arriba o hacia abajo, y cuando el Squeeze Momentum esté en "squeeze on" o "squeeze off".
Aquí tienes el código actualizado:
//@version=5 indicator("Combined Indicators with Alerts", overlay=false) // --- CM_Stochastic_MTF --- len = input(14, minval=1, title="Length for Main Stochastic") smoothK = input(3, minval=1, title="SmoothK for Main Stochastic") smoothD = input(3, minval=1, title="SmoothD for Main Stochastic") upLine = input(80, minval=50, maxval=90, title="Upper Line Value?") lowLine = input(20, minval=10, maxval=50, title="Lower Line Value?") sml = input(true, title="Show Mid Line?") sbh = input(false, title="Show Back Ground Highlights When Stoch is Above/Below High/Low Lines?") sch = input(true, title="Show Back Ground Highlights When Stoch Cross - Strict Criteria - K Greater/LesThan High/Low Line - Crosses D?") sl = input(true, title="Show 'B' and 'S' Letters When Stoch Crosses High/Low Line & D?") sac = input(false, title="Show Back Ground Highlights When Stoch Cross - Any Cross?") sacl = input(false, title="Show 'B' and 'S' Letters When Stoch Crosses - Any Cross?") useCurrentRes = input(true, title="Use Current Chart Resolution?") resCustom = input.timeframe("60", title="Use Different Timeframe? Uncheck Box Above") ssStoch = input(false, title="Show 2nd Stoch?") resCustom2 = input.timeframe("D", title="Use 2nd Stoch? Check Box Above") len2 = input(14, minval=1, title="2nd Stoch Length") smoothK2 = input(3, minval=1, title="SmoothK for 2nd Stoch") smoothD2 = input(3, minval=1, title="SmoothD for 2nd Stoch") // Resolution for MTF res = useCurrentRes ? timeframe.period : resCustom k = ta.sma(ta.stoch(close, high, low, len), smoothK) d = ta.sma(k, smoothD) outK = request.security(syminfo.tickerid, res, k) outD = request.security(syminfo.tickerid, res, d) k2 = ta.sma(ta.stoch(close, high, low, len2), smoothK2) d2 = ta.sma(k2, smoothD2) outK2 = request.security(syminfo.tickerid, resCustom2, k2) outD2 = request.security(syminfo.tickerid, resCustom2, d2) // Definitions for Cross crossUp = (outK[1] < outD[1]) and (outK > outD) crossDn = (outK[1] > outD[1]) and (outK < outD) // Plot main Stochastic plot(outK, title="Stoch K", color=color.lime, linewidth=3) plot(outD, title="Stoch D", color=color.red, linewidth=3) // --- WMAMulti --- tf1 = input("15", title="time frame 1") tf2 = input("30", title="time frame 2") tf3 = input("60", title="time frame 3") length = input(20, title="length") ma1 = request.security(syminfo.tickerid, tf1, ta.wma(hl2, length)) ma2 = request.security(syminfo.tickerid, tf2, ta.wma(hl2, length)) ma3 = request.security(syminfo.tickerid, tf3, ta.wma(hl2, length)) getcolor(avg, tf) => prev = request.security(syminfo.tickerid, tf, ta.wma(hl2, length)[1]) avg >= prev ? color.green : color.red // Plot WMA plot(ma1, color=getcolor(ma1, tf1), linewidth=3) plot(ma2, color=getcolor(ma2, tf2), linewidth=3) plot(ma3, color=getcolor(ma3, tf3), linewidth=3) // --- SQZMOM_LB --- lengthSQZ = 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=input.bool) // Calculate BB source = close basis = ta.sma(source, lengthSQZ) dev = multKC * ta.stdev(source, lengthSQZ) 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 = not sqzOn and not sqzOff val = ta.linreg(source - math.avg(math.highest(high, lengthKC), math.lowest(low, lengthKC)), lengthKC, 0) bcolor = val > 0 ? (val > nz(val[1]) ? color.lime : color.green) : (val < nz(val[1]) ? color.red : color.maroon) scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray plot(val, color=bcolor, style=plot.style_histogram, linewidth=4) plot(0, color=scolor, style=plot.style_cross, linewidth=2) // --- Alerts --- stochBuySignal = crossUp stochSellSignal = crossDn squeezeSignal = sqzOn ? 1 : sqzOff ? -1 : 0 // Check for coinciding signals buyCondition = stochBuySignal and (squeezeSignal == 1) // Stochastic bullish cross & squeeze on sellCondition = stochSellSignal and (squeezeSignal == -1) // Stochastic bearish cross & squeeze off // Alert conditions alertcondition(buyCondition, title="Buy Alert", message="Buy Signal: Stochastic Cross Up + Squeeze On!") alertcondition(sellCondition, title="Sell Alert", message="Sell Signal: Stochastic Cross Down + Squeeze Off!") // Optional plot for visual verification plotshape(buyCondition, style=shape.labelup, location=location.belowbar, color=color.green, size=size.small, title="Buy Alert Signal", text="BUY") plotshape(sellCondition, style=shape.labeldown, location=location.abovebar, color=color.red, size=size.small, title="Sell Alert Signal", text="SELL")Cambios Realizados:
-
Alertas: Agregué las condiciones para las alertas cuando hay coincidencias en las señales de los indicadores.
- Se activa una alerta de compra cuando el Stochastic cruza hacia arriba y el indicador Squeeze está activado (squeeze on).
- Se activa una alerta de venta cuando el Stochastic cruza hacia abajo y el indicador Squeeze está desactivado (squeeze off).
-
Figuras Visuales: Añadí gráficos que marcan en el gráfico las alertas de compra y venta con etiquetas.
Uso:
- Cuando las condiciones de compra o venta se cumplan, recibirás alertas (que puedes configurar en TradingView) y verás las etiquetas correspondientes en el gráfico.
- Ajusta los mensajes, colores o cualquier otro parámetro según tus preferencias.
Guarda y aplica el script en tu gráfico de TradingView. Si hay algo más que te gustaría ajustar, ¡hazmelo saber!
-
- User
necesito me modifiques este script para incluir alertas cuando coincidan los 3 indicadores a la vez en que el stochastic muestre un cruce hacia arriba o hacia abajo en zonas de sobre compra por encima de 90 o en zona de sobre venta por debajo de 10, cuando el Squeeze Momentum esté en "squeeze on" o "squeeze off" y en el WMA las media movil de 15 y la de 30 se crucen hacia arriba o hacia abajo y las velas del precio reboten por encima al alsa o por debajo a la baja con la media movil de 60. //@version=5 indicator("Combined Indicators with Alerts", overlay=false)
// --- CM_Stochastic_MTF --- len = input(14, minval=1, title="Length for Main Stochastic") smoothK = input(3, minval=1, title="SmoothK for Main Stochastic") smoothD = input(3, minval=1, title="SmoothD for Main Stochastic") upLine = input(80, minval=50, maxval=90, title="Upper Line Value?") lowLine = input(20, minval=10, maxval=50, title="Lower Line Value?") sml = input(true, title="Show Mid Line?") sbh = input(false, title="Show Back Ground Highlights When Stoch is Above/Below High/Low Lines?") sch = input(true, title="Show Back Ground Highlights When Stoch Cross - Strict Criteria - K Greater/LesThan High/Low Line - Crosses D?") sl = input(true, title="Show 'B' and 'S' Letters When Stoch Crosses High/Low Line & D?") sac = input(false, title="Show Back Ground Highlights When Stoch Cross - Any Cross?") sacl = input(false, title="Show 'B' and 'S' Letters When Stoch Crosses - Any Cross?") useCurrentRes = input(true, title="Use Current Chart Resolution?") resCustom = input.timeframe("60", title="Use Different Timeframe? Uncheck Box Above") ssStoch = input(false, title="Show 2nd Stoch?") resCustom2 = input.timeframe("D", title="Use 2nd Stoch? Check Box Above") len2 = input(14, minval=1, title="2nd Stoch Length") smoothK2 = input(3, minval=1, title="SmoothK for 2nd Stoch") smoothD2 = input(3, minval=1, title="SmoothD for 2nd Stoch")
// Resolution for MTF res = useCurrentRes ? timeframe.period : resCustom k = ta.sma(ta.stoch(close, high, low, len), smoothK) d = ta.sma(k, smoothD) outK = request.security(syminfo.tickerid, res, k) outD = request.security(syminfo.tickerid, res, d)
k2 = ta.sma(ta.stoch(close, high, low, len2), smoothK2) d2 = ta.sma(k2, smoothD2) outK2 = request.security(syminfo.tickerid, resCustom2, k2) outD2 = request.security(syminfo.tickerid, resCustom2, d2)
// Definitions for Cross crossUp = (outK[1] < outD[1]) and (outK > outD) crossDn = (outK[1] > outD[1]) and (outK < outD)
// Plot main Stochastic plot(outK, title="Stoch K", color=color.lime, linewidth=3) plot(outD, title="Stoch D", color=color.red, linewidth=3)
// --- WMAMulti --- tf1 = input("15", title="time frame 1") tf2 = input("30", title="time frame 2") tf3 = input("60", title="time frame 3") length = input(20, title="length")
ma1 = request.security(syminfo.tickerid, tf1, ta.wma(hl2, length)) ma2 = request.security(syminfo.tickerid, tf2, ta.wma(hl2, length)) ma3 = request.security(syminfo.tickerid, tf3, ta.wma(hl2, length))
getcolor(avg, tf) => prev = request.security(syminfo.tickerid, tf, ta.wma(hl2, length)[1]) avg >= prev ? color.green : color.red
// Plot WMA plot(ma1, color=getcolor(ma1, tf1), linewidth=3) plot(ma2, color=getcolor(ma2, tf2), linewidth=3) plot(ma3, color=getcolor(ma3, tf3), linewidth=3)
// --- SQZMOM_LB --- lengthSQZ = 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=input.bool)
// Calculate BB source = close basis = ta.sma(source, lengthSQZ) dev = multKC * ta.stdev(source, lengthSQZ) 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 = not sqzOn and not sqzOff
val = ta.linreg(source - math.avg(math.highest(high, lengthKC), math.lowest(low, lengthKC)), lengthKC, 0)
bcolor = val > 0 ? (val > nz(val[1]) ? color.lime : color.green) : (val < nz(val[1]) ? color.red : color.maroon) scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray
plot(val, color=bcolor, style=plot.style_histogram, linewidth=4) plot(0, color=scolor, style=plot.style_cross, linewidth=2)
// --- Alerts --- stochBuySignal = crossUp stochSellSignal = crossDn squeezeSignal = sqzOn ? 1 : sqzOff ? -1 : 0
// Check for coinciding signals buyCondition = stochBuySignal and (squeezeSignal == 1) // Stochastic bullish cross & squeeze on sellCondition = stochSellSignal and (squeezeSignal == -1) // Stochastic bearish cross & squeeze off
// Alert conditions alertcondition(buyCondition, title="Buy Alert", message="Buy Signal: Stochastic Cross Up + Squeeze On!") alertcondition(sellCondition, title="Sell Alert", message="Sell Signal: Stochastic Cross Down + Squeeze Off!")
// Optional plot for visual verification plotshape(buyCondition, style=shape.labelup, location=location.belowbar, color=color.green, size=size.small, title="Buy Alert Signal", text="BUY") plotshape(sellCondition, style=shape.labeldown, location=location.abovebar, color=color.red, size=size.small, title="Sell Alert Signal", text="SELL")
- Assistant
Para incluir las alertas solicitadas en tu script, vamos a ajustar las condiciones de las alertas para que comprueben si los tres indicadores coinciden y si el Stochastic está en las zonas de sobrecompra o sobreventa, así como el cruce de las medias móviles ponderadas (WMA) y el rebote de las velas respecto a la media móvil de 60.
A continuación, he modificado el código para que refleje estos requisitos:
//@version=5 indicator("Combined Indicators with Alerts", overlay=true) // --- CM_Stochastic_MTF --- len = input(14, minval=1, title="Length for Main Stochastic") smoothK = input(3, minval=1, title="SmoothK for Main Stochastic") smoothD = input(3, minval=1, title="SmoothD for Main Stochastic") upLine = input(90, minval=50, maxval=90, title="Upper Line Value?") // Cambiado a 90 lowLine = input(10, minval=10, maxval=50, title="Lower Line Value?") // Cambiado a 10 sml = input(true, title="Show Mid Line?") sbh = input(false, title="Show Back Ground Highlights When Stoch is Above/Below High/Low Lines?") sch = input(true, title="Show Back Ground Highlights When Stoch Cross - Strict Criteria - K Greater/LesThan High/Low Line - Crosses D?") sl = input(true, title="Show 'B' and 'S' Letters When Stoch Crosses High/Low Line & D?") sac = input(false, title="Show Back Ground Highlights When Stoch Cross - Any Cross?") sacl = input(false, title="Show 'B' and 'S' Letters When Stoch Crosses - Any Cross?") useCurrentRes = input(true, title="Use Current Chart Resolution?") resCustom = input.timeframe("60", title="Use Different Timeframe? Uncheck Box Above") ssStoch = input(false, title="Show 2nd Stoch?") resCustom2 = input.timeframe("D", title="Use 2nd Stoch? Check Box Above") len2 = input(14, minval=1, title="2nd Stoch Length") smoothK2 = input(3, minval=1, title="SmoothK for 2nd Stoch") smoothD2 = input(3, minval=1, title="SmoothD for 2nd Stoch") // Resolution for MTF res = useCurrentRes ? timeframe.period : resCustom k = ta.sma(ta.stoch(close, high, low, len), smoothK) d = ta.sma(k, smoothD) outK = request.security(syminfo.tickerid, res, k) outD = request.security(syminfo.tickerid, res, d) k2 = ta.sma(ta.stoch(close, high, low, len2), smoothK2) d2 = ta.sma(k2, smoothD2) outK2 = request.security(syminfo.tickerid, resCustom2, k2) outD2 = request.security(syminfo.tickerid, resCustom2, d2) // Definitions for Cross crossUp = (outK[1] < outD[1]) and (outK > outD and outK > upLine) crossDn = (outK[1] > outD[1]) and (outK < outD and outK < lowLine) // Plot main Stochastic plot(outK, title="Stoch K", color=color.lime, linewidth=3) plot(outD, title="Stoch D", color=color.red, linewidth=3) // --- WMAMulti --- tf1 = input("15", title="time frame 1") tf2 = input("30", title="time frame 2") tf3 = input("60", title="time frame 3") length = input(20, title="length") ma1 = request.security(syminfo.tickerid, tf1, ta.wma(hl2, length)) ma2 = request.security(syminfo.tickerid, tf2, ta.wma(hl2, length)) ma3 = request.security(syminfo.tickerid, tf3, ta.wma(hl2, length)) getcolor(avg, tf) => prev = request.security(syminfo.tickerid, tf, ta.wma(hl2, length)[1]) avg >= prev ? color.green : color.red // Plot WMA plot(ma1, color=getcolor(ma1, tf1), linewidth=3) plot(ma2, color=getcolor(ma2, tf2), linewidth=3) plot(ma3, color=getcolor(ma3, tf3), linewidth=3) // Cruces WMA crossWMA_UP = ta.crossover(ma1, ma2) // MA de 15 cruza por encima de MA de 30 crossWMA_DOWN = ta.crossover(ma2, ma1) // MA de 30 cruza por encima de MA de 15 // --- SQZMOM_LB --- lengthSQZ = 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=input.bool) // Calculate BB source = close basis = ta.sma(source, lengthSQZ) dev = multKC * ta.stdev(source, lengthSQZ) 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 = not sqzOn and not sqzOff val = ta.linreg(source - math.avg(math.highest(high, lengthKC), math.lowest(low, lengthKC)), lengthKC, 0) bcolor = val > 0 ? (val > nz(val[1]) ? color.lime : color.green) : (val < nz(val[1]) ? color.red : color.maroon) scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray plot(val, color=bcolor, style=plot.style_histogram, linewidth=4) plot(0, color=scolor, style=plot.style_cross, linewidth=2) // --- Alerts --- // Alert conditions buyCondition = crossUp and sqzOn and crossWMA_UP and close > ma3 // Cruza hacia arriba, squeeze on, cruza WMA y precio por encima de la MA de 60 sellCondition = crossDn and sqzOff and crossWMA_DOWN and close < ma3 // Cruza hacia abajo, squeeze off, cruza WMA y precio por debajo de la MA de 60 // Alert conditions alertcondition(buyCondition, title="Buy Alert", message="Buy Signal: Stochastic Cross Up in Overbought Zone + Squeeze On + WMA Cross Up + Price Above WMA!") alertcondition(sellCondition, title="Sell Alert", message="Sell Signal: Stochastic Cross Down in Oversold Zone + Squeeze Off + WMA Cross Down + Price Below WMA!") // Optional plot for visual verification plotshape(buyCondition, style=shape.labelup, location=location.belowbar, color=color.green, size=size.small, title="Buy Alert Signal", text="BUY") plotshape(sellCondition, style=shape.labeldown, location=location.abovebar, color=color.red, size=size.small, title="Sell Alert Signal", text="SELL")Cambios Realizados:
- Zonas de Sobrecompra y Sobreventa: Modifiqué la lógica para que el
Stochasticgenere alertas solo en zonas de sobrecompra (dondeoutK > 90) o sobreventa (outK < 10). - Condiciones de Cruce del WMA: Definí condiciones para que las medias móviles (MAs) de 15 y 30 se crucen hacia arriba o hacia abajo.
- Condiciones de Precio: Se añade la condición que verifica que el precio cierre por encima o por debajo de la media móvil de 60.
- Alertas: Las condiciones de alerta ahora comprueban que todos los indicadores coincidan según las condiciones que definiste.
Guarda y aplica este script en tu gráfico de TradingView. Deberías recibir alertas cuando todas las condiciones coincidan. Si necesitas más ajustes, ¡házmelo saber!
- Zonas de Sobrecompra y Sobreventa: Modifiqué la lógica para que el