比较相对强度策略是通过计算两个市场的相对强弱来产生交易信号。当被比较市场对基准市场显示出强势的时候,可以看作买入信号;而显露疲软时,为卖出信号。
具体交易逻辑是:
选择被比较市场,例如特定股票
选择基准市场,例如标普500指数
计算被比较市场相对基准市场的强弱比
当比率大于超买线时,做多该被比较市场
当比率小于超卖区域时,做空该被比较市场
设置回调线,价格回落时平仓
通过计算两个市场的相对强弱关系,该策略可以发现被低估的机会,也可避开被高估的局面。
比较相对强弱,识别被低估机会
设置回调线,避免继续跟涨杀跌
操作规则简单清晰
需要选择合适的比较基准市场
超买超卖区域需要优化判断
仅做多或做空无法获全市场机会
比较相对强度策略通过比对两个市场的强弱来发现套利机会。但其参数设定和止损策略需要审慎评估。
/*backtest
start: 2022-09-07 00:00:00
end: 2023-09-13 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 10/03/2017
// Comparative Relative Strength Strategy for ES
//
// You can change long to short in the Input Settings
// Please, use it only for learning or paper trading. Do not for real trading.
////////////////////////////////////////////////////////////
strategy("Comparative Relative Strength Strategy", shorttitle="CRS")
a = syminfo.tickerid
b = input("BTC_USDT:swap")
len = input(10)
BuyBand = input(0.9988, step = 0.0001)
SellBand = input(0.9960, step = 0.0001)
CloseBand = input(0.9975, step = 0.0001)
reverse = input(false, title="Trade reverse")
hline(CloseBand, color=blue, linestyle=hline.style_dashed)
hline(SellBand, color=red, linestyle=hline.style_solid)
hline(BuyBand, color=green, linestyle=hline.style_solid)
as = security(a, timeframe.period, close)
bs = security(b, timeframe.period, close)
nRes = sma(as/bs, len)
pos = iff(nRes > BuyBand, 1,
iff(nRes < SellBand, -1,
iff(pos[1] == 1 and nRes < CloseBand, 0,
iff(pos[1] == -1 and nRes > CloseBand, 0, 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)
if (possig == 0)
strategy.close("Long", when = possig == 0)
strategy.close("Short", when = possig == 0)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(as/bs, title="CRS", color=gray)
plot(nRes, color=navy)