这是一个基于平均趋向指标(ADX)和价格突破的量化交易策略。该策略主要通过监控ADX指标数值来判断市场趋势强度,并结合价格突破信号来捕捉市场动量。策略设定在特定交易时段内运行,并通过止损和每日交易次数限制来实现风险管理。
策略的核心逻辑包含以下几个关键要素: 1. ADX指标监控:使用ADX指标来评估市场趋势强度,当ADX值低于17.5时表明市场可能即将形成新趋势。 2. 价格突破判断:策略会跟踪过去34个周期的最高收盘价,当当前价格突破该阻力位时触发交易信号。 3. 交易时段管理:策略仅在指定的交易时段(0730-1430)内运行,以避免低流动性时段的风险。 4. 风险控制机制: - 设置固定美元止损来限制单笔交易损失 - 限制每个交易时段最多3笔交易 - 交易时段结束时自动平仓所有持仓
这是一个结构完整、逻辑清晰的趋势跟踪策略。通过将ADX指标与价格突破相结合,在有效的风险管理框架下捕捉市场趋势机会。虽然存在一些优化空间,但策略的基础框架稳健,适合作为量化交易系统的基础组件。建议交易者在实盘之前进行充分的回测和参数优化,并结合市场具体情况进行针对性改进。
/*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")