Name
Stochastic-RSI交易策略Stochastic-RSI-Trading-Strategy
Author
ChaoZhang
Strategy Description
[trans]
该策略是基于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指标的优势,使用多空线穿越产生交易信号。该策略简单易操作,但存在一定的假信号风险。通过优化止损策略、参数选择、趋势判断等手段,可以继续改进该策略,使之成为一个较为可靠的短线交易策略。
||
This strategy is based on the Stochastic RSI indicator, which combines the Stochastic oscillator and the Relative Strength Index (RSI). It generates trading signals when the Stochastic RSI lines cross overbought or oversold levels.
-
Calculate the 14-period RSI of close price, rsi1.
-
Calculate the Stochastic K and D values based on rsi1.
-
Go long when K goes above 80, and go short when K falls below 20.
-
Close positions when K crosses the 80 and 20 levels.
-
Option to trade in the reverse direction.
-
Backtest on different products and timeframes to evaluate performance.
The main advantages of this strategy are:
-
Stochastic RSI combines the strengths of RSI and Stochastic oscillators.
-
Overbought/oversold areas help filter false breakouts.
-
Flexibility to trade reversals when configured.
-
Simple and intuitive trading rules.
-
Clear visual signals easy for manual trading.
The main risks of this strategy are:
-
No stop loss exposes to large losses.
-
Oscillators prone to false signals without trend filter.
-
No position sizing control risks over-trading.
-
Lack of parameter optimization leads to overfitting.
-
Ignores trading costs.
-
Insufficient backtest data causes curve fitting.
The strategy can be improved by:
-
Adding stop loss and optimizing stop levels.
-
Optimizing parameters to reduce false signals.
-
Controlling position sizes and leverage.
-
Adding filters to avoid counter-trend trades.
-
Accounting for trading costs.
-
Validating over longer timeframes and instruments.
The Stochastic RSI strategy combines the strengths of RSI and Stochastic oscillators, generating signals when the lines cross key levels. Despite being simple to use, the strategy risks false signals. Further enhancements around stops, parameters, trend filters can help create a more robust short-term trading system.
[/trans]
Strategy Arguments
Argument | Default | Description |
---|---|---|
v_input_1 | 80 | TopBand |
v_input_2 | 20 | LowBand |
v_input_3 | false | Trade reverse |
v_input_4 | 14 | lengthRSI |
v_input_5 | 14 | lengthStoch |
v_input_6 | 3 | smoothK |
v_input_7 | 3 | smoothD |
Source (PineScript)
/*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)
Detail
https://www.fmz.com/strategy/427683
Last Modified
2023-09-23 15:59:22