
Esta es una estrategia de trading automática basada en indicadores de doble tecnología RSI y MACD. La estrategia identifica oportunidades de trading potenciales y logra una captura precisa del mercado mediante la combinación de señales de sobreventa y sobreventa con la confirmación de tendencias. La estrategia utiliza gestión de posición porcentual y un mecanismo de prevención de puntos de deslizamiento incorporado, con una gran practicidad y adaptabilidad.
La lógica central de la estrategia se basa en los siguientes elementos clave:
La estrategia construye un sistema de negociación relativamente sólido a través de la sinergia entre el RSI y el MACD. Aunque existe un cierto riesgo de atraso, la estrategia sigue teniendo un buen valor práctico a través de un control razonable del riesgo y la optimización de los parámetros. Se recomienda realizar un buen retroceso antes de la aplicación en el mercado real y realizar una optimización específica según las características específicas del mercado.
//@version=6
strategy("Debugging Demo GPT",
overlay=true,
initial_capital=100,
default_qty_type=strategy.percent_of_equity,
default_qty_value=3,
pyramiding=1,
calc_on_order_fills=true,
calc_on_every_tick=true,
slippage=3)
// -----------------------------------------------------------------------
// (1) Inputs: Start and End Date
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// (2) Indicators (RSI, MACD)
// -----------------------------------------------------------------------
// === RSI ===
rsiLen = input.int(14, "RSI Length")
rsiOB = input.int(80, "RSI Overbought")
rsiOS = input.int(20, "RSI Oversold")
rsiVal = ta.rsi(close, rsiLen)
// === MACD ===
fastLen = input.int(12, "MACD Fast Length")
slowLen = input.int(26, "MACD Slow Length")
sigLen = input.int(9, "MACD Signal Length")
[macdLine, sigLine, histLine] = ta.macd(close, fastLen, slowLen, sigLen)
// -----------------------------------------------------------------------
// (3) Trading Logic: LONG/SHORT Filters
// -----------------------------------------------------------------------
bool rsiLongOk = (rsiVal < rsiOB)
bool rsiShortOk = (rsiVal > rsiOS)
bool macdLongOk = (macdLine > sigLine)
bool macdShortOk = (macdLine < sigLine)
bool longCondition = rsiLongOk and macdLongOk
bool shortCondition = rsiShortOk and macdShortOk
// -----------------------------------------------------------------------
// (4) Entry Conditions
// -----------------------------------------------------------------------
// Debugging: Visualizing the conditions
plotshape(series=longCondition, location=location.belowbar, color=color.blue, style=shape.circle, title="LongCondition", size=size.tiny)
plotshape(series=shortCondition, location=location.abovebar, color=color.orange, style=shape.circle, title="ShortCondition", size=size.tiny)
// Entries only when all conditions are met
if longCondition
strategy.entry("Long", strategy.long)
if shortCondition
strategy.entry("Short", strategy.short)
// -----------------------------------------------------------------------
// (5) Plotting for Visualization
// -----------------------------------------------------------------------
// RSI Plots
hline(rsiOB, "RSI Overbought", color=color.red, linestyle=hline.style_dotted)
hline(rsiOS, "RSI Oversold", color=color.green, linestyle=hline.style_dotted)
plot(rsiVal, title="RSI", color=color.purple)
// MACD Plots
plot(macdLine, color=color.teal, title="MACD Line")
plot(sigLine, color=color.orange, title="MACD Signal")
plot(histLine, style=plot.style_histogram, color=(histLine >= 0 ? color.lime : color.red), title="MACD Histogram")