상대체 지수 크로스오버 전략

저자:차오장, 날짜: 2023-10-18 11:16:53
태그:

img

전반적인 설명

이 전략은 주로 트렌드를 결정하기 위해 일일 촛불의 상대적인 몸 비율 (RB) 의 이동 평균 크로스오버 신호를 사용하여 자동화 거래에 대한 스톱 로스와 수익을 취합니다. 전략 이름의 상대적인 몸 힘은 일일 촛불의 상대적인 몸 힘의 이동 평균을 의미합니다.

전략 논리

이 전략은 Vitelot의 RBI 지표에 기초하여 매일 촛불의 상대체 비율 (RB) 의 이동 평균을 계산합니다.

이 공식은 상승 촛불의 실제 몸과 촛불의 전체 길이의 비율을 계산하고, 상승 촛불의 긍정적 값과 하락 촛불의 부정적인 값을 취합니다. RB는 -1에서 1까지 있습니다.

RBI 지표는 RB의 이동 평균을 사용하여 소음을 필터링하고 시장 트렌드의 본질을 포착합니다. RBI가 신호선을 넘을 때 구매 신호가 생성되고, 아래에 넘을 때 판매 신호가 생성됩니다.

불확실한 상승 단계의 잘못된 신호를 피하기 위해 전략은 또한 긴 포지션에 대한 진정한 구매 신호를 생성하기 전에 종료 가격이 13 기간 EMA보다 높는지 확인합니다. 마찬가지로 종료가 13 EMA 이하일 때만 짧은 포지션이 실행됩니다.

이 전략은 또한 리스크를 제어하고 수익을 잠금하기 위해 스톱 로스를 구현하고 수익을 취합니다. 포지션을 열고 나면 수익은 포인트로 고정된 스톱 로스로 설정된 포인트에 따라 추적됩니다.

이점 분석

  • RBI는 상당한 소음을 필터링하고 시장 트렌드 특성을 캡처하여 다양한 시장에서 잘못된 신호를 피합니다.

  • 이동 평균 필터를 사용하면 불확실한 상승 단계에서 잘못된 신호를 효과적으로 피하고 쇼트에서 손실을 줄입니다.

  • 스톱 로즈와 영업이익은 개별 포지션의 손실 위험을 줄이고 수익을 고정시켜 전반적인 수익성을 향상시킵니다.

  • 이 전략은 몇 가지 매개 변수를 가지고 있으며 이해하기 쉽고 자동화 거래에 적합합니다.

위험 분석

  • 이 전략은 오직 RBI에만 의존합니다. 지표에서 잘못된 신호는 실패로 이어질 수 있습니다.

  • 지표의 잘못된 매개 변수 조정도 거래 신호의 품질을 악화시킬 수 있습니다.

  • 어떤 기술적 지표도 특정 시장 조건에서 손실을 완전히 피할 수 없습니다.

  • 너무 긴 스톱 로즈 설정은 너무 빈번한 스톱 아웃을 초래할 수 있고 너무 넓은 스톱 로즈 설정은 단일 포지션에서 큰 손실을 초래할 수 있습니다.

  • 부적절한 유출 통제는 계좌 삭제 위험을 초래할 수 있습니다.

최적화 방향

  • RBI 매개 변수를 최적화하기 위해 다양한 매개 변수 조합을 테스트 할 수 있습니다.

  • 신호 필터링 및 품질 향상을 위해 추가 지표가 추가 될 수 있습니다.

  • 기계 학습은 스톱 손실 및 수익 매개 변수를 훈련하고 최적화하는 데 사용될 수 있습니다.

  • 전체 포지션 크기와 위험 노출을 제어하기 위해 위험 관리 전략이 추가될 수 있습니다.

  • 오버나이트 홀딩이나 단기 스칼핑과 같은 다양한 보유 기간을 탐구할 수 있습니다.

결론

전체적으로 이것은 비교적 간단하고 직선적인 트렌드 추적 전략이다. 트렌드 방향을 결정하기 위해 추가 필터와 스톱 로스/프로프트를 사용하여 트렌드 방향을 결정하고 위험을 제어하여 다양한 시장의 잘못된 신호를 효과적으로 피한다. 그러나 어떤 기술적 지표도 위험을 완전히 피할 수 없다. 파라미터 최적화, 리스크 관리와 같은 지속적인 개선은 여전히 장기적으로 안정적인 초과 수익을 위해 필요하다. 논리는 명확하고 이해하기 쉽으며 자동 거래에 적합하다. 이것은 매우 실용적인 트렌드 추적 전략이다.


/*backtest
start: 2022-10-11 00:00:00
end: 2023-10-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("RBI Backtest /w TSSL", shorttitle="RBI Strategy", overlay=false, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital = 10000, slippage = 5)
// RBI:
//  The EMA of the relative body (RB) of Japanese candles is evaluated.
//  The RB of a candle (my definition) is simply the ratio of the body with respect to its full length
//  and taken positive for bull candles and negative for bear candles:
//      e.g. a bull "marubozo" has RB=1 a bear "marubozo" has RB=-1;
//      a "doji" has RB=0.
//  This simple indicator grasps the essence of the market by filtering out a great deal of noise.
//
//  A flag can be selected to calculate its very basic binary version, where a bull candle counts as a one
//  and a bear candle counts as a minus one.
//
//  Enter (or exit) the market when the signal line crosses the base line.
//  When the market is choppy we have a kind of alternating bear and bull candles so that
//  RBI is FLAT and usually close to zero. 
//  Therefore avoid entering the market when RBI is FLAT and INSIDE the Exclusion level.
//  The exclusion level is to be set by hand: go back in history and check when market was choppy; a good
//  way to set it is to frame the oscillations of RBI whe price was choppy.
//
//  RBI is more effective when an EMA of price is used as filtering. I found EMA(13) to be
//  a decent filter: go long when base crosses signal upwards AND closing price is above EMA(13);
//  same concept for going short.
//
//  As any other indicator, use it with responsibility: THERE CAN'T BE A SINGLE MAGIC INDICATOR winning
//  all trades.
//
//  Above all, have fun.
//
// Vitelot/Yanez/Vts March 31, 2019

par1 = input(5, title="MA1 Period")
par2 = input(5, title="Signal Period")
exclusion = input(0.2, title="Exclusion level")

useBin = input(false, title="Calculate the binary version")

treshold_long = input(0, title="Treshold Long")
treshold_short = input(0, title="Treshold Short")

fixedSL = input(title="SL Activation", defval=300)
trailSL = input(title="SL Trigger", defval=1)
fixedTP = input(title="TP Activation", defval=120)
trailTP = input(title="TP Trigger", defval=1)

FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear  = input(defval = 2019, title = "From Year", minval = 2017)
ToMonth   = input(defval = 6, title = "To Month", minval = 1, maxval = 12)
ToDay     = input(defval = 19, title = "To Day", minval = 1, maxval = 31)
ToYear    = input(defval = 2020, title = "To Year", minval = 2017)
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish window
startTimeOk()  => true // create function "within window of time" if statement true

ynSimple(t) =>
    s = (close>open)? 1: -1
    ema(sum(s,t),t)

ynRel(t) =>
    s = (close-open)/(high-low)
    ema(sum(s,t),t)

yn = useBin? ynSimple(par1): ynRel(par1) 
sig = ema(yn,par2)


plot(yn, color=aqua, title="RBI", linewidth=3, transp=0)
plot(sig, color=orange, title="Signal", linewidth=2, transp=0)

hline(0, color=white, title="Zero level", editable=false)
hline(exclusion, color=yellow, title="Exclusion level +", editable=true, linestyle=line)
hline( 0-exclusion, color=yellow, title="Exclusion level -", editable=true, linestyle=line)

long = crossover(yn,sig) and yn < treshold_long
short = crossover(sig,yn)  and yn > treshold_short

// === STRATEGY - LONG POSITION EXECUTION ===
strategy.entry("Long", strategy.long, when= long and startTimeOk())
strategy.exit("Exit", qty_percent = 100, loss=fixedSL, trail_offset=trailTP, trail_points=fixedTP) 
strategy.exit("Exit", when= short)
// === STRATEGY - SHORT POSITION EXECUTION ===
strategy.entry("Short", strategy.short, when= short and startTimeOk())
strategy.exit("Exit", qty_percent = 100, loss=fixedSL, trail_offset=trailTP, trail_points=fixedTP)
strategy.exit("Exit", when= long)


더 많은