该策略利用累积RSI指标识别趋势,在RSI指标累积值突破关键阈值时进行买入和卖出操作。该策略可以有效过滤市场noise,锁定较长线的趋势交易机会。
该策略主要基于累积RSI指标进行交易决策。累积RSI指标是RSI指标的累积值,通过设置参数cumlen,可以将RSI指标在cumlen天内的数值累加,得到累积RSI指标。该指标可以过滤掉短期市场noise。
当累积RSI指标上穿过bolinger带上轨,就进行买入开仓操作;当累积RSI指标下穿过bolinger带下轨,就进行卖出平仓操作。bolinger带上下轨通过多年历史数据计算得出,是动态变化的参考价位。
另外,策略还增加了趋势过滤器选项。只有当价格高于100天移动平均线时,也就是处于趋势上升通道时,才会进行买入开仓。这个过滤器可以避免价格震荡时的错误交易。
该累积RSI突破策略整体运作流畅、逻辑清晰,通过累积RSI指标有效滤波、增加趋势判断,对中长线趋势把握准确,历史回测表现优异。但仍有可优化空间,可以从调整参数设置、增加判断指标、丰富平仓条件等方面入手,打造更健壮和全面的趋势策略。该策略思路新颖,值得进一步探索和应用。
/*backtest start: 2023-09-26 00:00:00 end: 2023-10-26 00:00:00 period: 1h basePeriod: 15m 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/ // @version=5 // Author = TradeAutomation strategy(title="Cumulative RSI Strategy", shorttitle="CRSI Strategy", process_orders_on_close=true, overlay=true, commission_type=strategy.commission.cash_per_contract, commission_value=.0035, slippage = 1, margin_long = 75, initial_capital = 25000, default_qty_type=strategy.percent_of_equity, default_qty_value=110) // Cumulative RSI Indicator Calculations // rlen = input.int(title="RSI Length", defval=3, minval=1) cumlen = input(3, "RSI Cumulation Length") rsi = ta.rsi(close, rlen) cumRSI = math.sum(rsi, cumlen) ob = (100*cumlen*input(94, "Oversold Level")*.01) os = (100*cumlen*input(20, "Overbought Level")*.01) // Operational Function // TrendFilterInput = input(false, "Only Trade When Price is Above EMA?") ema = ta.ema(close, input(100, "EMA Length")) TrendisLong = (close>ema) plot(ema) // Backtest Timeframe Inputs // startDate = input.int(title="Start Date", defval=1, minval=1, maxval=31) startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12) startYear = input.int(title="Start Year", defval=2010, minval=1950, maxval=2100) endDate = input.int(title="End Date", defval=1, minval=1, maxval=31) endMonth = input.int(title="End Month", defval=1, minval=1, maxval=12) endYear = input.int(title="End Year", defval=2099, minval=1950, maxval=2100) InDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0)) // Buy and Sell Functions // if (InDateRange and TrendFilterInput==true) strategy.entry("Long", strategy.long, when = ta.crossover(cumRSI, os) and TrendisLong, comment="Buy", alert_message="buy") strategy.close("Long", when = ta.crossover(cumRSI, ob) , comment="Sell", alert_message="Sell") if (InDateRange and TrendFilterInput==false) strategy.entry("Long", strategy.long, when = ta.crossover(cumRSI, os), comment="Buy", alert_message="buy") strategy.close("Long", when = ta.crossover(cumRSI, ob), comment="Sell", alert_message="sell") if (not InDateRange) strategy.close_all()