
Esta estrategia es una estrategia de seguimiento de tendencias basada en una línea de medias móviles que se adapta a sí misma. Utiliza una línea de medias móviles DEMA de dos períodos diferentes para generar señales de compra y venta. La estrategia se adapta automáticamente a la granulación de análisis de acuerdo con diferentes períodos, lo que permite un seguimiento de varios marcos de tiempo.
Estrategia de construcción de señales de transacción usando la línea rápida DEMA y la línea lenta DEMA. La línea rápida tiene un período de tiempo de tf y la línea lenta de tf*2 ❚ Cuando la línea rápida atraviesa la línea lenta, se genera una señal de compra; cuando la línea rápida atraviesa la línea lenta, se genera una señal de venta. Así se puede seguir la tendencia de la línea media y larga. Además, la estrategia también utiliza un filtro de doble línea uniforme móvil de Hull para reducir el ruido de las transacciones.
La mayor ventaja de esta estrategia es que se puede adaptar a diferentes períodos. Se puede utilizar desde la línea de sol hasta la línea de circunferencia. Se puede utilizar desde la línea de sol hasta la línea de circunferencia.
El principal riesgo de esta estrategia proviene de la reversión de la tendencia. Cuando el mercado pasa de un mercado alcista a un mercado bajista, la línea rápida y la línea lenta pueden cruzarse fuertemente hacia abajo, lo que provoca grandes pérdidas. Además, los filtros de doble línea también pueden eliminar algunas oportunidades de ganar dinero.
Se puede optimizar la estrategia ajustando los parámetros de filtro o utilizando otros indicadores de sustitución. Por ejemplo, se puede probar el MACD en lugar del HullMA, o ajustar los parámetros de ciclo del HullMA. También se puede probar diferentes combinaciones de parámetros para encontrar reglas de negociación más compatibles. Además, se puede combinar con el indicador de fluctuación para controlar el tamaño de la posición.
La estrategia en su conjunto es una estrategia de seguimiento de tendencias de adaptación muy práctica. Se puede ajustar automáticamente el ciclo de análisis para adaptarse a las operaciones de diferentes períodos de tiempo. La estructura de doble línea uniforme permite un seguimiento estable de la tendencia, y el filtro también mejora la calidad de la señal. En general, es adecuado para los inversores que buscan ganancias estables en la línea media-larga.
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-24 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
//
//---------------------------------------------
//* Author - PPSingnal
//* http://ppsignal.com
//---------------------------------------------
//
//
strategy (title="PPSignal V4 (Auto Adaptive Times)", shorttitle="PPSignal V4", overlay=true)
delayOffset = input(defval = 0, title = "Delay Open/Close MA (Forces Non-Repainting)", minval = 0, step = 1)
//---------------------------------------- INICIO PPI ----------------------------------------
// - PARÁMETROS DE ENTRADA
// SE DEFINE LA RESOLUCIÓN
useRes1 = true
setRes1 = true
tf = timeframe.period == "60" ? 4 : timeframe.period == "240" ? 4 : timeframe.period == "D" ? 4 : timeframe.period == "W" ?4 : 4
// PRIMER DEMA
type = "DEMA"
src = close
len = tf
off = 0
lsma = 0
// SEGUNDA DEMA
type2 = "DEMA"
src2 = open
len2 = tf
off2 = 0
lsma2 = 0
// - INPUTS END
//---------------------------------------- INICIO FUNCIONES ----------------------------------------
// RETORNA UNA MEDIA MOVIL (TYPE=TIPO / SRC = TIPO DE PRECIO / LEN=LONGITUD / LSMA=0)
variant(type, src, len, lsma) =>
v1 = sma(src, len) // Simple
v2 = ema(src, len) // Exponential
v3 = wma(src, len) // Weighted
v4 = vwma(src, len) // Volume Weighted
v5 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len // Smoothed
v6 = 2 * v2 - ema(v2, len) // Double Exponential
v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) // Hull
v9 = linreg(src, len, lsma) // Least Squares
// return variant, defaults to SMA if input invalid.
type=="EMA"?v2 : type=="WMA"?v3 : type=="VWMA"?v4 : type=="SMMA"?v5 : type=="DEMA"?v6 : type=="TEMA"?v7 : type=="HullMA"?v8 : type=="LSMA"?v9 : v1
// SuperSmoother filter
// © 2013 John F. Ehlers
a1 = exp(-1.414*3.14159 / len)
b1 = 2*a1*cos(1.414*3.14159 / len)
c2 = b1
c3 = (-a1)*a1
c1 = 1 - c2 - c3
v12 = 0.0
v12 := c1*(src + nz(src[1])) / 2 + c2*nz(v12[1]) + c3*nz(v12[2])
// RETORNA LA RESOLUCIÓN SETEADA Y SINO LA DEFAULT
// 3H: 1min - 3min - 5min - 15min
// DIARIO: 30 - 45 - 60
// SEMANAL: 120 - 180 - 240 - D
reso(exp, use, res) => use ? request.security(syminfo.tickerid, timeframe.period=="1" ? "D" : timeframe.period=="3" ? "D" : timeframe.period=="5" ? "D" : timeframe.period=="15" ? "D" : timeframe.period=="30" ? "D" : timeframe.period=="45" ? "W" : timeframe.period=="60" ? "W" : timeframe.period=="120" ? "W" : timeframe.period=="180" ? "W" : timeframe.period=="240" ? "W" : timeframe.period=="D" ? "W" : "W", exp) : exp
//---------------------------------------- FIN FUNCIONES ----------------------------------------
//---------------------------------------- INICIO VARIABLES ----------------------------------------
// DEMAS
ma_short = reso(variant(type, src[off], len, lsma), useRes1, setRes1)
ma_long = reso(variant(type2, src2[off2], len2, lsma2), useRes1, setRes1)
//---------------------------------------- FIN VARIABLES ----------------------------------------
//---------------------------------------- FIN PPI ----------------------------------------
//---------------------------------------- PRIMER FILTRO ----------------------------------------
// Double HullMA
scolor = false
n=1
n2ma=2*wma(close,round(n/2))
nma=wma(close,n)
diff=n2ma-nma
sqn=round(sqrt(n))
n2ma1=2*wma(close[1],round(n/2))
nma1=wma(close[1],n)
diff1=n2ma1-nma1
sqn1=round(sqrt(n))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
//---------------------------------------- FIN PRIMER FILTRO ----------------------------------------
//---------------------------------------- INICIO CONDICIONES ----------------------------------------
// CONDICION CON FILTRO
cruce= (ma_short > ma_long) and n1>n2 ? true : ma_short < ma_long ? false : cruce[1]
// Condition
// FONDO DE COLOR
bground = cruce ? white : red
bgcolor(bground, transp=90)
// BARRAS COLOREADAS
barcol = cruce ? yellow : red
barcolor(barcol, transp=0)
closePlot = plot(ma_short, title = "Zone 1", color = gray, circles = 0, style = circles, transp = 100)
openPlot = plot(ma_long, title = "Zone 2", color = green, circles = 0, style = circles, transp = 100)
trendState = ma_short > ma_long ? true : ma_short < ma_long ? false : trendState[1]
// channel fill
closePlotU = plot(trendState ? ma_short : na, transp = 100, editable = false)
openPlotU = plot(trendState ? ma_long : na, transp = 100, editable = false)
closePlotD = plot(trendState ? na : ma_short, transp = 100, editable = false)
openPlotD = plot(trendState ? na : ma_long, transp = 100, editable = false)
fill(openPlotU, closePlotU, title = "Up Trend Fill", color = yellow, transp = 70)
fill(openPlotD, closePlotD, title = "Down Trend Fill", color = red, transp = 70)
//---------------------------------------- FIN CONDICIONES ----------------------------------------
//---------------------------------------- INICIO ESTRATEGIA ----------------------------------------
//CONDICION COMPRA
longCond = (ma_short > ma_long) and n1>=n2
//CONDICION VENTA
shortCond = (ma_short < ma_long)
//ABRO COMPRA A
strategy.entry("Bull Trend", strategy.long, when = longCond)
//ABRO VENTA A
strategy.entry("Bearish Trend", strategy.short, when = shortCond)
//CIERRO VENTA A
strategy.exit("Exit Short", from_entry = "Bull Trend", when = shortCond)
//CIERRO COMPRA A
strategy.exit("Exit Long", from_entry = "Bearish Trend", when = longCond)
//---------------------------------------- FIN ESTRATEGIA ----------------------------------------