该策略通过同时观察三个不同周期的RSI指标,来判断市场是否达到了超买超卖的极值区域,从而发出买入和卖出信号。主要判断市场趋势通过观察不同周期指标的组合来实现。
该策略同时利用2周期、7周期和14周期的RSI指标。当三个RSI指标同时显示超买或超卖信号时,即发出交易信号。
具体来说,当2周期RSI小于10,7周期RSI小于20,14周期RSI小于30时,认为市场处于超卖状态,发出买入信号。当2周期RSI大于90,7周期RSI大于80,14周期RSI大于70时,认为市场处于超买状态,发出卖出信号。
代码中通过accuracy参数来微调RSI的超买超卖判断阈值,默认为3,数值越小,超买超卖判断越严格。strategy.long和strategy.short用于控制是否进行相应方向交易。
当发出买入或卖出信号后,如果价格反向突破当日开盘价,则平掉当前头寸,实施趋势跟踪止损。
通过组合多周期RSI指标,可以更准确判断市场的超买超卖状况,过滤假信号。
采用不同参数微调超买超卖判定条件,可以根据市场调整策略灵敏度。
实施开盘价追踪止损,可以及时止损,锁定盈利。
RSI指标容易产生背离,判断市场趋势转折的效果不佳。
针对高波动行情,RSI指标的设置需要调整,否则会频繁止损。
三重RSI同时触发的情况较少,可能错过较好的交易机会。
应适当调整超买超卖判断的参数,建议测试不同市场的数据效果。
可以考虑加入别的指标进行确认,如布林线,KDJ等,避免RSI背离。
可以根据不同行情类型,自动优化RSI的参数。
可以测试其他止损exit条件,如ATR止损等。
可以添加筛选交易时段的条件,避免不适宜的时间段。
该策略通过组合多周期RSI指标判断超买超卖区域,实施趋势跟踪止损。优点是可以提高判断准确性,及时止损;缺点是容易漏单,RSI指标易错判。建议进行参数优化测试,并加入其他指标进行确认,可获得更好的效果。
/*backtest
start: 2023-10-25 00:00:00
end: 2023-10-28 10:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy(title = "Noro's Triple RSI Top/Bottom", shorttitle = "3RSI Top/Bottom", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)
//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
accuracy = input(3, defval = 3, minval = 1, maxval = 10, title = "accuracy")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")
//RSI-2
fastup = rma(max(change(close), 0), 2)
fastdown = rma(-min(change(close), 0), 2)
fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))
//RSI-7
middleup = rma(max(change(close), 0), 7)
middledown = rma(-min(change(close), 0), 7)
middlersi = middledown == 0 ? 100 : middleup == 0 ? 0 : 100 - (100 / (1 + middleup / middledown))
//RSI-14
slowup = rma(max(change(close), 0), 14)
slowdown = rma(-min(change(close), 0), 14)
slowrsi = slowdown == 0 ? 100 : slowup == 0 ? 0 : 100 - (100 / (1 + slowup / slowdown))
//Signals
acc = 10 - accuracy
up = fastrsi < (5 + acc) and middlersi < (10 + acc * 2) and slowrsi < (15 + acc * 3)
dn = fastrsi > (95 - acc) and middlersi > (90 - acc * 2) and slowrsi > (85 - acc * 3)
exit = (strategy.position_size > 0 and close > open) or (strategy.position_size > 0 and close > open)
//Trading
if up
if strategy.position_size < 0
strategy.close_all()
strategy.entry("Bottom", strategy.long, needlong == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if dn
if strategy.position_size > 0
strategy.close_all()
strategy.entry("Top", strategy.short, needshort == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if time > timestamp(toyear, tomonth, today, 23, 59) or exit
strategy.close_all()