
La estrategia es un sistema de negociación automatizado que combina el seguimiento de tendencias de varios períodos y la gestión de riesgos. Identifica oportunidades de negociación principalmente a través de un promedio móvil indexado (EMA) de dos períodos de tiempo, de 5 minutos y 1 minuto, mientras que aplica una configuración de pérdidas y ganancias de porcentaje fijo para controlar el riesgo. La estrategia es especialmente adecuada para los comerciantes de línea corta, especialmente aquellos que se centran en el seguimiento de tendencias.
La lógica central de la estrategia se basa en el juicio de tendencias en dos períodos de tiempo:
Se trata de una estrategia de seguimiento de tendencias estructurada y con claridad lógica. Combinando análisis multi-ciclo y una estricta gestión de riesgos, la estrategia capta eficazmente las tendencias del mercado, al mismo tiempo que protege los fondos. Aunque hay cierto espacio para la optimización, el marco básico de la estrategia es sólido y adecuado para ser mejorado y personalizado como una estrategia básica.
/*backtest
start: 2025-01-21 00:00:00
end: 2025-02-20 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"DOGE_USDT"}]
*/
//@version=5
strategy("Scalping Strategy: 1-min Entries with 5-min 200 EMA Filter", overlay=true, initial_capital=10000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=5, calc_on_every_tick=true)
// --- Higher Timeframe Trend Filter ---
// Get the 200-period EMA on a 5-minute timeframe
ema200_5 = request.security(syminfo.tickerid, "5", ta.ema(close, 200), lookahead=barmerge.lookahead_on)
plot(ema200_5, color=color.purple, title="5-min 200 EMA")
// --- Local (1-Minute) Indicators ---
// On a 1-minute chart, calculate a 20-period EMA for entry triggers
ema20_1 = ta.ema(close, 20)
plot(ema20_1, color=color.yellow, title="1-min 20 EMA")
// --- Entry Conditions ---
// For long entries:
// - The overall trend is bullish: current close > 5-min 200 EMA
// - The 1-min candle closes and crosses above its 20 EMA
longCondition = (close > ema200_5) and ta.crossover(close, ema20_1)
// For short entries:
// - Overall bearish trend: current close < 5-min 200 EMA
// - 1-min candle crosses below its 20 EMA
shortCondition = (close < ema200_5) and ta.crossunder(close, ema20_1)
// --- Risk Management Settings ---
// For scalping, use a tight stop loss. Here we set risk at 0.5% of the entry price.
var float riskPerc = 0.005 // 0.5% risk per trade
// Declare global variables for stop loss and take profit so they can be used outside the if-blocks
var float longStop = na
var float longTP = na
var float shortStop = na
var float shortTP = na
// --- Trade Execution ---
if (longCondition)
entryPrice = close
// Stop loss for long: 0.5% below entry
longStop := entryPrice * (1 - riskPerc)
// Take profit: twice the risk distance (1:2 risk-reward)
longTP := entryPrice + 2 * (entryPrice - longStop)
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", from_entry="Long", stop=longStop, limit=longTP)
if (shortCondition)
entryPrice = close
// Stop loss for short: 0.5% above entry
shortStop := entryPrice * (1 + riskPerc)
// Take profit: twice the risk distance
shortTP := entryPrice - 2 * (shortStop - entryPrice)
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", from_entry="Short", stop=shortStop, limit=shortTP)
// --- Visual Debug Markers ---
// Plot a green triangle below bars when a long signal is generated
plotshape(longCondition, title="Long Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.tiny)
// Plot a red triangle above bars when a short signal is generated
plotshape(shortCondition, title="Short Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.tiny)