高级动态追踪止损与目标盈利策略

RSI ATR SMA
创建日期: 2024-12-11 14:57:09 最后修改: 2024-12-11 14:57:09
复制: 0 点击次数: 150
avatar of ChaoZhang ChaoZhang
1
关注
1259
关注者

高级动态追踪止损与目标盈利策略

概述

该策略是一个结合了动态追踪止损、风险报酬比和RSI极值退出的高级交易系统。策略通过识别市场中的特定形态(平行K线形态和针型K线形态)来进行交易,同时利用ATR和最近低点来设置动态止损位,并根据预设的风险回报比来确定获利目标。系统还集成了基于RSI指标的市场过热/过冷判断机制,可以在市场达到极值时及时平仓。

策略原理

策略的核心逻辑包括以下几个关键部分: 1. 入场信号基于两种形态:平行K线形态(大阳线跟随大阴线)和双针型K线形态。 2. 动态追踪止损使用ATR乘数对最近N根K线的最低价进行调整,确保止损位能够动态适应市场波动。 3. 获利目标基于固定的风险回报比设置,通过计算每笔交易的风险值®来确定。 4. 仓位规模根据固定风险金额和每笔交易的风险值动态计算。 5. RSI极值退出机制在市场过热或过冷时触发平仓信号。

策略优势

  1. 动态风险管理:通过ATR和最近低点的结合,止损位能够根据市场波动动态调整。
  2. 精确的仓位控制:基于固定风险金额的仓位计算方法确保每笔交易的风险一致。
  3. 多维度的退出机制:结合追踪止损、固定盈利目标和RSI极值三重退出机制。
  4. 灵活的交易方向选择:可以选择只做多、只做空或者双向交易。
  5. 清晰的风险回报设置:通过预设的风险回报比明确每笔交易的盈利目标。

策略风险

  1. 形态识别的准确性风险:平行K线和针型K线的识别可能存在误判。
  2. 止损设置的滑点风险:在波动剧烈的市场中可能面临较大滑点。
  3. RSI极值退出可能过早:在强趋势市场中可能导致提前退出而错过更多盈利。
  4. 固定风险回报比的局限性:不同市场环境下最优的风险回报比可能不同。
  5. 参数优化的过拟合风险:多个参数的组合可能导致过度优化。

策略优化方向

  1. 入场信号优化:可以增加更多的形态确认指标,如成交量、趋势指标等。
  2. 动态风险回报比:根据市场波动性动态调整风险回报比。
  3. 智能参数自适应:引入机器学习算法对参数进行动态优化。
  4. 多时间周期确认:增加更多时间周期的信号确认机制。
  5. 市场环境分类:根据不同的市场环境采用不同的参数组合。

总结

这是一个设计完善的交易策略,通过结合多个成熟的技术分析概念,构建了一个完整的交易系统。策略的优势在于其全面的风险管理体系和灵活的交易规则,但同时也需要注意参数优化和市场适应性的问题。通过建议的优化方向,策略还有进一步提升的空间。

策略源码
/*backtest
start: 2024-11-10 00:00:00
end: 2024-12-09 08:00:00
period: 2h
basePeriod: 2h
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/
// © ZenAndTheArtOfTrading | www.TheArtOfTrading.com
// @version=5
strategy("Trailing stop 1", overlay=true)

// Get user input 
int     BAR_LOOKBACK    = input.int(10, "Bar Lookback")
int     ATR_LENGTH      = input.int(14, "ATR Length")
float   ATR_MULTIPLIER  = input.float(1.0, "ATR Multiplier")
rr                      = input.float(title="Risk:Reward", defval=3)

// Basic definition
var float shares=na
risk = 1000
var float R=na
E = strategy.position_avg_price

// Input option to choose long, short, or both
side = input.string("Long", title="Side", options=["Long", "Short", "Both"])

// RSI exit option
RSIexit = input.string("Yes", title="Exit at RSI extreme?", options=["Yes", "No"])
RSIup = input(75)
RSIdown = input(25)

// Get indicator values 
float atrValue = ta.atr(ATR_LENGTH)

// Calculate stop loss values
var float trailingStopLoss = na 
float longStop  = ta.lowest(low, BAR_LOOKBACK) - (atrValue * ATR_MULTIPLIER)
float shortStop = ta.highest(high, BAR_LOOKBACK) + (atrValue * ATR_MULTIPLIER)

// Check if we can take trades 
bool canTakeTrades = not na(atrValue)
bgcolor(canTakeTrades ? na : color.red)

//Long pattern
    //Two pin bar
onepinbar = (math.min(close,open)-low)/(high-low)>0.6 and math.min(close,open)-low>ta.sma(high-low,14)
twopinbar = onepinbar and onepinbar[1]
notatbottom = low>ta.lowest(low[1],10)
    // Parallel
bigred = (open-close)/(high-low)>0.8 and high-low>ta.sma(high-low,14)
biggreen = (close-open)/(high-low)>0.8 and high-low>ta.sma(high-low,14)
parallel = bigred[1] and biggreen  
atbottom = low==ta.lowest(low,10)

// Enter long trades (replace this entry condition)
longCondition = parallel 
if (longCondition and canTakeTrades and  strategy.position_size == 0 and (side == "Long" or side == "Both"))
    R:= close-longStop
    shares:= risk/R
    strategy.entry("Long", strategy.long,qty=shares)

// Enter short trades (replace this entry condition)
shortCondition = parallel
if (shortCondition and canTakeTrades and strategy.position_size == 0 and (side == "Short" or side == "Both"))
    R:= shortStop - close
    shares:= risk/R
    strategy.entry("Short", strategy.short,qty=shares)

// Update trailing stop
if (strategy.position_size > 0)
    if (na(trailingStopLoss) or longStop > trailingStopLoss)
        trailingStopLoss := longStop
else if (strategy.position_size < 0)
    if (na(trailingStopLoss) or shortStop < trailingStopLoss)
        trailingStopLoss := shortStop
else
    trailingStopLoss := na

// Exit trades with trailing stop
strategy.exit("Long Exit",  "Long",  stop=trailingStopLoss, limit = E + rr*R )
strategy.exit("Short Exit", "Short", stop=trailingStopLoss, limit = E - rr*R)

//Close trades at RSI extreme
if ta.rsi(high,14)>RSIup and RSIexit == "Yes"
    strategy.close("Long")
if ta.rsi(low,14)<RSIdown and RSIexit == "Yes"
    strategy.close("Short")

// Draw stop loss 
plot(trailingStopLoss, "Stop Loss", color.red, 1, plot.style_linebr)
相关推荐