本策略是一个结合RSI(相对强弱指标)和趋势均线的双重过滤交易系统。该策略通过RSI的超买超卖信号与长期趋势均线相结合,在日线级别上进行交易。策略的核心是在传统RSI交易信号的基础上增加趋势过滤器,以提高交易的准确性和可靠性。
策略主要基于以下核心组件: 1. RSI指标用于识别超买超卖区域,默认参数为14周期 2. 超买水平设置为70,超卖水平设置为30 3. 200周期简单移动平均线作为趋势过滤器 4. 买入条件:RSI从超卖区域向上突破且价格位于均线之上 5. 卖出条件:RSI从超买区域向下突破且价格位于均线之下 策略在每个信号出现时自动执行交易,并可配置提醒功能。
该策略通过结合RSI和趋势均线,构建了一个稳健的交易系统。策略设计合理,操作规则清晰,具有良好的实用性。通过合理的风险管理和持续优化,该策略有望在实际交易中取得稳定收益。
/*backtest
start: 2025-02-13 00:00:00
end: 2025-02-20 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"DOGE_USDT"}]
*/
//@version=5
strategy("Leading Indicator Strategy – Daily Signals", overlay=true,
pyramiding=1, initial_capital=100000,
default_qty_type=strategy.percent_of_equity, default_qty_value=100)
/// **Inputs for Customization**
rsiLength = input.int(14, minval=1, title="RSI Period")
oversold = input.float(30.0, minval=1, maxval=50, title="Oversold Level")
overbought = input.float(70.0, minval=50, maxval=100, title="Overbought Level")
maLength = input.int(200, minval=1, title="Trend MA Period")
useTrendFilter = input.bool(true, title="Use Trend Filter (MA)",
tooltip="Require price above MA for buys and below MA for sells")
/// **Indicator Calculations**
rsiValue = ta.rsi(close, rsiLength) // RSI calculation
trendMA = ta.sma(close, maLength) // Long-term moving average
/// **Signal Conditions** (RSI crosses with optional trend filter)
buySignal = ta.crossover(rsiValue, oversold) // RSI crosses above oversold level
sellSignal = ta.crossunder(rsiValue, overbought) // RSI crosses below overbought level
bullCond = buySignal and (not useTrendFilter or close > trendMA) // final Buy condition
bearCond = sellSignal and (not useTrendFilter or close < trendMA) // final Sell condition
/// **Trade Execution** (entries and exits with alerts)
if bullCond
strategy.close("Short", alert_message="Buy Signal – Closing Short") // close short position if open
strategy.entry("Long", strategy.long, alert_message="Buy Signal – Enter Long") // go long
if bearCond
strategy.close("Long", alert_message="Sell Signal – Closing Long") // close long position if open
strategy.entry("Short", strategy.short, alert_message="Sell Signal – Enter Short") // go short
/// **Plotting** (MA and signal markers for clarity)
plot(trendMA, color=color.orange, linewidth=2, title="Trend MA")
plotshape(bullCond, title="Buy Signal", style=shape.labelup, location=location.belowbar,
color=color.green, text="BUY", textcolor=color.white)
plotshape(bearCond, title="Sell Signal", style=shape.labeldown, location=location.abovebar,
color=color.red, text="SELL", textcolor=color.white)
// (Optional) Plot RSI in a separate pane for reference:
// plot(rsiValue, title="RSI", color=color.blue)
// hline(oversold, title="Oversold", color=color.gray, linestyle=hline.style_dotted)
// hline(overbought, title="Overbought", color=color.gray, linestyle=hline.style_dotted)