
A estratégia utiliza a identificação de tendências no indicador RSI acumulado para comprar e vender quando o indicador RSI acumulado ultrapassa o limite crítico. A estratégia pode filtrar efetivamente o ruído do mercado e bloquear as oportunidades de negociação de tendências mais longas.
A estratégia baseia-se principalmente em um indicador RSI cumulativo para tomar decisões de negociação. O indicador RSI cumulativo é o valor acumulado do indicador RSI. Ao definir o parâmetro cumlen, os valores do indicador RSI podem ser acumulados em dias cumulativos para obter o indicador RSI cumulativo.
Quando o indicador RSI acumulado atravessa a banda de Bollinger, a operação de compra e abertura de posição é realizada; Quando o indicador RSI acumulado atravessa a banda de Bollinger, a operação de venda de posição é realizada. A banda de Bollinger é calculada por vários anos de dados históricos e é o preço de referência para mudanças dinâmicas.
Além disso, a estratégia também adicionou a opção de filtro de tendência. A compra e abertura de posições são feitas apenas quando o preço está acima da média móvel de 100 dias, ou seja, no canal ascendente da tendência. Este filtro evita transações erradas quando os preços são agitados.
A estratégia de ruptura do RSI acumulado funciona de forma fluida e lógica, aumenta o julgamento de tendências com o uso de indicadores RSI acumulados, é preciso para entender as tendências de linha média e longa e tem um excelente desempenho de retrospectiva histórica. No entanto, ainda há espaço para otimização, que pode começar a partir da configuração de parâmetros de ajuste, aumento de indicadores de julgamento e enriquecimento de condições de equilíbrio.
/*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()