
La estrategia combina varios indicadores técnicos, incluido el índice de fuerza relativa (RSI), el indicador de dispersión de convergencia de promedios móviles (MACD) y el promedio móvil simple (SMA) de varios períodos diferentes, con el objetivo de proporcionar una herramienta de análisis integral para el comercio de Bitcoin (BTC). La idea principal de la estrategia es tomar en cuenta las señales de los diferentes indicadores de forma integrada, hacer más cuando el RSI está en un rango específico, el MACD aparece y el precio de la horquilla está por debajo de varios SMA, al mismo tiempo establecer un stop loss y un stop loss, y actualizar la posición de stop loss cuando el RSI alcanza los 50.
La estrategia proporciona un marco analítico integral para el comercio de Bitcoin mediante la aplicación integrada de indicadores técnicos como RSI, MACD y SMA. Utiliza la confirmación conjunta de varios indicadores para generar señales de negociación y establece medidas de control de riesgo. Sin embargo, la estrategia aún tiene espacio para optimización, como la introducción de más indicadores, parámetros de ajuste dinámico y análisis combinado de elementos fundamentales.
/*backtest
start: 2024-03-01 00:00:00
end: 2024-03-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Advanced Strategy", shorttitle="1M Advanced Strat", overlay=true)
// Input settings
rsiLength = input(14, title="RSI Length")
rsiLowerBound = input(20, title="RSI Lower Bound")
rsiUpperBound = input(30, title="RSI Upper Bound")
atrLength = input(14, title="ATR Length")
smaFastLength = input(20, title="SMA 20 Length")
smaMediumLength = input(50, title="SMA 50 Length")
smaSlowLength = input(200, title="SMA 200 Length")
riskPercent = input(0.005, title="Risk Percentage for SL and Target")
// Calculate indicators
rsiValue = rsi(close, rsiLength)
[macdLine, signalLine, _] = macd(close, 12, 26, 9)
smaFast = sma(close, smaFastLength)
smaMedium = sma(close, smaMediumLength)
smaSlow = sma(close, smaSlowLength)
atrValue = atr(atrLength)
// Checking previous RSI value
prevRsiValue = rsi(close[1], rsiLength)
// Conditions for Entry
longCondition = rsiValue > rsiLowerBound and rsiValue < rsiUpperBound and prevRsiValue < rsiLowerBound or prevRsiValue > rsiUpperBound and crossover(macdLine, signalLine) and close < smaFast and close < smaMedium and close < smaSlow
// Strategy Entry
if (longCondition and not strategy.position_size)
strategy.entry("Long", strategy.long)
// Setting Stop Loss and Take Profit
stopLoss = close - riskPercent * close
takeProfit = close + atrValue
strategy.exit("Exit Long", "Long", stop = stopLoss, limit = takeProfit)
//Update Stop Loss when RSI reaches 50
if (strategy.position_size > 0 and rsiValue >= 50)
strategy.exit("Update SL", "Long", stop = high)
// Conditions for Exit
shortCondition = crossunder(macdLine, signalLine)
// Strategy Exit
if (shortCondition)
strategy.close("Long")