基于真实强弱指标的比特币短线交易策略


创建日期: 2023-10-07 15:12:08 最后修改: 2023-10-07 15:12:08
复制: 0 点击次数: 559
avatar of ChaoZhang ChaoZhang
1
关注
1259
关注者

概述

该策略通过计算比特币的真实强弱指标(True Strength Index,TSI)以识别市场趋势,并结合RSI指标过滤做多做空时机,实现对比特币的短线交易。该策略适合对比特币市场逐笔行情进行程序化交易的投资者。

策略原理

该策略主要基于真实强弱指标(TSI)。TSI指标通过双平滑价格变化率,来衡量价格变动的绝对值大小和方向,从而识别出价格上涨和下跌的绝对力度。具体计算方法如下:

  1. 计算价格的变化率Pc
  2. 对Pc进行双平滑,分别使用长期EMA和短期EMA,生成double_smoothed_pc
  3. 对绝对值Pc进行双平滑,生成double_smoothed_abs_pc
  4. TSI值为double_smoothed_pc除以double_smoothed_abs_pc乘以100

当TSI指标上穿其信号线tsi2时产生做多信号,下穿其信号线tsi2时产生做空信号。此外,策略还结合RSI指标过滤TSI交易信号,只有当RSI值大于50时才产生做多信号,RSI值小于50时才产生做空信号,从而过滤掉部分假信号。

优势分析

该策略具有以下优势:

  1. TSI指标能够识别价格变动的绝对力度和方向,对于捕捉趋势较为敏感。
  2. 双EMA平滑价格变化率,可以有效滤除价格变动的噪音,对突发事件不敏感。
  3. 结合RSI指标过滤,可以进一步避免因噪音导致的错误交易。
  4. 采用短线交易方式,能够捕捉市场中的短期机会。
  5. 策略参数优化空间大,可以通过调整EMA周期等参数进行优化。

风险分析

该策略也存在以下风险:

  1. 作为趋势跟踪指标,TSI存在滞后问题,可能错过价格反转点。
  2. RSI过滤条件过于严格,可能错过部分交易机会。
  3. 双EMA滤波也可能过滤掉部分有效交易信号。
  4. 短线交易具有较高的交易频率,需要承担更高的交易成本和滑点风险。

可以通过适当放宽RSI过滤条件,缩短EMA周期等方式来降低滤波效应和滞后问题。同时优化止损策略,严格控制单笔交易风险。

优化方向

该策略可以从以下几个方面进行优化:

  1. 优化TSI和RSI的参数,找到最佳参数组合。可以调整长短EMA周期、RSI参数等。

  2. 增加其他指标结合,形成多因子模型。例如可以加入MA,KD等指标,充分发挥各指标优势。

  3. 优化入场条件,避免多头市撞空头,空头市撞多头。可以根据大周期趋势判断方向。

  4. 优化止损策略,例如移动止损、时间止损、突破止损等方式。

  5. 优化离场条件,防止止损过早或过晚离场。可以结合波动率指标判断何时离场。

  6. 对交易品种、交易时段进行优化,concentration在最有效的品种和交易时段。

总结

本策略通过真实强弱指标识别比特币短期趋势,并辅以RSI指标过滤信号,可以有效进行比特币的短线程序化交易。该策略具有敏感识别趋势、滤除噪音的优势,但也存在一定的滞后问题和交易风险。通过多方面优化,可以进一步提升策略表现,开发出可靠的比特币交易专家顾问。

策略源码
/*backtest
start: 2022-09-30 00:00:00
end: 2023-10-06 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/


// strategy("True Strength Indicator BTCUSD 15p", shorttitle="TSI BTCUSD 15p",initial_capital=1000, commission_value=0.15, commission_type =strategy.commission.percent, default_qty_value=100 , overlay = false, pyramiding=10, default_qty_type=strategy.percent_of_equity)

//BASED ON True Strength Indicator MTF
resCustom = input(title="Timeframe",  defval="15" )
long = input(title="Long Length",  defval=25)
short = input(title="Short Length",  defval=13)
signal = input(title="Signal Length",  defval=13)
price = request.security(syminfo.tickerid,resCustom,close)


double_smooth(src, long, short) =>
    fist_smooth = ta.ema(src, long)
    ta.ema(fist_smooth, short)
pc = ta.change(price)
double_smoothed_pc = double_smooth(pc, long, short)
double_smoothed_abs_pc = double_smooth(math.abs(pc), long, short)
tsi_value = 100 * (double_smoothed_pc / double_smoothed_abs_pc)
tsi2=ta.ema(tsi_value, signal)
plot(tsi_value, color=color.lime,linewidth=2)
plot(tsi2, color=color.red,linewidth=2)




rsiserie = ta.rsi(price,7)
cciserie = ta.cci(price,14)
stochserie = ta.stoch(price,14,3,3)

plot(rsiserie,color=color.purple)



hline(30, title="Zero")
hline(50, title="Zero",linestyle=hline.style_solid, linewidth=2)
hline(70, title="Zero")

buy = ta.crossover(tsi_value, tsi2) //and rsiserie[1]<25 //and cciserie<-100 and stochserie<20
sell = ta.crossunder(tsi_value, tsi2) //and rsiserie[1]>85 //and cciserie>100 and stochserie>80


alertcondition(buy, title='TSI system', message='Buy signal at!' )
alertcondition(sell, title='TSI system', message='Sell signal at!' )

strategy.entry("BUY", strategy.long, 1, when = buy)
strategy.entry("SELL", strategy.short, 1, when = sell ) 

greentsi =tsi_value
redtsi = tsi2

bgcolor( greentsi>redtsi and rsiserie > 50 ? color.lime : na, transp=90)
bgcolor( greentsi<redtsi and rsiserie < 50 ? color.red : na, transp=90)

yellow1= redtsi > greentsi and rsiserie > 50 
yellow2 = redtsi < greentsi and rsiserie < 50 
bgcolor( yellow1 ? yellow : na, transp=80)
bgcolor( yellow2  ? yellow : na, transp=50)

bgcolor( yellow1 and yellow1[1] ? yellow : na, transp=70)
bgcolor( yellow2  and yellow2[2] ? yellow : na, transp=70)

bgcolor( rsiserie > 70 ? color.lime : na, transp=60)
bgcolor( rsiserie < 30  ? color.red : na, transp=60)