
Se trata de una estrategia de trading cuantitativa basada en indicadores de tendencia promedio (ADX) y breakouts de precios. La estrategia se basa principalmente en la vigilancia de los valores de los indicadores de ADX para juzgar la fuerza de la tendencia del mercado y, en combinación con las señales de breakouts de precios, para capturar el movimiento del mercado. La estrategia se establece para operar dentro de un período de negociación específico y permite la gestión del riesgo a través de stop loss y un límite en el número de transacciones diarias.
La lógica central de la estrategia incluye los siguientes elementos clave:
Se trata de una estrategia de seguimiento de tendencias estructurada y con claridad de lógica. Capturar oportunidades de tendencias en el mercado mediante la combinación de indicadores de ADX con brechas de precios en un marco de gestión de riesgos eficaz. Aunque hay algo de espacio para la optimización, el marco básico de la estrategia es sólido y adecuado para ser el componente básico de un sistema de comercio cuantitativo.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 00:00:00
period: 1d
basePeriod: 1d
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/
// © HuntGatherTrade
// ========================
// NQ 30 minute, ES 30 minute
//@version=5
strategy("ADX Breakout", overlay=false, initial_capital=25000, default_qty_value=1)
// ===============================
// Input parameters
// ===============================
stopLoss = input(1000.0, title="Stop Loss ($)", group="Exits")
session = input("0730-1430:1234567", group="Trade Session")
highestLB = input(34, title="Highest lookback window", group="Indicator values")
// ===============================
// Trade Session Handling
// ===============================
t = time(timeframe.period, session)
// Reset numTrades at the start of each session
var int numTrades = 0
is_new_session = ta.change(time("D")) != 0
if is_new_session
numTrades := 0
// ===============================
// Entry Conditions
// ===============================
[plusDI, minusDI, adxValue] = ta.dmi(50, 14)
entryCondition = (close >= ta.highest(close, highestLB)[1]) and (adxValue < 17.5) and (strategy.position_size == 0) and (numTrades < 3) and not na(t)
// ===============================
// 7. Execute Entry
// ===============================
var float stopPricePlot = na
if entryCondition
entryPrice = close + syminfo.mintick
strategy.entry("Long Entry", strategy.long, stop=entryPrice)
//stopPrice = strategy.position_avg_price - (stopLoss / syminfo.pointvalue)
//strategy.exit("Stop Loss", "Long Entry", stop=stopPrice)
numTrades += 1
if (strategy.position_size > 0) and (strategy.position_size[1] == 0)
stopPoints = stopLoss / syminfo.pointvalue
stopPrice = strategy.position_avg_price - stopPoints
stopPrice := math.round(stopPrice / syminfo.mintick) * syminfo.mintick
strategy.exit("Stop Loss", from_entry="Long Entry", stop=stopPrice)
if ta.change(strategy.opentrades) == 1
float entryPrice = strategy.opentrades.entry_price(0)
stopPricePlot := entryPrice - (stopLoss / syminfo.pointvalue)
if ta.change(strategy.closedtrades) == 1
stopPricePlot := na
plot(stopPricePlot, "Stop-loss level", color.red, 1, plot.style_linebr)
// ===============================
// Exit at End of Session
// ===============================
if na(t) and strategy.position_size != 0
strategy.close_all(comment="End of Day Exit")