
La estrategia es un sistema de auto-adaptación que combina el seguimiento de tendencias y el intercambio de intervalos para juzgar el estado del mercado a través del índice de fluctuación (CI) y adoptar la lógica de negociación correspondiente en función de las diferentes condiciones del mercado. En el mercado de tendencias, la estrategia utiliza la señal de venta por encima de la compra por encima de la venta de EMA y RSI; en el mercado de intervalos, la estrategia se opera principalmente en función del máximo valor del indicador RSI.
El núcleo de la estrategia es dividir el mercado en un mercado de tendencia (CI <38.2) y un mercado intervalo (CI >61.8) a través del índice de fluctuación (CI). En un mercado de tendencia, se abren los polos cuando el EMA rápido (en el ciclo 9) atraviesa el EMA lento (en el ciclo 21) y el RSI está por debajo de 70. En un mercado intervalo, se abren los polos cuando el RSI está por debajo de 30 y por encima de 70.
La estrategia, mediante la combinación de varios indicadores técnicos, construye un sistema de negociación que se adapta a sí mismo y puede mantener un rendimiento estable en diferentes entornos de mercado. La ventaja central de la estrategia radica en su adaptabilidad al mercado y su mecanismo de gestión de riesgos, pero también debe tener en cuenta la optimización de los parámetros y la dependencia de las condiciones del mercado.
/*backtest
start: 2024-12-19 00:00:00
end: 2024-12-26 00:00:00
period: 45m
basePeriod: 45m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © nopology
//@version=6
strategy("CI, EMA, RSI", overlay=false)
// Input parameters
lengthCI = input(14, title="CI Length")
lengthRSI = input(14, title="RSI Length")
fastLength = input(9, title="Fast EMA Length")
slowLength = input(21, title="Slow EMA Length")
// Calculate CI
atr = ta.atr(lengthCI)
highLowRange = math.log10(math.max(high[lengthCI], high) - math.min(low[lengthCI], low))
sumATR = math.sum(atr, lengthCI)
ci = 100 * (math.log10(sumATR / highLowRange) / math.log10(lengthCI))
// Calculate RSI
rsi = ta.rsi(close, lengthRSI)
// Calculate EMAs
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
// Define conditions
trendingMarket = ci < 38.2
rangingMarket = ci > 61.8
bullishSignal = ta.crossover(fastEMA, slowEMA) and rsi < 70
bearishSignal = ta.crossover(slowEMA, fastEMA) and rsi > 30
// Plot indicators for visualization
plot(ci, title="Choppiness Index", color=color.purple, linewidth=2)
plot(fastEMA, title="Fast EMA", color=color.blue)
plot(slowEMA, title="Slow EMA", color=color.red)
// Strategy Execution
if (trendingMarket)
if (bullishSignal)
strategy.entry("Long", strategy.long)
if (bearishSignal)
strategy.entry("Short", strategy.short)
else if (rangingMarket)
if (rsi < 30)
strategy.entry("Long", strategy.long)
if (rsi > 70)
strategy.entry("Short", strategy.short)
// Close positions when conditions no longer met or reverse
if (trendingMarket and not bullishSignal)
strategy.close("Long")
if (trendingMarket and not bearishSignal)
strategy.close("Short")
if (rangingMarket and rsi > 40)
strategy.close("Long")
if (rangingMarket and rsi < 60)
strategy.close("Short")
// Optional: Add stop loss and take profit
stopLossPerc = input.float(2, title="Stop Loss (%)", minval=0.1, step=0.1) / 100
takeProfitPerc = input.float(4, title="Take Profit (%)", minval=0.1, step=0.1) / 100
strategy.exit("Exit Long", "Long", stop=close*(1-stopLossPerc), limit=close*(1+takeProfitPerc))
strategy.exit("Exit Short", "Short", stop=close*(1+stopLossPerc), limit=close*(1-takeProfitPerc))