//@version=5 strategy("Estrategia de Scalping Optimizada con Apalancamiento", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=5) // Configuración de indicadores lengthRSI = input.int(14, "Longitud RSI") upperThresholdRSI = input.int(70, "Umbral Superior RSI") lowerThresholdRSI = input.int(30, "Umbral Inferior RSI") rsi = ta.rsi(close, lengthRSI) // Configuración de Bandas de Bollinger para confirmación lengthBB = input.int(20, "Longitud BB") multBB = input.float(2.0, "Multiplicador BB") basisBB = ta.sma(close, lengthBB) devBB = multBB * ta.stdev(close, lengthBB) upperBB = basisBB + devBB lowerBB = basisBB - devBB // Opción para elegir operaciones en largo, corto o ambos tradeDirection = input.string("both", "Dirección de Operación", options=["long", "short", "both"]) // Opción para apalancamiento leverage = input.float(1.0, "Apalancamiento", minval=1.0, maxval=100.0, step=0.1) // Señales de entrada más selectivas longCondition = (rsi < lowerThresholdRSI) and (close < lowerBB) shortCondition = (rsi > upperThresholdRSI) and (close > upperBB) // Gestión de riesgo dinámica basada en la volatilidad atr = ta.atr(14) riskPerTrade = input.float(1.0, "Riesgo por Operación (%)", step=0.1) stopLossATRMultiple = input.float(2.0, "Múltiplo de ATR para Stop Loss", step=0.5) // Cálculo de tamaño de posición basado en el riesgo, ATR y apalancamiento riskAmount = strategy.equity * riskPerTrade / 100 positionSize = (riskAmount / (atr * stopLossATRMultiple)) * leverage // Ejecución de órdenes con gestión de riesgo basada en la dirección seleccionada if (tradeDirection == "long" or tradeDirection == "both") and longCondition strategy.entry("Compra", strategy.long, qty=positionSize) strategy.exit("StopLoss/TakeProfit Compra", "Compra", stop=close - atr * stopLossATRMultiple, limit=close + atr * stopLossATRMultiple * 2) if (tradeDirection == "short" or tradeDirection == "both") and shortCondition strategy.entry("Venta", strategy.short, qty=positionSize) strategy.exit("StopLoss/TakeProfit Venta", "Venta", stop=close + atr * stopLossATRMultiple, limit=close - atr * stopLossATRMultiple * 2) // Visualización en gráfico plot(upperBB, "Banda Superior BB", color=color.red) plot(basisBB, "Banda Media BB", color=color.blue) plot(lowerBB, "Banda Inferior BB", color=color.green) hline(upperThresholdRSI, "Umbral Superior RSI", color=color.red) hline(lowerThresholdRSI, "Umbral Inferior RSI", color=color.green)