Stochastic RSI交易策略
该策略根据Stochastic RSI指标的交叉信号进行交易。
具体交易规则如下:
当Stochastic RSI上穿30时做多
当Stochastic RSI下穿70时做空
该策略还包括两个附加入场条件:
做多时,9周期SMA必须高于21周期SMA
做空时,9周期SMA必须低于21周期SMA
做多仅在价格低于VWAP时发出信号
做空仅在价格高于VWAP时发出信号
该策略采用止损和止盈进行风险管理:
无论做多做空,止损设置为20ticks
无论做多做空,止盈设置为25ticks
该策略的优势在于利用Stochastic RSI识别超买超卖区域,并加入SMA和VWAP进行过滤,可有效减少错误信号。但该策略较适合趋势行情,在盘整行情中容易被套住。
/*backtest start: 2023-09-03 00:00:00 end: 2023-09-10 00:00:00 period: 1m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © thedoggwalker //@version=4 strategy("Stochastic RSI Strategy", overlay=true) // Stochastic RSI length = input(14, title="Length") src = input(close, title="Source") smoothK = input(3, title="K") smoothD = input(3, title="D") rsiValue = rsi(src, length) highestRSI = highest(rsiValue, length) lowestRSI = lowest(rsiValue, length) k = (rsiValue - lowestRSI) / (highestRSI - lowestRSI) * 100 d = sma(k, smoothD) // Moving averages maShort = sma(close, 9) maLong = sma(close, 21) // Spread between moving averages spread = maShort - maLong // VWAP vwapValue = vwap(hlc3) // Entry conditions longCondition = crossover(k, 30) and spread > 0 and close < vwapValue shortCondition = crossunder(k, 70) and spread < 0 and close > vwapValue // Entry orders if (longCondition) strategy.entry("Long", strategy.long) if (shortCondition) strategy.entry("Short", strategy.short) // Exit orders // longStopLoss = close - 20 * syminfo.mintick // longTakeProfit = close + 25 * syminfo.mintick // strategy.exit("Exit Long", "Long", stop=longStopLoss, limit=longTakeProfit) // shortStopLoss = close + 20 * syminfo.mintick // shortTakeProfit = close - 25 * syminfo.mintick // strategy.exit("Exit Short", "Short", stop=shortStopLoss, limit=shortTakeProfit)