该策略是基于Stochastic RSI指标的交易策略。Stochastic RSI指标是结合随机指标Stochastic和相对强弱指数RSI而产生的一个 oscilllator 指标。该策略通过 Stochastic RSI的多空线穿越进行判断,产生交易信号。
计算close的14周期RSI,即rsi1。
基于rsi1计算Stochastic K和D值。
K值大于80时做多,小于20时做空。
K线和80、20水平线交叉时平仓。
可选择正向交易或者反向交易。
设置交易品种和周期后,回测查看策略效果。
该策略主要优势:
Stochastic RSI综合了RSI和Stochastic的优点,是一种很好的震荡指标。
结合超买超卖区域判断,可以过滤假突破。
可配置反向交易,适用于看跌机会。
规则简单直观,容易理解实现。
可视化的指标和交易信号,操作容易。
该策略主要风险:
未考虑止损设置,存在大额损失风险。
随机指标容易产生假信号,需要结合趋势过滤。
未控制仓位数量,存在超仓风险。
未设置参数优化方法,参数容易过拟合。
没有考虑交易成本的影响。
回测数据不充分可能导致曲拟合。
该策略可以从以下几点进行优化:
设置止损机制,优化止损点位。
优化参数组合,降低假信号。
增加仓位数量和杠杆控制。
加入趋势判断指标,避免逆势交易。
考虑交易成本的影响。
使用更长的时间周期和不同品种进行回测验证。
Stochastic RSI策略结合了RSI和Stochastic指标的优势,使用多空线穿越产生交易信号。该策略简单易操作,但存在一定的假信号风险。通过优化止损策略、参数选择、趋势判断等手段,可以继续改进该策略,使之成为一个较为可靠的短线交易策略。
/*backtest
start: 2023-08-23 00:00:00
end: 2023-09-22 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 24/11/2014
// This strategy used to calculate the Stochastic RSI
//
// You can change long to short in the Input Settings
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title="Stochastic RSI", shorttitle="Stoch RSI Backtest")
TopBand = input(80, step=0.01)
LowBand = input(20, step=0.01)
reverse = input(false, title="Trade reverse")
hline(TopBand, color=red, linestyle=line)
hline(LowBand, color=green, linestyle=line)
Source = close
lengthRSI = input(14, minval=1), lengthStoch = input(14, minval=1)
smoothK = input(3, minval=1), smoothD = input(3, minval=1)
rsi1 = rsi(Source, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
d_cross_80 = cross(d,TopBand)
dc80 = d_cross_80 ? red : green
pos = iff(k > TopBand, 1,
iff(k < LowBand, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(k, color= orange)
plot(d, color=dc80)