Estrategia de negociación combinada basada en 123 Reversión y MACD

El autor:¿ Qué pasa?, Fecha: 2023-09-19 17:17:30
Las etiquetas:

Resumen general

Esta estrategia combina 123 patrones de reversión e indicadores MACD para generar señales comerciales más fuertes a través del filtrado.

Estrategia lógica

  1. 123 estrategia de reversión compra cuando los dos últimos días fueron días bajos y el cierre de hoy es superior, con el Estocástico por debajo del umbral; vende cuando los dos últimos días fueron días altos y hoy es inferior, con el Estocástico por encima del umbral.

  2. La estrategia MACD es larga cuando el MA rápido está por encima del MA lento, y corta cuando el MA rápido está por debajo del MA lento.

  3. Las operaciones se realizan solo cuando ambas estrategias están de acuerdo, de lo contrario no se toma ninguna acción.

Análisis de ventajas

Las principales ventajas:

  1. La señal combinada filtra eficazmente las falsas fugas, mejorando la tasa de ganancias.

  2. 123 captura las reversiones a corto plazo, el MACD juzga la dirección de la tendencia a mediano y largo plazo.

  3. El estocástico con 123 evita el exceso de negociación después de la inversión de tendencia.

  4. Dos estrategias comparten tareas diferentes, validándose mutuamente, evitando la sobre-optimización.

  5. Cambiar fácilmente entre largo y corto, adaptable a diversos entornos de mercado.

Análisis de riesgos

Principales riesgos:

  1. La señal combinada puede ser demasiado conservadora, perdiendo buenas oportunidades.

  2. Los reveses son susceptibles a eventos repentinos, propensos al fracaso.

  3. La falta de stop loss expone a la estrategia a grandes pérdidas.

  4. El doble filtrado puede causar la falta de operaciones de tendencia.

  5. Falta de optimización de parámetros, los valores predeterminados pueden no ajustarse a todos los instrumentos.

Direcciones de optimización

Mejoras:

  1. Prueba diferentes combinaciones de parámetros para encontrar valores óptimos.

  2. Se añadirá el stop loss a la pérdida de control por operación.

  3. Incorporar más indicadores de filtro para mejorar la calidad de la señal.

  4. Introducir modelos de aprendizaje automático para la optimización automática de parámetros.

  5. Prueba en más instrumentos de negociación para evaluar la solidez.

  6. Conjuntos de parámetros basados en las condiciones del mercado.

Resumen de las actividades

En general, la combinación de señales duales evita la sobre-optimización en comparación con las estrategias individuales.


/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-14 02:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 24/07/2020
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This System was created from the Book "How I Tripled My Money In The 
// Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
// The strategy buys at market, if close price is higher than the previous close 
// during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50. 
// The strategy sells at market, if close price is lower than the previous close price 
// during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
//
// Second strategy
// This is one of the techniques described by William Blau in his book
// "Momentum, Direction and Divergence" (1995). If you like to learn more,
// we advise you to read this book. His book focuses on three key aspects
// of trading: momentum, direction and divergence. Blau, who was an electrical
// engineer before becoming a trader, thoroughly examines the relationship 
// between price and momentum in step-by-step examples. From this grounding,
// he then looks at the deficiencies in other oscillators and introduces some
// innovative techniques, including a fresh twist on Stochastics. On directional 
// issues, he analyzes the intricacies of ADX and offers a unique approach to help 
// define trending and non-trending periods.
// Blau`s indicator is like usual MACD, but it plots opposite of meaningof
// stndard MACD indicator.  
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
Reversal123(Length, KSmoothing, DLength, Level) =>
    vFast = sma(stoch(close, high, low, Length), KSmoothing) 
    vSlow = sma(vFast, DLength)
    pos = 0.0
    pos := iff(close[2] < close[1] and close > close[1] and vFast < vSlow and vFast > Level, 1,
	         iff(close[2] > close[1] and close < close[1] and vFast > vSlow and vFast < Level, -1, nz(pos[1], 0))) 
	pos

fADX(Len) =>
    up = change(high)
    down = -change(low)
    trur = rma(tr, Len)
    plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, Len) / trur)
    minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, Len) / trur)
    sum = plus + minus 
    100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), Len)

EMACD(r,SmthLen,LengthMACD) =>
    pos = 0
    source = close
    fastMA = ema(source, r)
    slowMA = ema(source, LengthMACD)
    xmacd = fastMA - slowMA
    xMA_MACD = ema(xmacd, SmthLen)
    pos := iff(xmacd < xMA_MACD, -1,
    	     iff(xmacd > xMA_MACD, 1, nz(pos[1], 0))) 
    pos

strategy(title="Combo Backtest 123 Reversal & Ergodic MACD", shorttitle="Combo", overlay = true)
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
r = input(14, minval=1)
LengthMACD = input(21, minval=1)
SmthLen = input(5, minval=1)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posEMACD = EMACD(r,SmthLen,LengthMACD)
pos = iff(posReversal123 == 1 and posEMACD == 1 , 1,
	   iff(posReversal123 == -1 and posEMACD == -1, -1, 0)) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1 , 1, pos))	   
if (possig == 1) 
    strategy.entry("Long", strategy.long)
if (possig == -1)
    strategy.entry("Short", strategy.short)	 
if (possig == 0) 
    strategy.close_all()
barcolor(possig == -1 ? #b50404: possig == 1 ? #079605 : #0536b3 )

Más.