该策略是一个结合波动率和动量指标的自适应交易系统,通过多重技术指标的协同配合来捕捉市场趋势。策略采用ATR指标监测市场波动,MACD判断趋势动量,同时结合价格动量指标来确认交易信号,并设置了灵活的止盈止损机制。该系统具有很强的适应性,能够根据市场状况自动调整交易频率和仓位控制。
策略主要依靠三重指标体系作为核心交易逻辑:首先使用ATR衡量市场波动率状况,为交易决策提供波动性参考;其次运用MACD指标的金叉死叉来捕捉趋势转折点,MACD快线与慢线的交叉被用作主要的交易触发信号;第三重验证使用价格动量指标,通过观察价格相对前期的变化来确认趋势强度。系统还加入了50日均线作为趋势过滤器,只有价格在均线之上才允许做多,反之允许做空。为了避免过度交易,策略设置了最小交易间隔,并可选择强制信号交替执行。
该策略是一个设计合理、逻辑严密的量化交易系统,通过多重技术指标的配合使用,实现了对市场趋势的有效捕捉。系统在风险控制和交易执行方面都做了细致的考虑,具有较好的实用性。虽然存在一些潜在风险,但通过建议的优化方向,策略的稳定性和收益性都有望得到进一步提升。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("[ETH] Volatility & Momentum Adaptive Strategy", shorttitle="Definitive 1 day Ethereum Signal", overlay=true, initial_capital=10000, currency=currency.USD)
// === Input Parameters === //
trade_size = input.float(5, title="Trade Size (ETH)")
atr_length = input.int(8, minval=1, title="ATR Length")
macd_fast = input.int(8, minval=1, title="MACD Fast Length")
macd_slow = input.int(7, minval=1, title="MACD Slow Length")
macd_signal = input.int(9, minval=1, title="MACD Signal Length")
momentum_length = input.int(37, title="Momentum Length")
stop_loss_percent = input.float(9.9, title="Stop Loss Percentage (%)")
take_profit_percent = input.float(9.0, title="Take Profit Percentage (%)")
alternate_signal = input.bool(true, title="Alternate Buy/Sell Signals")
// === Indicators === //
// ATR to measure volatility
atr = ta.atr(atr_length)
// MACD for trend momentum
[macd_line, signal_line, _] = ta.macd(close, macd_fast, macd_slow, macd_signal)
macd_cross_up = ta.crossover(macd_line, signal_line)
macd_cross_down = ta.crossunder(macd_line, signal_line)
// Momentum
momentum = ta.mom(close, momentum_length)
// === Signal Control Variables === //
var bool last_signal_long = na
var int last_trade_bar = na
min_bars_between_trades = 5 // Adjust for minimal trade frequency control
time_elapsed = na(last_trade_bar) or (bar_index - last_trade_bar) >= min_bars_between_trades
// === Buy and Sell Conditions === //
// Buy when:
buy_signal = (macd_cross_up and momentum > 0 and close > ta.sma(close, 50) and time_elapsed)
// Sell when:
sell_signal = (macd_cross_down and momentum < 0 and close < ta.sma(close, 50) and time_elapsed)
// Enforce alternate signals if selected
if alternate_signal
buy_signal := buy_signal and (na(last_signal_long) or not last_signal_long)
sell_signal := sell_signal and (not na(last_signal_long) and last_signal_long)
// === Trade Execution === //
// Buy Position
if (buy_signal)
if strategy.position_size < 0
strategy.close("Short")
strategy.entry("Long", strategy.long, qty=trade_size)
last_signal_long := true
last_trade_bar := bar_index
// Sell Position
if (sell_signal)
if strategy.position_size > 0
strategy.close("Long")
strategy.entry("Short", strategy.short, qty=trade_size)
last_signal_long := false
last_trade_bar := bar_index
// === Stop Loss and Take Profit === //
if strategy.position_size > 0
long_take_profit = strategy.position_avg_price * (1 + take_profit_percent / 100)
long_stop_loss = strategy.position_avg_price * (1 - stop_loss_percent / 100)
strategy.exit("TP/SL Long", from_entry="Long", limit=long_take_profit, stop=long_stop_loss)
if strategy.position_size < 0
short_take_profit = strategy.position_avg_price * (1 - take_profit_percent / 100)
short_stop_loss = strategy.position_avg_price * (1 + stop_loss_percent / 100)
strategy.exit("TP/SL Short", from_entry="Short", limit=short_take_profit, stop=short_stop_loss)
// === Visual Signals === //
plotshape(series=buy_signal and time_elapsed, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sell_signal and time_elapsed, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")