本策略通过计算相对强度指数(RSI)识别市场潜在的买入和卖出机会。它利用RSI指标判断价格可能从趋势向反趋势转变的点,以捕捉反转机会。当RSI从超买或超卖区域反转时产生交易信号。
该策略的核心指标是RSI,它显示了一段时间内收盘价格上涨的天数相对于价格下跌的天数的比率,用来判断资产是否被高估或低估。RSI以0到100之间的数值展示,数值高表示市场强势向上,数值低表示市场强势向下。
策略首先设置RSI的参数,包括周期长度(默认14)、超卖区域的阈值(默认为70和30)。然后根据收盘价格计算RSI值。当RSI上穿超卖区域的阈值时,产生买入信号;当RSI下穿超卖区域的阈值时,产生卖出信号。
策略同时绘制RSI指标曲线,以及阈值线。在价格图上用文字和图形标记买入卖出信号。另外,策略计算并绘制自上一个交易信号以来价格变化的百分比,让交易者直观看到信号后的价格走势。
本策略通过相对强度指数的反转交易原理设计而成,主要判断资产短期内是否出现明显的超买超卖现象,以捕捉随后的反转机会。计算百分比变化并配合可视化的交易提示,可以辅助交易决策。RSI参数可自定义设定,用户可以根据个人偏好进行调整。结合其他指标提高信号可靠性,以及适当优化可以减少假信号,是本策略的发展方向。
/*backtest
start: 2023-01-19 00:00:00
end: 2024-01-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Improved RSI Strategy", overlay=true)
// Define RSI parameters
rsiLength = input(14, title="RSI Length")
rsiOversold = input(30, title="Oversold Threshold")
rsiOverbought = input(70, title="Overbought Threshold")
// Calculate RSI
rsiValue = ta.rsi(close, rsiLength)
// Define entry conditions
longCondition = ta.crossover(rsiValue, rsiOversold)
shortCondition = ta.crossunder(rsiValue, rsiOverbought)
// Plot RSI and thresholds
plot(rsiValue, title="RSI", color=color.blue)
hline(rsiOversold, title="Oversold Threshold", color=color.red)
hline(rsiOverbought, title="Overbought Threshold", color=color.green)
// Calculate percentage change since last signal
var float percentageChange = na
lastCloseValue = ta.valuewhen(longCondition or shortCondition, close, 1)
if longCondition or shortCondition
percentageChange := (close - lastCloseValue) / lastCloseValue * 100
plot(percentageChange, color=color.blue, style=plot.style_histogram, linewidth=1, title="% Change since last signal")
// Execute strategy
if longCondition
strategy.entry("RSI Long", strategy.long)
if shortCondition
strategy.entry("RSI Short", strategy.short)
// Plot shapes and text for buy/sell signals
plotshape(series=longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")