Scalping 전략은 RSI 지표에 기반하여 Trailing Stop Loss

저자:차오장, 날짜: 2023-12-12 15:46:49
태그:

img

전반적인 설명

이 전략은 트레일링 스톱 러스 (Trailing Stop Loss) 로 RSI 지표에 기반한 스칼핑 전략 (Scalping Strategy) 이라고 불린다. 그것은 과잉 구매 및 과잉 판매 조건을 결정하기 위해 RSI 지표를 활용하고, 트렌드 방향을 결정하기 위해 빠르고 느린 이동 평균 (MA) 과 결합하고, 진입 조건을 설정한다. 또한 지점을 종료하기 위해 퍼센트 트레일링 스톱 러스 메커니즘을 사용합니다.

전략 논리

이 전략의 진입 신호는 주로 RSI 지표와 MA 크로스오버에 의해 결정된다. RSI 매개 변수는 2 기간으로 설정되어 반전 기회를 위해 과잉 구매 및 과잉 판매 상황을 신속하게 파악한다. 빠른 MA와 느린 MA는 respectively 50 및 200 기간으로 설정되어 트렌드 방향을 식별한다. 구체적으로 진입 논리는:

롱 엔트리: 빠른 MA는 느린 MA를 넘고, 가격은 느린 MA를 넘고, RSI는 과잉 판매 수준을 넘는다 (디폴트 10%); 단기 엔트리: 빠른 MA는 느린 MA를 넘고, 가격은 느린 MA를 넘고, RSI는 과잉 매수 수준 (디폴트 90%) 을 넘습니다.

또한 전략에는 선택적 인 변동성 필터가 있습니다. 빠른 MA와 느린 MA의 기울기 사이의 차이를 계산합니다. 차이가 한 임계치를 초과 할 때만 지점이 열립니다. 목적은 시장 변동 중에 명확한 방향이 없을 때 지점을 열지 않도록하는 것입니다.

출구 측면에서는, 전략은 백분율 트레일링 스톱 로스를 사용합니다. 입력 백분율에 기초하여, 스톱 로스를 동적으로 조정하기 위해 틱 크기와 결합한 스톱 로스 가격을 계산합니다.

이점 분석

이 전략의 주요 장점은 다음과 같습니다.

  1. 2개의 기간으로 설정된 RSI는 회전 기회를 얻기 위해 과반 구매 및 과반 판매 상황을 빠르게 파악할 수 있습니다.
  2. 빠르고 느린 MAs는 트렌드 방향과 전환점을 효과적으로 식별 할 수 있습니다.
  3. RSI와 MA의 이중 지표 조합은 잘못된 파장을 피합니다.
  4. 변동성 필터는 변동 중에 명확한 방향이 없을 때 포지션을 개설하는 것을 피합니다.
  5. 지연 스톱 손실의 비율은 시장 변동성에 따라 스톱 손실 수준을 조정하여 위험을 효과적으로 제어 할 수 있습니다.

위험 분석

이 전략에는 몇 가지 위험도 있습니다.

  1. RSI와 MA 지표는 약간의 지연 효과를 가지고 있으며, 몇 가지 반전 기회를 놓칠 수 있습니다.
  2. 금전 손실의 비율은 저용량 감소에서 유발될 가능성이 높습니다.
  3. 중요한 오버나이트 및 시장 이전 가격 변동은 효과적으로 처리되지 않습니다.

위험에 대한 최적화 방향은 다음과 같습니다.

  1. RSI 매개 변수를 1 기간으로 조정하여 지연 효과를 줄이십시오.
  2. 기호 특성에 따라 MA 기간을 최적화합니다.
  3. 스톱 로스 비율을 스톱 로스 및 변동 허용 사이의 균형을 맞추기 위해 조정합니다.

최적화 방향

이 전략의 최적화 방향은 다음과 같습니다.

  1. 부피와 같은 다른 지표 판단을 추가하여 잘못된 브레이크 신호를 피합니다.
  2. 결정에 도움이 되는 기계 학습 모델 예측을 추가합니다.
  3. 피라미드 시기를 최적화하고 위치 크기를 조정하여 수익을 더 향상시킵니다.
  4. 오버나이트 및 시장 전 가격 변동에 대한 필터를 설정합니다. 변동에 따라 다음 거래일에 참여할지 여부를 결정합니다.

결론

일반적으로, 이것은 전략에 따른 비교적 안정적인 트렌드이다. 이중 RSI와 MA 지표를 결합함으로써, 더 명확한 트렌드 역전 기회를 포착하는 동시에 일정 안정성을 보장한다. 변동성 필터는 일부 위험을 피하고, 비율 스톱 손실은 또한 단일 거래 손실을 효과적으로 제어한다. 이 전략은 멀티 기호 일반 전략으로 사용될 수 있으며, 또한 더 나은 결과를 달성하기 위해 특정 기호에 대한 매개 변수 및 모델에 최적화 될 수 있다.


/*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")


더 많은