该策略旨在实现一种基于随机指数平滑移动平均线(RSI)和指数移动平均线(EMA)指标的自主式买入并持有币种的Scalper交易策略。它适用于5分钟K线,针对BTC进行了优化。策略的目标是在横盘或不大幅下跌时尽可能多持有币种。
该策略使用RSI指标判断是否处于超买超卖区域,并结合随机RSI指标的K值和D值关系来发出买入和卖出信号。
当随机RSI的K线低于20时视为超卖,并在K线大于D线时产生买入信号。之后,会根据三个条件判断是否卖出:1)价格上涨超过1%后出现EMA翻转;2)随机RSI指标K线低于D线时;3)止损价格达到入场价的98.5%时。
此外,当短期EMA在上涨后发生向下翻转也会判断为卖出信号。
该策略整合了随机RSI和EMA等多个指标的优势,采用较为稳健的方法判断买入和卖出时机。通过参数优化及风险管理可以进一步提高策略收益率和稳定性。总体来说,该策略逻辑合理,值得在实盘中进行验证和优化。
/*backtest start: 2023-09-30 00:00:00 end: 2023-10-30 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy(title="Stochastic RSI W Auto Buy Scalper Scirpt III ", shorttitle="Stoch RSI_III", format=format.price, precision=2) smoothK = input.int(3, "K", minval=1) smoothD = input.int(3, "D", minval=1) lengthRSI = input.int(14, "RSI Length", minval=1) lengthStoch = input.int(14, "Stochastic Length", minval=1) src = input(close, title="RSI Source") rsi1 = ta.rsi(src, lengthRSI) k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK) d = ta.sma(k, smoothD) plot(k, "K", color=#2962FF) plot(d, "D", color=#FF6D00) h0 = hline(80, "Upper Band", color=#787B86) hline(50, "Middle Band", color=color.new(#787B86, 50)) h1 = hline(20, "Lower Band", color=#787B86) longStopLoss = strategy.opentrades.entry_price(0)* (.985) stochDropping = ta.falling(k,2) shortSma = ta.sma(hlc3,12) shorterSma = ta.sma(hlc3,3) plot(shortSma[3]) shortSmaFlip = (ta.change(shortSma,3)>0) and ta.falling(hlc3,1) shorterSmaFlip = (ta.change(shorterSma,2)>0) and ta.falling(hlc3,1) messageSellText ='"type": "sell", "symbol": "BTCUSD", "marketPosition": "{{strategy.market_position}}"' messageBuyText ='"type": "buy", "symbol": "BTCUSD", "marketPosition": {{strategy.market_position}}"' fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background") strategy.entry("Tech", strategy.long, when=(strategy.position_size <= 0 and k<17 and k>d),alert_message=messageBuyText) //original: strategy.close("TL", when=(strategy.position_size >= 0 and (k>90 and k<d))) takeProfit = hlc3 > strategy.opentrades.entry_price(0)*1.01 //longStopLoss = strategy.opentrades.entry_price(0)* (.995) strategy.close("Tech", when=(strategy.position_size >= 0 and (k>90 and k<d and stochDropping)) or close<longStopLoss, comment="rsi or Stop sell",alert_message=messageSellText) //strategy.close("Tech", when=(strategy.position_size >= 0 and close<longStopLoss), comment="stopLoss sell",alert_message=messageSellText) strategy.close("Tech", when=(shortSmaFlip and k>20 and takeProfit),comment="Sma after profit",alert_message=messageSellText)