Esta estrategia es un sistema de trading adaptativo que integra múltiples indicadores de análisis técnico y cambia entre diferentes estrategias de trading identificando dinámicamente las condiciones del mercado. El sistema se basa principalmente en tres indicadores técnicos: media móvil (MA), bandas de Bollinger (BB) e índice de fuerza relativa (RSI), y selecciona automáticamente el método de negociación más adecuado según las tendencias del mercado y las fluctuaciones del rango. La estrategia adopta soluciones de gestión de riesgos diferenciadas para mercados de tendencia y rango estableciendo diferentes parámetros de toma de ganancias y de stop loss.
La estrategia utiliza los promedios móviles de 50 y 20 períodos para determinar las tendencias del mercado y combina los indicadores Bandas de Bollinger y RSI para identificar áreas de sobrecompra y sobreventa. En un mercado de tendencia, el sistema opera principalmente en función de la relación entre el precio y el promedio móvil lento y el cruce de las líneas rápida y lenta; en un mercado de rango, opera principalmente en función de las rupturas de los límites de la banda de Bollinger y las señales de sobrecompra y sobreventa del RSI. . El sistema ajusta automáticamente el nivel de toma de ganancias según el entorno del mercado. Se utiliza una toma de ganancias del 6 % para mercados con tendencia y una toma de ganancias del 4 % para mercados con rango. Se utiliza un stop loss del 2 % de manera uniforme para controlar riesgos.
Esta estrategia integra múltiples indicadores técnicos clásicos para construir un sistema de trading adaptativo que pueda adaptarse a diferentes entornos de mercado. Si bien mantiene una operación simple, el sistema realiza una identificación dinámica del estado del mercado y el cambio automático de estrategias comerciales, y es altamente práctico. A través de configuraciones diferenciadas de take-profit y stop-loss, la estrategia mantiene una buena rentabilidad al tiempo que controla los riesgos. En el futuro, la estabilidad y confiabilidad de la estrategia se pueden mejorar aún más introduciendo más indicadores técnicos y optimizando los mecanismos de ajuste de parámetros.
/*backtest
start: 2024-01-17 00:00:00
end: 2025-01-16 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=6
strategy("Supply & Demand Test 1 - Enhanced", overlay=true)
// Inputs
ma_length = input.int(50, title="50-period Moving Average Length", minval=1)
ma_length_fast = input.int(20, title="20-period Moving Average Length", minval=1)
bb_length = input.int(20, title="Bollinger Bands Length", minval=1)
bb_std_dev = input.float(2.0, title="Bollinger Bands Std Dev", step=0.1)
rsi_length = input.int(14, title="RSI Length", minval=1)
stop_loss_percent = input.float(0.02, title="Stop Loss Percent", step=0.001, minval=0.001)
take_profit_trend = input.float(0.06, title="Take Profit Percent (Trend)", step=0.001, minval=0.001)
take_profit_range = input.float(0.04, title="Take Profit Percent (Range)", step=0.001, minval=0.001)
// Moving Averages
ma_slow = ta.sma(close, ma_length)
ma_fast = ta.sma(close, ma_length_fast)
// Bollinger Bands
bb_basis = ta.sma(close, bb_length)
bb_dev = ta.stdev(close, bb_length)
bb_upper = bb_basis + bb_std_dev * bb_dev
bb_lower = bb_basis - bb_std_dev * bb_dev
// RSI
rsi = ta.rsi(close, rsi_length)
// Market Conditions
is_trending_up = close > ma_slow
is_trending_down = close < ma_slow
is_range_bound = not (is_trending_up or is_trending_down)
// Entry Conditions
long_trend_entry = is_trending_up and close >= ma_slow * 1.02
short_trend_entry = is_trending_down and close <= ma_slow * 0.98
long_ma_crossover = ta.crossover(ma_fast, ma_slow)
short_ma_crossover = ta.crossunder(ma_fast, ma_slow)
long_range_entry = is_range_bound and close <= bb_lower * 0.97
short_range_entry = is_range_bound and close >= bb_upper * 1.03
long_rsi_entry = is_range_bound and rsi < 30
short_rsi_entry = is_range_bound and rsi > 70
// Entry and Exit Logic
if long_trend_entry
strategy.entry("Long Trend", strategy.long)
strategy.exit("Exit Long Trend", from_entry="Long Trend", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_trend))
alert("Entered Long Trend", alert.freq_once_per_bar)
if short_trend_entry
strategy.entry("Short Trend", strategy.short)
strategy.exit("Exit Short Trend", from_entry="Short Trend", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_trend))
alert("Entered Short Trend", alert.freq_once_per_bar)
if long_ma_crossover
strategy.entry("Long MA Crossover", strategy.long)
strategy.exit("Exit Long MA Crossover", from_entry="Long MA Crossover", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_trend))
alert("Entered Long MA Crossover", alert.freq_once_per_bar)
if short_ma_crossover
strategy.entry("Short MA Crossover", strategy.short)
strategy.exit("Exit Short MA Crossover", from_entry="Short MA Crossover", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_trend))
alert("Entered Short MA Crossover", alert.freq_once_per_bar)
if long_range_entry
strategy.entry("Long Range", strategy.long)
strategy.exit("Exit Long Range", from_entry="Long Range", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_range))
alert("Entered Long Range", alert.freq_once_per_bar)
if short_range_entry
strategy.entry("Short Range", strategy.short)
strategy.exit("Exit Short Range", from_entry="Short Range", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_range))
alert("Entered Short Range", alert.freq_once_per_bar)
if long_rsi_entry
strategy.entry("Long RSI", strategy.long)
strategy.exit("Exit Long RSI", from_entry="Long RSI", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_range))
alert("Entered Long RSI", alert.freq_once_per_bar)
if short_rsi_entry
strategy.entry("Short RSI", strategy.short)
strategy.exit("Exit Short RSI", from_entry="Short RSI", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_range))
alert("Entered Short RSI", alert.freq_once_per_bar)
// Plotting
plot(ma_slow, color=color.blue, title="50-period MA")
plot(ma_fast, color=color.orange, title="20-period MA")
plot(bb_upper, color=color.red, title="Bollinger Upper")
plot(bb_lower, color=color.green, title="Bollinger Lower")
plot(bb_basis, color=color.gray, title="Bollinger Basis")
hline(70, "Overbought (RSI)", color=color.red, linestyle=hline.style_dotted)
hline(30, "Oversold (RSI)", color=color.green, linestyle=hline.style_dotted)