本策略利用RSI指标识别股票超买超卖的市场状态,在超买区形成死叉做空,在超卖区形成金叉做多,属于基于指标的反转交易策略。该策略结合趋势跟踪止损、固定止盈止损,可以有效控制交易风险。
该策略的交易信号是基于RSI指标的金叉死叉产生的。RSI指标一般以30作为超卖线,70作为超买线。当RSI指标上穿超卖线时,产生买入信号;当RSI指标下穿超买线时,产生卖出信号。根据这个原理,策略判断超买超卖区域的形成,并相应的产生做多做空信号。
在进场后,策略采用百分比追踪止损方式,通过持续刷新最高价或最低价,并离开一定百分比作为止损位。同时也采用了固定的止盈止损距离,当达到目标利润或最大亏损时止损。这种组合可以很好地控制交易风险。
该策略具有以下优势:
利用RSI指标判断超买超卖区域,这是比较成熟的交易技巧,可以较准确地捕捉到市场反转点。
采用金叉死叉方式,可以过滤掉部分噪音交易信号,使交易更加可靠。
结合趋势跟踪止损,可以最大限度锁定盈利,同时也可以快速止损,降低单笔损失。
固定止盈止损距离,也可以有效控制单笔交易风险。
整体来说,该策略规则清晰,易于理解和实现,适合量化交易初学者学习。
该策略也存在以下风险:
RSI指标容易产生错误信号,技术形态破裂的概率较大,可能导致止损被触发。
固定止盈止损距离,不能根据市场波动程度做调整,可能会过早止盈或扩大止损。
百分比跟踪止损只跟踪价格最高点或最低点,可能会过于激进,使盈利不足。
回测数据拟合风险。该策略的参数可能是针对历史数据进行优化的,在实际应用中表现可能会逊色。
交易频率可能过高,增加交易费用和滑点风险。
该策略可以从以下几个方向进行优化:
优化RSI参数,寻找最佳指标参数组合,提高信号质量。
增加其他指标过滤,形成多指标共振,提高信号准确率。
采用自适应止盈止损机制,根据市场波动自动调整止损止盈位。
增加交易频率控制模块,降低交易次数,减少交易费用。
增加资金管理模块,控制单笔交易规模,降低单笔损失。
在更长时间周期内进行回测,检验参数稳定性。
本策略整体是一个典型的反转交易策略,利用RSI指标判定超买超卖区域,采取金叉死叉方式产生交易信号。并使用趋势跟踪止损和固定止盈止损来控制风险。该策略逻辑清晰,容易实现,适合量化交易初学者学习和实践。但也存在一定的假信号风险和参数优化风险,需要继续对策略进行验证和优化,才能实际投入使用。
/*backtest start: 2023-12-01 00:00:00 end: 2023-12-31 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // LOVE JOY PEACE PATIENCE KINDNESS GOODNESS FAITHFULNESS GENTLENESS SELF-CONTROL // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // Author: © JoshuaMcGowan // Taken from https://www.tradingview.com/script/GbZGYi6l-Adding-some-essential-components-to-a-prebuilt-RSI-strategy/ // Just updated to compile in version 4. //@version=4 strategy("Adding some essential components to a prebuilt RSI strategy", overlay=true) /////////////// Component Code Start /////////////// testStartYear = input(2011, "Backtest Start Year") testStartMonth = input(8, "Backtest Start Month") testStartDay = input(1, "Backtest Start Day") testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0) testStopYear = input(2100, "Backtest Stop Year") testStopMonth = input(9, "Backtest Stop Month") testStopDay = input(29, "Backtest Stop Day") // testStopDay = testStartDay + 1 testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0) // A switch to control background coloring of the test period testPeriodBackground = input(title="Color Background?", type=input.bool, defval=true) testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na bgcolor(testPeriodBackgroundColor, transp=97) testPeriod() => true /////////////// Component Code Stop /////////////// // Replace RSI Component, Long/Short, and Long Signal/Short Signal conditions with your trade setup components. ///////////// RSI component ///////////// length = input( 14 ) overSold = input( 30 ) overBought = input( 70 ) price = close vrsi = rsi(price, length) notna = not na(vrsi) /////////////// STRATEGY /////////////// ts = input(99999, "Trailing Stop") / 100 tp = input(99999, "Take Profit") / 100 sl = input(99999, "Stop Loss") / 100 // Update this with your setup. long = notna and crossover(vrsi, overSold) short = notna and crossunder(vrsi, overBought) last_long = 0 last_short = 0 last_long := long ? time : nz(last_long[1]) last_short := short ? time : nz(last_short[1]) // Update this to reflect your setup. long_signal = crossover(last_long, last_short) short_signal = crossover(last_short, last_long) float last_open_long_signal = 0 float last_open_short_signal = 0 last_open_long_signal := long_signal ? open : nz(last_open_long_signal[1]) last_open_short_signal := short_signal ? open : nz(last_open_short_signal[1]) last_long_signal = 0 last_short_signal = 0 last_long_signal := long_signal ? time : nz(last_long_signal[1]) last_short_signal := short_signal ? time : nz(last_short_signal[1]) in_long_signal = last_long_signal > last_short_signal in_short_signal = last_short_signal > last_long_signal float last_high = 0 float last_low = 0 last_high := not in_long_signal ? na : in_long_signal and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1]) last_low := not in_short_signal ? na : in_short_signal and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1]) long_ts = not na(last_high) and high <= (last_high - ts) //and high >= last_open_long_signal short_ts = not na(last_low) and low >= (last_low + ts) //and low <= last_open_short_signal long_tp = high >= (last_open_long_signal + tp) short_tp = low <= (last_open_short_signal - tp) long_sl = low <= (last_open_long_signal - sl) short_sl = high >= (last_open_short_signal + sl) leverage = input(200, "Leverage") long_call = last_open_long_signal - (0.8 + 0.2 * (1/leverage)) / leverage * last_open_long_signal short_call = last_open_short_signal + (0.78 + 0.2 * (1/leverage)) / leverage * last_open_short_signal long_call_signal = low <= long_call short_call_signal = high >= short_call if testPeriod() strategy.entry("Long", strategy.long, when=long_signal) strategy.entry("Short", strategy.short, when=short_signal) // plot(long_call, color=color.red) // plot(short_call, color=color.green) strategy.close("Long", when=long_call_signal) strategy.close("Short", when=short_call_signal) strategy.close("Long", when=long_tp) strategy.close("Short", when=short_tp) strategy.close("Long", when=long_sl) strategy.close("Short", when=short_sl) strategy.close("Long", when=long_ts) strategy.close("Short", when=short_ts)