资源加载中... loading...

多重指标动态自适应调仓ATR波动率策略

Author: ChaoZhang, Date: 2024-11-12 11:41:30
Tags: ATREMARSISMA

多重指标动态自适应调仓ATR波动率策略

概述

该策略是一个基于多重技术指标和动态风险管理的量化交易策略。它结合了EMA趋势跟踪、ATR波动率、RSI超买超卖以及K线形态识别等多个维度,通过自适应调仓和动态止损来实现收益风险的平衡。策略采用了分批止盈和移动止损的方式来保护盈利。

策略原理

策略主要通过以下几个方面来实现交易: 1. 使用5周期和10周期的EMA均线交叉来确定趋势方向 2. 通过RSI指标判断超买超卖区域,避免追涨杀跌 3. 利用ATR指标动态调整止损位置和仓位大小 4. 结合K线形态(吞没、锤子、流星)作为辅助入场信号 5. 采用基于ATR的动态滑点补偿机制 6. 通过交易量确认来过滤虚假信号

策略优势

  1. 多重信号交叉验证,提高交易可靠性
  2. 动态风险管理,根据市场波动自适应调整
  3. 分批止盈策略,合理锁定部分利润
  4. 采用移动止损,保护既有盈利
  5. 设置每日止损限制,控制风险暴露
  6. 滑点动态补偿,提高订单成交率

策略风险

  1. 多重指标可能导致信号滞后
  2. 频繁交易可能产生较高成本
  3. 在震荡市场中可能频繁止损
  4. K线形态识别存在主观因素
  5. 参数优化可能导致过度拟合

策略优化方向

  1. 引入市场波动周期判断,动态调整参数
  2. 增加趋势强度过滤器,减少假信号
  3. 优化仓位管理算法,提高资金利用效率
  4. 加入更多的市场情绪指标
  5. 开发自适应参数优化系统

总结

这是一个综合了多个技术指标的成熟策略系统,通过动态风险管理和多重信号验证来提高交易的稳定性。策略的核心优势在于其自适应性和完善的风险控制体系,但仍需要在实盘中进行充分验证和持续优化。


/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Optimized Scalping with High Risk-Reward", overlay=true)

// Input for EMA periods
shortEMA_length = input(5, title="Short EMA Length")
longEMA_length = input(10, title="Long EMA Length")

// ATR for dynamic stop-loss
atrPeriod = input(14, title="ATR Period")
atrMultiplier = input(1.5, title="ATR Multiplier for Stop Loss")

// Calculate EMAs
shortEMA = ta.ema(close, shortEMA_length)
longEMA = ta.ema(close, longEMA_length)

// ATR calculation for dynamic stop loss
atr = ta.atr(atrPeriod)

// RSI for overbought/oversold conditions
rsi = ta.rsi(close, 14)

// Plot EMAs
plot(shortEMA, color=color.blue, title="Short EMA")
plot(longEMA, color=color.red, title="Long EMA")

// Dynamic Slippage based on ATR
dynamic_slippage = math.max(5, atr * 0.5)

// Candlestick pattern recognition
bullish_engulfing = close[1] < open[1] and close > open and close > open[1] and close > close[1]
hammer = close > open and (high - close) / (high - low) > 0.6 and (open - low) / (high - low) < 0.2
bearish_engulfing = open[1] > close[1] and open > close and open > open[1] and close < close[1]
shooting_star = close < open and (high - open) / (high - low) > 0.6 and (close - low) / (high - low) < 0.2

// Enhanced conditions with volume and RSI check
buy_condition = (bullish_engulfing or hammer) and close > shortEMA and shortEMA > longEMA and volume > ta.sma(volume, 20) and rsi < 70
sell_condition = (bearish_engulfing or shooting_star) and close < shortEMA and shortEMA < longEMA and volume > ta.sma(volume, 20) and rsi > 30

// Dynamic ATR multiplier based on recent volatility
volatility = atr
adaptiveMultiplier = atrMultiplier + (volatility - ta.sma(volatility, 50)) / ta.sma(volatility, 50) * 0.5

// Execute buy trades with slippage consideration
if (buy_condition)
    strategy.entry("Buy", strategy.long)
    stop_loss_buy = strategy.position_avg_price - atr * adaptiveMultiplier - dynamic_slippage
    take_profit_buy = strategy.position_avg_price + atr * adaptiveMultiplier * 3 + dynamic_slippage
    strategy.exit("Exit Buy", "Buy", stop=stop_loss_buy, limit=take_profit_buy)

// Execute sell trades with slippage consideration
if (sell_condition)
    strategy.entry("Sell", strategy.short)
    stop_loss_sell = strategy.position_avg_price + atr * adaptiveMultiplier + dynamic_slippage
    take_profit_sell = strategy.position_avg_price - atr * adaptiveMultiplier * 3 - dynamic_slippage
    strategy.exit("Exit Sell", "Sell", stop=stop_loss_sell, limit=take_profit_sell)

// Risk Management
maxLossPerTrade = input.float(0.01, title="Max Loss Per Trade (%)", minval=0.01, maxval=1, step=0.01)  // 1% max loss per trade
dailyLossLimit = input.float(0.03, title="Daily Loss Limit (%)", minval=0.01, maxval=1, step=0.01) // 3% daily loss limit

maxLossAmount_buy = strategy.position_avg_price * maxLossPerTrade
maxLossAmount_sell = strategy.position_avg_price * maxLossPerTrade

if (strategy.position_size > 0)
    strategy.exit("Max Loss Buy", "Buy", stop=strategy.position_avg_price - maxLossAmount_buy - dynamic_slippage)

if (strategy.position_size < 0)
    strategy.exit("Max Loss Sell", "Sell", stop=strategy.position_avg_price + maxLossAmount_sell + dynamic_slippage)

// Daily loss limit logic
var float dailyLoss = 0.0
if (dayofweek != dayofweek[1])
    dailyLoss := 0.0  // Reset daily loss tracker at the start of a new day

if (strategy.closedtrades > 0)
    dailyLoss := dailyLoss + strategy.closedtrades.profit(strategy.closedtrades - 1)

if (dailyLoss < -strategy.initial_capital * dailyLossLimit)
    strategy.close_all("Daily Loss Limit Hit")

// Breakeven stop after a certain profit with a delay
if (strategy.position_size > 0 and close > strategy.position_avg_price + atr * 1.5 and bar_index > strategy.opentrades.entry_bar_index(0) + 5)
    strategy.exit("Breakeven Buy", from_entry="Buy", stop=strategy.position_avg_price)

if (strategy.position_size < 0 and close < strategy.position_avg_price - atr * 1.5 and bar_index > strategy.opentrades.entry_bar_index(0) + 5)
    strategy.exit("Breakeven Sell", from_entry="Sell", stop=strategy.position_avg_price)

// Partial Profit Taking
if (strategy.position_size > 0 and close > strategy.position_avg_price + atr * 1.5)
    strategy.close("Partial Close Buy", qty_percent=50)  // Use strategy.close for partial closure at market price

if (strategy.position_size < 0 and close < strategy.position_avg_price - atr * 1.5)
    strategy.close("Partial Close Sell", qty_percent=50) // Use strategy.close for partial closure at market price

// Trailing Stop with ATR type
if (strategy.position_size > 0)
    strategy.exit("Trailing Stop Buy", from_entry="Buy", trail_offset=atr * 1.5, trail_price=strategy.position_avg_price)

if (strategy.position_size < 0)
    strategy.exit("Trailing Stop Sell", from_entry="Sell", trail_offset=atr * 1.5, trail_price=strategy.position_avg_price)


相关内容

更多内容