성장 생산자 - 전략에 따른 두 가지 RSI 트렌드

저자:차오장, 날짜: 2023년 11월 15일 17:31:24
태그:

img

전반적인 설명

이 전략은 트렌드 방향을 결정하기 위해 이동 평균 시스템과 결합하여 긴 및 짧은 거래 신호를위한 두 가지 RSI 지표를 사용하는 이중 RSI 트렌드 추적 전략입니다. 이 전략은 이중 RSI 알고리즘 전략의 범주에 속합니다. 이 전략은 먼저 RSI 지표를 사용하여 상승 및 하락 신호를 결정하고, 이후 이동 평균을 사용하여 긴 또는 짧은 거래의 트렌드 방향을 확인합니다. 이것은 전형적인 트렌드 추적 전략입니다.

원칙 분석

이중 RSI 전략은 주로 거래 신호를 위해 서로 다른 시간 프레임으로 두 개의 RSI 지표를 사용합니다. 먼저 두 개의 RSI 매개 변수를 설정합니다. 하나는 더 긴 기간 RSI를 주요 지표로, 다른 하나는 더 짧은 기간 RSI를 보조 필터로 사용합니다. 더 긴 기간 RSI가 과판 라인을 넘어서면 긴 신호가 생성됩니다. 짧은 기간 RSI가 과반 라인을 넘어서면 짧은 신호가 생성됩니다. 이것은 거래 기회를위한 이중 RSI 크로스오버 시스템을 형성합니다.

잘못된 신호를 필터하기 위해 전략은 또한 트렌드 검출을 위해 SMA와 EMA 이동 평균을 포함합니다. 단기 SMA가 긴 기간 EMA를 넘을 때만 긴 RSI 신호가 고려됩니다. 단기 SMA가 긴 EMA를 넘을 때만 짧은 RSI 신호가 고려됩니다. 이것은 RSI 신호가 트렌드 방향과 조화를 이루고 트렌드에 반대하는 거래를 피하도록합니다.

또한, 전략은 또한 중지 손실 및 이익 취득 논리를 설정합니다. 포지션을 열면, 다른 크기의 두 가지 이익 취득 주문이 위치하고 있으며, 중지 손실 수준이 있습니다.

이점 분석

이중 RSI 알고리즘 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 듀얼 타임프레임 RSI 인디케이터는 상승 및 하락 신호를 더 정확하게 결정할 수 있습니다. 장기 및 단기 RSI의 조합은 일부 잘못된 신호를 필터하고 신호 품질을 향상시킬 수 있습니다.

  2. 이동 평균 시스템은 주요 트렌드 방향을 결정하는 데 도움이 되고, 트렌드에 반대되는 거래를 피하고, 대부분의 노이즈 트레이드를 필터링하여 승률을 향상시킬 수 있습니다.

  3. 유연한 스톱 로스 및 수익 취득 메커니즘은 다른 취득 설정으로 더 높은 수익을 허용하고 스톱 로스를 통해 위험을 관리합니다.

  4. 거래 논리는 간단하고 명확하고 이해하기 쉽고 최적화 할 수 있습니다. 알고리즘 트레이더가 배우기에 적합합니다.

위험 분석

이 두 가지 RSI 전략의 장점에도 불구하고 다음과 같은 위험이 있습니다.

  1. RSI 자체는 시장 범위 및 트렌드 역전에서 제한된 효과를 가지고 있습니다. 이 전략은 이러한 시장 조건에서 성과를 떨어뜨릴 수 있습니다.

  2. 이동 평균은 작은 소음을 필터하지만 중간 사이클 트렌드 변화를 감지하는 데 덜 효과적이며 트렌드 전환점을 놓칠 수 있습니다.

  3. 부적절한 스톱 로스 및 수익 취득 설정은 스톱이 너무 넓거나 수익이 너무 작아 전략 성과를 악화시킬 수 있습니다.

  4. 큰 긴 / 짧은 포지션은 손실을 증가시킬 수 있습니다. 포지션 크기를 제어해야합니다.

이러한 위험을 해결하기 위해 매개 변수를 조정하고, 더 고급 트렌드 및 역전 지표를 도입하고, 스톱 및 이익 논리를 최적화하고, 위험을 최소화하기 위해 포지션 사이즈를 제어 할 수 있습니다.

최적화 방향

이중 RSI 전략은 다음 측면에서 더 이상 최적화 될 수 있습니다.

  1. 다양한 매개 변수 조합을 테스트하여 최적의 길고 짧은 RSI 기간을 찾습니다.

  2. 더 나은 트렌드 및 역전 분석을 위해 MACD와 같은 다른 지표를 도입하십시오.

  3. 스톱 로스를 최적화하고 수익 전략을 취하십시오. 더 많은 유연성을 위해 후속 스톱을 사용하거나 수익을 이동하십시오.

  4. 다른 트렌드 사이클 단계에서 긴/단지 포지션을 조정하기 위해 포지션 사이징 제어 모듈을 추가합니다.

  5. 입력 및 출력 정확성을 향상시키기 위해 기계 학습 모델을 통합합니다.

  6. 다양한 제품과 최적화 시간 프레임에 대한 백테스트.

결론

요약하자면, 이중 RSI 전략은 트렌드를 따르는 전형적인 전략이다. 이중 RSI 신호와 이동 평균 노이즈 필터링을 결합하는 아이디어는 매우 고전적이고 실용적입니다. 개선해야 할 영역이 있지만 전반적인 논리는 명확하고 이해하기 쉽고 최적화 할 수 있습니다. 이것은 알고리즘 거래 초보자가 배우고 연습 할 수있는 훌륭한 전략입니다.


/*backtest
start: 2023-11-07 00:00:00
end: 2023-11-14 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Growth Producer", overlay=true, initial_capital = 1000, currency = "USD", pyramiding = 2, commission_type=strategy.commission.percent, commission_value=0.07, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)

//Functions
Atr(p) =>
    atr = 0.
    Tr = max(high - low, max(abs(high - close[1]), abs(low - close[1])))
    atr := nz(atr[1] + (Tr - atr[1])/p,Tr)

/// TREND
ribbon_period = input(19, "Period", step=1)

leadLine1 = ema(close, ribbon_period)
leadLine2 = sma(close, ribbon_period)

p1 = plot(leadLine1, color= #53b987, title="EMA", transp = 50, linewidth = 1)
p2 = plot(leadLine2, color= #eb4d5c, title="SMA", transp = 50, linewidth = 1)
fill(p1, p2, transp = 60, color = leadLine1 > leadLine2 ? #53b987 : #eb4d5c)

// Relative volatility index
length = input(120,"RVI period", minval=1), src = close
len = 14
stddev = stdev(src, length)
upper = ema(change(src) <= 0 ? 0 : stddev, len)
lower = ema(change(src) > 0 ? 0 : stddev, len)
rvi = upper / (upper + lower) * 100
benchmark = input(35, "RVI benchmark", minval=10, maxval=100, step=0.1)

// Plot RVI
// h0 = hline(80, "Upper Band", color=#C0C0C0)
// h1 = hline(20, "Lower Band", color=#C0C0C0)
// fill(h0, h1, color=#996A15, title="Background")
// offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
// plot(rvi, title="RVI", color=#008000, offset = offset)


/// MFI input
mfi_source = hlc3
mfi_length = input(19, "MFI Length", minval=1)
mfi_lower = input(15, "MFI Lower level", minval=0, maxval=50)
mfi_upper = input(90, "MFI Higher level", minval=50, maxval=100)


// MFI
upper_s = sum(volume * (change(mfi_source) <= 0 ? 0 : mfi_source), mfi_length)
lower_s = sum(volume * (change(mfi_source) >= 0 ? 0 : mfi_source), mfi_length)
mf = rsi(upper_s, lower_s)
// mfp = plot(mf, color=color.new(color.gray,0), linewidth=1)
// top = hline(mfi_upper, color=color.new(color.gray, 100), linewidth=1, editable=false)
// bottom = hline(mfi_lower, color=color.new(color.gray,100), linewidth=1, editable=false)
// hline(0, color=color.new(color.black,100), editable=false)
// hline(100, color=color.new(color.black,100), editable=false)

// Breaches
// b_color = (mf > mfi_upper) ? color.new(color.red,70) : (mf < mfi_lower) ? color.new(color.green,60) : na
// bgcolor(HighlightBreaches ? b_color : na)

// fill(top, bottom, color=color.gray, transp=75)

// Initial inputs
Act_RSI_VWAP_long = input(true, "RSI VOLUME WEIGHTED AVERAGE PRICE LONG")
RSI_VWAP_length_long = input(16, "RSI-VWAP LENGTH LONG")
RSI_VWAP_overSold_long = input(13, "RSI-VWAP OVERSOLD LONG", type=input.float)
RSI_VWAP_overBought_long = input(68, "RSI-VWAP OVERBOUGHT LONG", type=input.float)

Act_RSI_VWAP_short = input(true, "RSI VOLUME WEIGHTED AVERAGE PRICE SHORT")
RSI_VWAP_length_short = input(14, "RSI-VWAP LENGTH SHORT")
RSI_VWAP_overSold_short = input(7, "RSI-VWAP OVERSOLD SHORT", type=input.float)
RSI_VWAP_overBought_short = input(68, "RSI-VWAP OVERBOUGHT SHORT", type=input.float)

// RSI with VWAP as source
RSI_VWAP_long = rsi(vwap(close), RSI_VWAP_length_long)
RSI_VWAP_short = rsi(vwap(close), RSI_VWAP_length_short)

// Plot Them Separately.
// Plotting LONG, Put overlay=false
// r=plot(RSI_VWAP_long, color = RSI_VWAP_long > RSI_VWAP_overBought_long ? color.red : RSI_VWAP_lnog < RSI_VWAP_overSold_long ? color.lime : color.blue, title="rsi", linewidth=2, style=plot.style_line)
// h1=plot(RSI_VWAP_overBought_long, color = color.gray, style=plot.style_stepline)
// h2=plot(RSI_VWAP_overSold_long, color = color.gray, style=plot.style_stepline)
// fill(r,h1, color = RSI_VWAP_long > RSI_VWAP_overBought_long ? color.red : na, transp = 60)
// fill(r,h2, color = RSI_VWAP_long < RSI_VWAP_overSold_long ? color.lime : na, transp = 60)

// Plotting SHORT, Put overlay=false
// r=plot(RSI_VWAP_short, color = RSI_VWAP_short > RSI_VWAP_overBought_short ? color.red : RSI_VWAP_short < RSI_VWAP_overSold_short ? color.lime : color.blue, title="rsi", linewidth=2, style=plot.style_line)
// h1=plot(RSI_VWAP_overBought_short, color = color.gray, style=plot.style_stepline)
// h2=plot(RSI_VWAP_overSold_short, color = color.gray, style=plot.style_stepline)
// fill(r,h1, color = RSI_VWAP_short > RSI_VWAP_overBought_short ? color.red : na, transp = 60)
// fill(r,h2, color = RSI_VWAP_short < RSI_VWAP_overSold_short ? color.lime : na, transp = 60)


///////  STRATEGY Take Profit / Stop Loss ////////
////// LONG //////

long_tp1_inp = input(3.3, title='Long Take Profit 1 %', step=0.1)/100
long_tp1_qty = input(15, title="Long Take Profit 1 Qty", step=1)

long_tp2_inp = input(12, title='Long Take Profit 2%', step=0.1)/100
long_tp2_qty = input(100, title="Long Take Profit 2 Qty", step=1)

long_sl_inp = input(3.3, title='Long Stop Loss %', step=0.1)/100

long_take_level_1 = strategy.position_avg_price * (1 + long_tp1_inp)
long_take_level_2 = strategy.position_avg_price * (1 + long_tp2_inp)
long_stop_level = strategy.position_avg_price * (1 - long_sl_inp)

////// SHORT //////
short_tp1_inp = input(3.2, title='Short Take Profit 1 %', step=0.1)/100
short_tp1_qty = input(20, title="Short Take Profit 1 Qty", step=1)

short_tp2_inp = input(5.5, title='Short Take Profit 2%', step=0.1)/100
short_tp2_qty = input(100, title="Short Take Profit 2 Qty", step=1)

short_sl_inp = input(3.2, title='Short Stop Loss %', step=0.1)/100

short_take_level_1 = strategy.position_avg_price * (1 - short_tp1_inp)
short_take_level_2 = strategy.position_avg_price * (1 - short_tp2_inp)
short_stop_level = strategy.position_avg_price * (1 + short_sl_inp)



///Strategy_Conditions
/// LONG ///
entry_long =(crossover(RSI_VWAP_long, RSI_VWAP_overSold_long) and leadLine2<leadLine1) or (crossunder(mf,mfi_lower) and leadLine2<leadLine1)
entry_price_long=valuewhen(entry_long,close,0)
exit_long =crossunder(RSI_VWAP_long, RSI_VWAP_overBought_long)

/// SHORT ///

entry_short =crossunder(RSI_VWAP_short, RSI_VWAP_overBought_short) and leadLine2>leadLine1 or (crossover(mf,mfi_upper) and leadLine2>leadLine1)
entry_price_short=valuewhen(entry_short,close,0)
exit_short =crossover(RSI_VWAP_short, RSI_VWAP_overSold_short)

////// BACKTEST PERIOD ///////
testStartYear = input(2019, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2020, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

testPeriod() => true

if testPeriod()

    if strategy.position_size == 0 or strategy.position_size > 0 and rvi>benchmark
        strategy.entry("long", true, when = entry_long, comment="Insert Enter Long Comment")
    strategy.exit("TP1","long", qty_percent=long_tp1_qty, limit=long_take_level_1, stop=long_stop_level)
    strategy.exit("TP2","long", qty_percent=long_tp2_qty, limit=long_take_level_2, stop=long_stop_level)
    strategy.close("long", when=exit_long, comment = "Insert Exit Long Comment")

    if strategy.position_size == 0 or strategy.position_size < 0 and rvi>benchmark
        strategy.entry("short", false, when = entry_short, comment="Insert Enter Short Comment")
    strategy.exit("TP1","short", qty_percent=short_tp1_qty, limit=short_take_level_1, stop=short_stop_level)
    strategy.exit("TP2","short", qty_percent=short_tp2_qty, limit=short_take_level_2, stop=short_stop_level)
    strategy.close("short", when=exit_short, comment = "Insert Exit Short Comment")


// LONG POSITION
plot(strategy.position_size > 0 ? long_take_level_1 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="1st Long Take Profit")
plot(strategy.position_size > 0 ? long_take_level_2 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="2nd Long Take Profit")
plot(strategy.position_size > 0 ? long_stop_level : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Stop Loss")


// SHORT POSITION
plot(strategy.position_size < 0 ? short_take_level_1 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="1st Short Take Profit")
plot(strategy.position_size < 0 ? short_take_level_2 : na, style=plot.style_linebr, color=color.green, linewidth=1, title="2nd Short Take Profit")
plot(strategy.position_size < 0 ? short_stop_level : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Stop Loss")

더 많은