Estrategia Triple SuperTrend y Stoch RSI


Fecha de creación: 2023-12-06 14:29:00 Última modificación: 2023-12-06 14:29:00
Copiar: 1 Número de Visitas: 1377
1
Seguir
1619
Seguidores

Estrategia Triple SuperTrend y Stoch RSI

Descripción general

La estrategia Triple SuperTrend y Stoch RSI es una estrategia de comercio cuantitativa que combina el seguimiento de tendencias de varios marcos temporales y el sobreventa de indicadores de venta por adelantado. La estrategia utiliza el indicador SuperTrend con tres diferentes parámetros para determinar la tendencia del mercado y en combinación con la señal de venta por adelantado del indicador Stoch RSI para emitir una señal de comercio.

Principio de estrategia

La lógica central de la triple estrategia de SuperTrend y Stoch RSI es la combinación de diferentes parámetros de los indicadores de SuperTrend y Stoch RSI para filtrar las señales de negociación para mejorar la calidad de la señal y reducir la tasa de señales erróneas.

En primer lugar, la estrategia utiliza tres grupos de indicadores de SuperTrend con diferentes parámetros para determinar las principales tendencias del mercado. Estos tres grupos de indicadores de SuperTrend tienen diferentes configuraciones de parámetros, con marcos de tiempo que van de rápido a lento, para capturar los cambios de tendencia en diferentes niveles. Cuando el indicador de SuperTrend más rápido y el segundo más rápido emiten al mismo tiempo una señal de compra/venta, se determina previamente que la señal tiene cierta fiabilidad.

En segundo lugar, la estrategia introduce el indicador Stoch RSI para determinar si la señal es excesivamente sobrecomprada o sobrevendida. El indicador Stoch RSI combina las ventajas del indicador RSI al azar y el indicador Stochastic al azar para determinar eficazmente si el mercado está sobrecomprado o sobrevendido. Podemos emitir una señal de compra/venta final si la señal de SuperTrend más rápida y la más rápida coinciden con la señal del indicador Stoch RSI.

A través de la combinación de múltiples indicadores y múltiples marcos de tiempo, la triple estrategia SuperTrend y Stoch RSI puede filtrar eficazmente el ruido del mercado, mejorar la fiabilidad de las señales y reducir la incidencia de operaciones erróneas.

Ventajas estratégicas

La mayor ventaja de la triple estrategia de SuperTrend y Stoch RSI es la combinación efectiva de múltiples indicadores y múltiples marcos de tiempo, lo que nos brinda los siguientes beneficios:

  1. La combinación de los indicadores Triple SuperTrend y el indicador Stoch RSI puede reducir considerablemente la señal de ruido y la señal errónea que existe en un solo indicador.

  2. Aumentar la proporción de señales ganadoras. Aunque la frecuencia de la señal se reduce, la proporción de señales ganadoras aumenta significativamente.

  3. Adecuado para mercados de tendencia. Las ondas de los marcos temporales múltiples son útiles para capturar tendencias de línea media y larga, y son adecuadas para entornos de mercado en los que las tendencias son más evidentes.

  4. El triple indicador ofrece un mayor espacio de posibilidades para la optimización de parámetros.

  5. Se pueden ajustar los parámetros según el estilo personal. Se puede ajustar libremente los parámetros para que la estrategia se adapte mejor a su propio estilo de negociación.

Riesgo estratégico

Las estrategias Triple SuperTrend y Stoch RSI también presentan ciertos riesgos, que se centran principalmente en los siguientes aspectos:

  1. Reducción de la frecuencia de las señales. El mecanismo de filtración de capas permite una reducción significativa de la frecuencia de las operaciones en las estrategias.

  2. Es fácil perderse parte de las señales. La conservaduría de la estrategia hace que sea fácil perderse parte de las oportunidades potenciales.

  3. Aumentar el número de indicadores aumenta la dependencia de los parámetros. Cuantos más indicadores y parámetros hay, más difícil es optimizar la estrategia.

  4. La combinación de múltiples marcos de tiempo también limita la flexibilidad de la estrategia para seguir las tendencias.

Para los riesgos mencionados anteriormente, podemos optimizar la estrategia para obtener una mayor calidad de ganancias al controlar el riesgo mediante la adaptación de los parámetros de los indicadores, la introducción de más indicadores auxiliares de juicio, etc.

Dirección de optimización de la estrategia

Las estrategias Triple SuperTrend y Stoch RSI aún tienen espacio para una mayor optimización, principalmente en los siguientes aspectos:

  1. Ajuste la combinación de parámetros indicadores para encontrar la mejor combinación de parámetros. Se puede introducir más pruebas de parámetros indicadores para encontrar el parámetro óptimo.

  2. Aumentar las estrategias de stop loss y control del riesgo de una sola transacción. Esto puede aumentar considerablemente la estabilidad de la estrategia.

  3. Introducir más indicadores de juicio para la verificación de señales. Por ejemplo, la introducción de indicadores de volumen de transacciones para juzgar desde múltiples ángulos.

  4. La adición de la función de adaptación permite que las estrategias se optimicen automáticamente y ajusten los parámetros para adaptarse a los cambios en el mercado.

  5. El uso de algoritmos de IA para predecir la precisión de las señales indicadoras.

Con una optimización continua, la triple estrategia de SuperTrend y Stoch RSI puede convertirse en una estrategia de comercio cuantitativa estable y eficiente, que nos brinda un Alpha considerable.

Resumir

La estrategia Triple SuperTrend y Stoch RSI combinan con éxito el análisis de múltiples marcos de tiempo con el juicio de sobreventa y sobreventa, formando una estrategia de comercio de tipo seguimiento de tendencia única. Al mismo tiempo, conserva la doble ventaja de seguir la tendencia y filtrar los indicadores, aumentando la proporción de señales de ganancias al tiempo que reduce las señales de ruido. Aunque el riesgo de la estrategia y el espacio para la optimización siguen existiendo, su rentabilidad y estabilidad pueden ser mejoradas aún más mediante la adaptación de los parámetros y la optimización de la estrategia.

Código Fuente de la Estrategia
/*backtest
start: 2022-11-29 00:00:00
end: 2023-04-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © M3RZI

//@version=4
strategy("3x Supertrend and Stoch RSI", overlay = true, max_bars_back = 1000)

//INPUTS
STATRLENGTH1 = input(10, title = "Fast Supertrend ATR Length", type = input.integer, group = "SUPERTREND SETTINGS")
STATRMULT1 = input(1, title = "Fast Supertrend ATR Multiplier", type = input.float, group = "SUPERTREND SETTINGS")
STATRLENGTH2 = input(11, title = "Medium Supertrend ATR Length", type = input.integer, group = "SUPERTREND SETTINGS")
STATRMULT2 = input(2, title = "Medium Supertrend ATR Multiplier", type = input.float, group = "SUPERTREND SETTINGS")
STATRLENGTH3 = input(12, title = "Slow Supertrend ATR Length", type = input.integer, group = "SUPERTREND SETTINGS")
STATRMULT3 = input(3, title = "Slow Supertrend ATR Multiplier", type = input.float, group = "SUPERTREND SETTINGS")

stochK = input(3, title = "K (Stochastic Fast)", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
stochD = input(3, title = "D (Signal Line)", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
rsiLength = input(14, title = "RSI Length", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
stochLength = input(14, title = "Stochastic Length", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
rsiSource = input(close, title = "RSI Source", type = input.source, group = "STOCHASTIC RSI SETTINGS")
stochRestrictions = input(false, title = "Restrict crosses to overbought/oversold territory", type = input.bool, group = "STOCHASTIC RSI SETTINGS")
overboughtLine = input(80, title = "Stochastic  RSI Upper Band", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
oversoldLine = input(20, title = "Stochastic RSI Lower Band", type = input.integer, group = "STOCHASTIC RSI SETTINGS")

EMALength  = input(200, title = "EMA Length", type = input.integer, group = "EMA SETTINGS")

SLStrategy = input("ATR Based", title = "Stop Loss Strategy", options = ["ATR Based"],type = input.string, group = "POSITION EXIT SETTINGS")
SLATRLength = input(14, title = "Stop Loss ATR Length", type = input.integer, group = "POSITION EXIT SETTINGS")
SLATRMult = input(2.7, title = "Stop Loss ATR Multiplier", type = input.float, group = "POSITION EXIT SETTINGS")
TPStrategy = input("ATR Based", title = "Take Profit Strategy", options = ["ATR Based"],type = input.string, group = "POSITION EXIT SETTINGS")
TPATRLength = input(14, title = "Take Profit ATR Length", type = input.integer, group = "POSITION EXIT SETTINGS")
TPATRMult = input(1.6, title = "Take Profit ATR Multiplier", type = input.float, group = "POSITION EXIT SETTINGS")

//SUPERTRENDS
[superTrend1,dir1] = supertrend(STATRMULT1,STATRLENGTH1)
[superTrend2,dir2] = supertrend(STATRMULT2,STATRLENGTH2)
[superTrend3,dir3] = supertrend(STATRMULT3,STATRLENGTH3)

directionST1 = dir1 == 1 and dir1[1] == 1 ? false : dir1 == -1 and dir1[1] == -1 ? true : na
directionST2 = dir2 == 1 and dir2[1] == 1 ? false : dir2 == -1 and dir2[1] == -1 ? true : na
directionST3 = dir3 == 1 and dir3[1] == 1 ? false : dir3 == -1 and dir3[1] == -1 ? true : na

//STOCH RSI
rsi = rsi(rsiSource, rsiLength)
k = sma(stoch(rsi, rsi, rsi, stochLength), stochK)
d = sma(k, stochD)

//EMA
ema = ema(close,EMALength)

//CONDITIONS LONG AND SHORT

var long = false
var longCondition = false
var short = false
var shortCondition = false
var drawing = false
var TP = 0.0
var SL = 0.0
var middle = 0.0
var initial = 0

stopSize = atr(SLATRLength) * SLATRMult
profitSize = atr(TPATRLength) * TPATRMult
longStop = close - stopSize
longProfit = close + profitSize
current = close
shortStop = close + stopSize
shortProfit = close - profitSize
barInitial = bar_index

if  stochRestrictions
    longCondition := close > ema and ((directionST1 == true and directionST2 == true)  or (directionST2 == true and directionST3 == true)) and crossover(k,d) and k < oversoldLine and not long and not drawing
    shortCondition := close < ema and ((directionST1 == false and directionST2 == false)  or (directionST2 == false and directionST3 == false)) and crossunder(k,d) and k > overboughtLine and not short and not drawing
else
    longCondition := close > ema and ((directionST1 == true and directionST2 == true)  or (directionST2 == true and directionST3 == true)) and crossover(k,d) and not long and not drawing
    shortCondition := close < ema and ((directionST1 == false and directionST2 == false)  or (directionST2 == false and directionST3 == false)) and crossunder(k,d) and not short and not drawing

if longCondition
    long := true
    short := false
    drawing := true
    TP := longProfit
    middle := current
    SL := longStop
    initial := barInitial
    strategy.entry("Long", strategy.long, 10)
    strategy.exit("Long exit","Long", limit = TP, stop = SL)
    alert("Long signal Supertrend \n Profit:"+tostring(TP)+"\Curret price:"+tostring(close)+"\Stop:"+tostring(SL),alert.freq_once_per_bar_close)
    //label.new(bar_index,low,text = "Long\nTP:"+tostring(TP)+"\nSL:"+tostring(SL)+"\nAbierto:"+tostring(current), yloc = yloc.belowbar, textcolor = color.white, color = color.green, size = size.small,  style = label.style_label_up)

if shortCondition
    short := true
    long := false
    drawing := true
    TP := shortProfit
    middle := current
    SL := shortStop
    initial := barInitial
    strategy.entry("Short", strategy.short, 10)
    strategy.exit("Short exit","Short",limit = TP , stop = SL)
    alert("Short signal Supertrend \n Profit:"+tostring(TP)+"\Curret price:"+tostring(close)+"\Stop:"+tostring(SL),alert.freq_once_per_bar_close)
    //label.new(bar_index,high,text = "Short\nTP:"+tostring(TP)+"\nSL:"+tostring(SL)+"\nAbierto:"+tostring(current), yloc = yloc.abovebar, textcolor = color.white, color = color.red, size = size.small,  style = label.style_label_down)

if long and (high[1] >= TP or low[1] <= SL)
    drawing := false
    long := false
    if high[1] >= TP
        label.new(bar_index[int((bar_index - initial)/2)],TP, text = "Win (Long)", textcolor = color.white, color = color.green, size = size.small, style = label.style_label_down)
    else
        label.new(bar_index[int((bar_index - initial)/2)],SL, text = "Lose (Long)", textcolor = color.white, color = color.red, size = size.small, style = label.style_label_up)

if short and (low[1] <= TP or high[1] >= SL)
    drawing :=  false
    short := false
    if low[1] <= TP
        label.new(bar_index[int((bar_index - initial)/2)],TP, text = "Win (short)", textcolor = color.white, color = color.green, size = size.small, style = label.style_label_up)
    else
        label.new(bar_index[int((bar_index - initial)/2)],SL, text = "Lose (short)", textcolor = color.white, color = color.red, size = size.small, style = label.style_label_down)

//STRATEGY
//strategy.entry("buy", strategy.long, 10, when = longCondition)
//strategy.exit("bracket", "buy",  10, limit = TP, stop = SL)
//strategy.entry("short", strategy.long, 10, when = shortCondition)
//strategy.exit("bracket", "short",  10, limit = TP, stop = SL)

//DRAWING
plotshape(longCondition, title = "Long Signal", location=location.belowbar, style=shape.labelup, color=color.green, textcolor=color.white, size=size.small, text="Long")
plotshape(shortCondition, title = "Short Signal", location=location.abovebar, style=shape.labeldown, color=color.red, textcolor=color.white, size=size.small, text="Short")
profitLine = plot(drawing and drawing[1] ? TP : na, title = "Take profit", color = color.green, style = plot.style_linebr)
currentLine =plot(drawing and drawing[1]  ? middle : na, title = "Middle Line", color = color.white, style = plot.style_linebr)
lossLine = plot(drawing and drawing[1]  ? SL : na, title = "Stop Loss", color = color.red, style = plot.style_linebr)
fill(currentLine,profitLine, title = "Profit Background" ,color = color.new(color.green,75))
fill(currentLine,lossLine, title = "Loss Background" ,color = color.new(color.red,75))
plot(superTrend1, title = "Fast Supertrend", color = dir1 == 1 and dir1[1] == 1 ? color.red : dir1 == -1 and dir1[1] == -1 ? color.green : na)
plot(superTrend2, title = "Medium Supertrend", color = dir2 == 1 and dir2[1] == 1 ? color.red : dir2 == -1 and dir2[1] == -1 ? color.green : na)
plot(superTrend3, title = "Slow Supertrend", color = dir3 == 1 and dir3[1] == 1 ? color.red : dir3 == -1 and dir3[1] == -1 ? color.green : na)
plot(ema, title = "EMA",color = color.yellow)
//plot(k, color = color.blue)
//plot(d, color = color.orange)
//h1 = hline(80)
//h2 = hline(20)
//fill(h1,h2, color = color.new(color.purple,60))