双重跟踪止损海龟交易策略


创建日期: 2023-12-20 13:37:31 最后修改: 2023-12-20 13:37:31
复制: 1 点击次数: 626
avatar of ChaoZhang ChaoZhang
1
关注
1621
关注者

双重跟踪止损海龟交易策略

概述

该策略利用海龟交易法则设立两个追踪止损点,通过双重跟踪止损限制亏损,同时设置不同的参数以过滤掉市场噪音,在趋势较为明显时进行买入。

策略原理

该策略主要通过两个追踪止损点long_1和long_2确定买入时机。其中long_1追踪较长期趋势,long_2追踪较短期趋势。同时设置profit1和profit2作为止损点。

如果价格高于long_1,则市场处于较长期上涨趋势,这个时候如果价格又低于long_2,说明 shorterm出现回调提供较好入场时机,那么就入场做多;如果价格低于long_1,则较长期没有确定趋势,shorterm如果价格高于long_2,说明短期出现反弹,也可以入场。

入场后,设置两个追踪止损点stoploss1和stoploss2,并和profit1、profit2比较取最大值,从而锁定利润。

优势分析

  • 通过双重跟踪止损,可以有效控制风险,最大程度锁定利润
  • 结合长短期两类指标,可以过滤部分噪音,在较明确趋势时入场
  • 可以通过参数调整自由控制策略的保守性

风险分析

  • 策略较为保守,容易错过部分机会
  • 止损点设置不当可能过早止损
  • 交易次数较少,单笔亏损可能较大

可以通过适当调整long和profit的参数,使策略更加进取,增加交易次数。同时优化止损点算法,实现自动调整。

优化方向

  • 优化long和profit的参数找到最优参数组合
  • 尝试之字止损或者影线止损 algorithem 以减少不必要的止损
  • 增加开仓条件以过滤噪音,找到更加明确的趋势
  • 结合交易量指标寻找真实的突破

总结

该策略整体较为保守,适合稳定增长的投资者。通过参数调整和止损算法优化,可以适当增加策略的进取性。此外,增加过滤市场噪音的机制也是后续的一个优化方向。

策略源码
/*backtest
start: 2023-11-19 00:00:00
end: 2023-12-19 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Turtle Project",overlay= true)
//-----------------------------------------------------------
entry_1 =  input(55) 
profit_1 =  input(20)             

long_1 = float(na)                                                             
long_1:= if high[entry_1] >= highest(high,entry_1)                   
    high[entry_1]                                                            
else                                                                              
    long_1[1]                                                                   


profit1 = float(na)                                                            
profit1:= if low[profit_1] <= lowest(low,profit_1)                   
    low[profit_1]                                                            
else                                                                            
    profit1[1]                      
//-----------------------------------------------------------
entry_2 =  input(20) 
profit_2 =  input(10)             

long_2 = float(na)                                                             
long_2:= if high[entry_2] >= highest(high,entry_2)                   
    high[entry_2]                                                            
else                                                                              
    long_2[1]                                                                   


profit2 = float(na)                                                            
profit2:= if low[profit_2] <= lowest(low,profit_2)                   
    low[profit_2]                                                            
else                                                                           
    profit2[1]                      
//------------------------------------------------------------
stoploss_1= lowest(low,1) < long_1 and highest(high,1) > long_1
stoploss_2= lowest(low,1) < long_2 and highest(high,1) > long_2 

stop_1 = input(1)/100
stop_2 = input(2)/100

plotchar(stoploss_1, "high1", "▲",location.top,color=color.red )
plotchar(stoploss_2, "high2", "▲",location.top,color=color.blue)


//------------------------------------------------------------
if strategy.position_size == 0
    if low < long_1
        if high < long_1 
            strategy.entry("longlong_4",strategy.long, stop=long_1)

if strategy.position_size == 0    
    if low > long_1
        if high < long_2 
            strategy.entry("longlong_3",strategy.long, stop=long_2)

stoploss1 = float(na)
stoploss1:= stoploss_1 ? strategy.position_avg_price * (1 - stop_1) : stoploss1[1]
stoploss__1 = max(stoploss1,profit1)

if high > long_1 and strategy.position_size > 0
    strategy.exit("exit_1 ","longlong_4",stop=stoploss__1)

stoploss2 = float(na)
stoploss2:= stoploss_2 ? strategy.position_avg_price * (1 - stop_2) : stoploss2[1]
stoploss__2 = max(stoploss2,profit2)

if high > long_2 and strategy.position_size > 0
    strategy.exit("exit_2 ","longlong_3",stop=stoploss__2)
//--------------------------------------------------------------
plot(long_1,color=color.red ,linewidth=3)
plot(long_2,color=color.blue,linewidth=3)

plot(profit1,color=color.red,   linewidth=1)
plot(profit2,color=color.blue,  linewidth=1)

//plot(stoploss__1,style=plot.style_circles, color=color.yellow) 
//plot(stoploss__2,style=plot.style_circles, color=color.yellow) 

plot(stoploss1,style=plot.style_circles, color=color.blue) 
plot(stoploss2,style=plot.style_circles, color=color.red) 
//--------------------------------------------------------------