
Esta estratégia é conhecida como a estratégia de tracking de tendência de stop loss baseada no indicador RSI. A estratégia usa o indicador RSI para determinar a sobrevenda e a sobrevenda, em combinação com o indicador MA rápido e lento para determinar a direção da tendência e definir as condições de entrada.
A estratégia é baseada no RSI e no MA para determinar o momento de entrada. O RSI é definido como um indicador de 2 ciclos para determinar a sobrevenda e a sobrevenda. O MA é definido como um indicador de 50 ciclos e 200 ciclos para determinar a direção da tendência.
Multi-headed entry: fazer mais quando o MA rápido está acima do MA lento e o RSI está abaixo da área de oversold (default 10%);
Entrada de entrada vazia: a MA rápida atravessa a MA lenta, e o preço é menor que a MA lenta, enquanto o RSI está acima da área de sobrecompra (default 90%) e está vazia.
Além disso, a estratégia também define um filtro de taxa de flutuação opcional. O filtro calcula o diferencial de inclinação do MA de forma lenta, abrindo posições apenas quando o diferencial ultrapassa o limite definido. O objetivo é evitar a abertura de posições em períodos de volatilidade sem direção clara.
Na saída, a estratégia usa o método de rastreamento de percentual de parada. De acordo com a porcentagem de parada de entrada, o preço de parada é calculado em combinação com cada diferença de preço de salto, permitindo a parada de ajuste dinâmico.
A estratégia tem as seguintes vantagens:
A estratégia também apresenta riscos, como:
Os riscos acima mencionados podem ser otimizados de acordo com:
A estratégia pode ser melhorada em:
Esta estratégia é uma estratégia de acompanhamento de tendência mais estável. Combina o julgamento de dois indicadores RSI e MA, garantindo certa estabilidade, mas também pode capturar oportunidades de reversão de tendência mais claras. Ao mesmo tempo, a configuração do filtro de taxa de flutuação evita parte do risco, e o método de parada percentual também pode controlar efetivamente a perda individual.
/*backtest
start: 2023-11-11 00:00:00
end: 2023-12-11 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// Scalping strategy
// © Lukescream and Ninorigo
// (original version by Lukescream - lastest versions by Ninorigo) - v1.3
//
//@version=4
strategy(title="Scalping using RSI 2 indicator", shorttitle="RSI 2 Strategy", overlay=true, pyramiding=0, process_orders_on_close=false)
var bool ConditionEntryL = false
var bool ConditionEntryS = false
//***********
// Costants
//***********
def_start_date = timestamp("01 Jan 2021 07:30 +0000")
def_end_date = timestamp("01 Dec 2024 07:30 +0000")
def_rsi_length = 2
def_overbought_value = 90
def_oversold_value = 10
def_slow_ma_length = 200
def_fast_ma_length = 50
def_ma_choice = "EMA"
def_tick = 0.5
def_filter = true
def_trailing_stop = 1
//***********
// Change the optional parameters
//***********
start_time = input(title="Start date", defval=def_start_date, type=input.time)
end_time = input(title="End date", defval=def_end_date, type=input.time)
// RSI
src = input(title="Source", defval=close, type=input.source)
rsi_length = input(title="RSI Length", defval=def_rsi_length, minval=1, type=input.integer)
overbought_threshold = input(title="Overbought threshold", defval=def_overbought_value, type=input.float)
oversold_threshold = input(title="Oversold threshold", defval=def_oversold_value, type=input.float)
// Moving average
slow_ma_length = input(title="Slow MA length", defval=def_slow_ma_length, type=input.integer)
fast_ma_length = input(title="Fast MA length", defval=def_fast_ma_length, type=input.integer)
ma_choice = input(title="MA choice", defval="EMA", options=["SMA", "EMA"])
// Input ticker
tick = input(title="Ticker size", defval=def_tick, type=input.float)
filter = input(title="Trend Filter", defval=def_filter, type=input.bool)
// Trailing stop (%)
ts_rate = input(title="Trailing Stop %", defval=def_trailing_stop, type=input.float)
//***********
// RSI
//***********
// Calculate RSI
up = rma(max(change(src), 0), rsi_length)
down = rma(-min(change(src), 0), rsi_length)
rsi = (down == 0 ? 100 : (up == 0 ? 0 : 100-100/(1+up/down)))
//***********
// Moving averages
//***********
slow_ma = (ma_choice == "SMA" ? sma(close, slow_ma_length) : ema(close, slow_ma_length))
fast_ma = (ma_choice == "SMA" ? sma(close, fast_ma_length) : ema(close, fast_ma_length))
// Show the moving averages
plot(slow_ma, color=color.white, title="Slow MA")
plot(fast_ma, color=color.yellow, title="Fast MA")
//***********
// Strategy
//***********
if true
// Determine the entry conditions (only market entry and market exit conditions)
// Long position
ConditionEntryL := (filter == true ? (fast_ma > slow_ma and close > slow_ma and rsi < oversold_threshold) : (fast_ma > slow_ma and rsi < oversold_threshold))
// Short position
ConditionEntryS := (filter == true ? (fast_ma < slow_ma and close < slow_ma and rsi > overbought_threshold) : (fast_ma < slow_ma and rsi > overbought_threshold))
// Calculate the trailing stop
ts_calc = close * (1/tick) * ts_rate * 0.01
// Submit the entry orders and the exit orders
// Long position
if ConditionEntryL
strategy.entry("RSI Long", strategy.long)
// Exit from a long position
strategy.exit("Exit Long", "RSI Long", trail_points=0, trail_offset=ts_calc)
// Short position
if ConditionEntryS
strategy.entry("RSI Short", strategy.short)
// Exit from a short position
strategy.exit("Exit Short", "RSI Short", trail_points=0, trail_offset=ts_calc)
// Highlights long conditions
bgcolor (ConditionEntryL ? color.navy : na, transp=60, offset=1, editable=true, title="Long position band")
// Highlights short conditions
bgcolor (ConditionEntryS ? color.olive : na, transp=60, offset=1, editable=true, title="Short position band")