스토카스틱 모멘텀 인덱스 및 RSI 기반 양상 거래 전략

저자:차오장, 날짜: 2023-12-12 15:20:29
태그:

img

전반적인 설명

이 전략은 주로 두 가지 지표 - 스토카스틱 모멘텀 인덱스 (SMI) 및 상대 강도 인덱스 (RSI) 를 기반으로합니다. 또한 색 필터 및 촛불 몸 필터를 보조 판단 조건으로 통합합니다. 이 전략은 필터 조건과 결합하여 SMI 및 RSI의 구매 및 판매 신호를 기반으로 거래 신호를 생성합니다. 이 전략은 시장에서 단기 거래 기회를 효과적으로 발견 할 수 있습니다.

전략 논리

이 전략은 판단을 위해 SMI와 RSI 지표에 의존한다. SMI는 주식이 과소매 또는 과소매인지 주로 판단하고, RSI는 주식의 상대적 강도를 결정한다. 두 지표가 동시에 구매 신호를 제공하면 구매 행동이 발생한다. 구체적인 논리는 다음과 같다:

  1. SMI가 과판 (하위 한계 이하) 이면 구매 신호로 간주됩니다.
  2. RSI가 임계치 이하인 경우 구매 신호로 간주됩니다.
  3. SMI 과잉 판매와 RSI가 해당 임계 이하로 나타났을 때 구매 신호가 발사됩니다.
  4. 판매 신호 논리는 비슷합니다.

또한 이 전략은 이중 신호 모드를 가지고 있다. 이 모드는 모든 트레이드를 트리거하기 위해 SMI와 RSI 신호를 모두 필요로 한다. 이는 잘못된 신호를 효과적으로 줄일 수 있다.

또한, 컬러 필터와 촛불 몸 필터가 통합되어 있습니다. 이 필터는 상대적으로 큰 촛불 몸과 마지막 촛불이 열린 것보다 더 높게 닫히는 것을 요구합니다. 이것은 가짜 브레이크업을 추가로 피할 수 있습니다.

장점

  1. 과잉 구매/ 과잉 판매를 위한 SMI와 상대적 강도를 나타내는 RSI를 활용합니다. 이중 확인은 잘못된 신호를 줄일 수 있습니다.
  2. 이중 신호 모드는 비효율적인 거래를 크게 줄일 수 있습니다.
  3. 색상 및 몸 필터는 거짓 튀김을 효과적으로 필터링 할 수 있습니다.
  4. 전략 논리는 간단하고 깨끗합니다.
  5. 대부분의 매개 변수는 사용자 정의가 가능합니다.

위험 과 최적화

  1. SMI 및 RSI는 단독으로 사용되면 더 많은 잘못된 신호를 생성 할 수 있습니다. 신중한 검사가 필요합니다.
  2. 이중 신호 모드에서 매개 변수가 제대로 설정되지 않으면 좋은 거래 기회가 놓칠 수 있습니다.
  3. 최적의 매개 변수 조합을 찾기 위해 다른 주기적인 매개 변수 아래 전략 수익성을 테스트 할 수 있습니다.
  4. 시뮬레이션이나 백테스팅을 통해 임계 매개 변수를 평가할 수 있습니다.
  5. 전략을 최적화하기 위해 더 많은 필터를 통합하는 것을 고려할 수 있습니다

요약

이 전략은 SMI와 RSI 지표의 신호를 통합하고 이중 확인을 통해 거래 명령을 생성합니다. 색상 필터와 촛불 몸 필터는 또한 잘못된 브레이크아웃을 필터링하기 위해 구현됩니다. 전략은 간단하고 깨끗한 논리 흐름을 가지고 있으며 대부분의 매개 변수는 사용자 정의 할 수 있습니다. 매개 변수를 적절히 조정함으로써 더 나은 수익을 얻을 수 있습니다.


/*backtest
start: 2023-12-04 00:00:00
end: 2023-12-06 19:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2018

//@version=2
strategy(title = "Noro's Stochastic Strategy v1.3", shorttitle = "Stochastic str 1.3", overlay = false, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)

//Settings 
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
usemar = input(false, defval = false, title = "Use Martingale")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Capital, %")
usesmi = input(true, defval = true, title = "Use SMI Strategy")
usersi = input(true, defval = true, title = "Use RSI Strategy")
usecol = input(true, defval = true, title = "Use Color-Filter")
usebod = input(true, defval = true, title = "Use Body-Filter")
a = input(2, defval = 2, minval = 2, maxval = 50, title = "SMI Percent K Length")
b = input(2, defval = 2, minval = 2, maxval = 50, title = "SMI Percent D Length")
limitsmi = input(50, defval = 50, minval = 1, maxval = 100, title = "SMI Limit")
periodrsi = input(2, defval = 2, minval = 2, maxval = 50, title = "RSI Period")
limitrsi = input(10, defval = 10, minval = 1, maxval = 50, title = "RSI Limit")
double = input(false, defval = false, title = "SMI+RSI Mode")
showbg = input(false, defval = false, title = "Show background")
fromyear = input(2018, defval = 2018, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//Fast RSI
fastup = rma(max(change(close), 0), periodrsi)
fastdown = rma(-min(change(close), 0), periodrsi)
fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))

//Stochastic Momentum Index
ll = lowest (low, a)
hh = highest (high, a)
diff = hh - ll
rdiff = close - (hh+ll)/2
//avgrel = ema(ema(rdiff,b),b)
//avgdiff = ema(ema(diff,b),b)
avgrel = sma(sma(rdiff,b),b)
avgdiff = sma(sma(diff,b),b)
SMI = avgdiff != 0 ? (avgrel/(avgdiff/2)*100) : 0
SMIsignal = ema(SMI,b)

//Lines
plot(SMI, color = blue, linewidth = 3, title = "Stochastic Momentum Index")
plot(SMIsignal, color = red, linewidth = 3, title = "SMI Signal Line")
plot(limitsmi, color = black, title = "Over Bought")
plot(-1 * limitsmi, color = black, title = "Over Sold")
plot(0, color = blue, title = "Zero Line")

//Color-Filter
gb = close > open or usecol == false
rb = close < open or usecol == false

//Body Filter
nbody = abs(close - open)
abody = sma(nbody, 10)
body = nbody > abody / 3 or usebod == false

//Signals
up1 = SMI < -1 * limitsmi and rb and body and usesmi
dn1 = SMI > limitsmi and gb and body and usesmi
up2 = fastrsi < limitrsi and rb and body and usersi
dn2 = fastrsi > 100 - limitrsi and gb and body and usersi
exit = ((strategy.position_size > 0 and close > open) or (strategy.position_size < 0 and close < open)) and body

//Background
redb = (SMI > limitsmi and usesmi) or (fastrsi > 100 - limitrsi and usersi)
limeb = (SMI < -1 * limitsmi and usesmi) or (fastrsi < limitrsi and usersi)
col = showbg == false ? na : redb ? red : limeb ? lime : na
bgcolor(col, transp = 50)

//Trading
profit = exit ? ((strategy.position_size > 0 and close > strategy.position_avg_price) or (strategy.position_size < 0 and close < strategy.position_avg_price)) ? 1 : -1 : profit[1]
mult = usemar ? exit ? profit == -1 ? mult[1] * 2 : 1 : mult[1] : 1
lot = strategy.position_size == 0 ? strategy.equity / close * capital / 100 * mult : lot[1]

signalup = ((up1 or up2) and double == false) or (up1 and up2 and double)
if signalup
    if strategy.position_size < 0
        strategy.close_all()
        
    strategy.entry("long", strategy.long, needlong == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

signaldn = ((dn1 or dn2) and double == false) or (dn1 and dn2 and double)
if signaldn
    if strategy.position_size > 0
        strategy.close_all()
        
    strategy.entry("Short", strategy.short, needshort == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    
if time > timestamp(toyear, tomonth, today, 23, 59) or exit
    strategy.close_all()

더 많은