该策略通过计算比特币的真实强弱指标(True Strength Index,TSI)以识别市场趋势,并结合RSI指标过滤做多做空时机,实现对比特币的短线交易。该策略适合对比特币市场逐笔行情进行程序化交易的投资者。
该策略主要基于真实强弱指标(TSI)。TSI指标通过双平滑价格变化率,来衡量价格变动的绝对值大小和方向,从而识别出价格上涨和下跌的绝对力度。具体计算方法如下:
当TSI指标上穿其信号线tsi2时产生做多信号,下穿其信号线tsi2时产生做空信号。此外,策略还结合RSI指标过滤TSI交易信号,只有当RSI值大于50时才产生做多信号,RSI值小于50时才产生做空信号,从而过滤掉部分假信号。
该策略具有以下优势:
该策略也存在以下风险:
可以通过适当放宽RSI过滤条件,缩短EMA周期等方式来降低滤波效应和滞后问题。同时优化止损策略,严格控制单笔交易风险。
该策略可以从以下几个方面进行优化:
优化TSI和RSI的参数,找到最佳参数组合。可以调整长短EMA周期、RSI参数等。
增加其他指标结合,形成多因子模型。例如可以加入MA,KD等指标,充分发挥各指标优势。
优化入场条件,避免多头市撞空头,空头市撞多头。可以根据大周期趋势判断方向。
优化止损策略,例如移动止损、时间止损、突破止损等方式。
优化离场条件,防止止损过早或过晚离场。可以结合波动率指标判断何时离场。
对交易品种、交易时段进行优化,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)