다중 시간 프레임 RSI 및 이동 평균 거래 전략

저자:차오장, 날짜: 2024-01-22 11:00:20
태그:

img

전반적인 설명

이 전략은 RSI 지표, 간단한 이동 평균 (SMA) 및 가중 이동 평균 (WMA) 을 결합하여 거래 신호를 식별합니다. 5 분 및 1 시간 시간 프레임에서 동시다발적으로 트렌드 방향을 판단합니다. 빠른 RSI 라인이 안정적인 트렌드 중 느린 라인을 넘거나 밑으로 넘을 때 거래 신호가 생성됩니다.

전략 논리

이 전략은 먼저 1시간 및 5분 시간 프레임에서 144페리오드 WMA와 5페리오드 SMA를 계산한다. 5분 SMA가 WMA보다 높을 때만 상승 시장이 확인된다. 이 전략은 RSI 오시일레이터와 그에 상응하는 K 및 D 라인을 계산한다. K 라인이 과소매 영역에서 D 라인을 넘어서면 판매 신호가 생성된다. K 라인이 과소매 영역에서 D 라인을 넘어서면 구매 신호가 생성된다.

이점 분석

이것은 매우 효과적인 트렌드-추천 전략이다. 트렌드를 결정하기 위해 두 개의 타임프레임을 통합함으로써 잘못된 신호를 크게 감소시킵니다. 또한 신호를 더 신뢰할 수 있도록 RSI, SMA 및 WMA를 포함한 여러 필터를 결합합니다. KDJ를 RSI와 함께 운전함으로써 정상적인 KDJ 전략에 내재된 일부 가짜 신호를 피합니다. 또한 적절한 스톱 손실 및 수익 취득 설정은 이익을 잠금하고 위험을 제어하는 데 도움이됩니다.

위험 분석

이 전략의 가장 큰 위험은 잘못된 트렌드 판단에 있다. 전환점에, 단기 및 장기 이동 평균은 상향 또는 하향으로 뒤집어질 수 있으며, 잘못된 신호로 이어질 수 있다. 또한, RSI는 시장의 범위 동안 더 시끄러운 신호를 생성할 수 있다. 그러나, 이러한 위험은 SMA, WMA 및 RSI 매개 변수의 기간을 적절히 조정함으로써 줄일 수 있다.

최적화 방향

이 전략은 다음과 같은 측면에서 개선될 수 있습니다.

  1. 최적의 조합을 찾기 위해 SMA, WMA 및 RSI의 다른 길이를 테스트하십시오.
  2. 신호 신뢰성을 확인하기 위해 MACD, 볼링거 밴드와 같은 다른 지표를 포함
  3. 고정 비율 정지, 후속 정지 등을 테스트함으로써 손해를 멈추고 이익을 취하는 메커니즘을 최적화하십시오.
  4. 거래 크기와 전체 위험 노출을 제어하기 위해 자본 관리 모듈을 추가합니다.
  5. 대용량 백테스팅을 통해 가장 좋은 성능 매개 변수를 찾기 위해 기계 학습 모델을 도입

요약

이 전략은 상대적으로 탄탄한 트렌드 추후 시스템을 구축하기 위해 이동 평균과 오시레이터의 강점을 완전히 활용합니다. 여러 시간 프레임과 지표에 걸쳐 신호를 확인함으로써 중장기 트렌드를 원활하게 캡처 할 수 있습니다. 스톱 로스 및 영리 설정은 또한 정상적인 시장 변동에 어느 정도 견딜 수 있습니다. 그러나 더 많은 지표 조합을 테스트하고 매개 변수 최적화를 위해 머신 러닝을 활용하는 것과 같은 개선의 여지가 있습니다. 전반적으로 이것은 매우 유망한 거래 전략입니다.


/*backtest
start: 2023-12-22 00:00:00
end: 2024-01-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bufirolas

// Works well with a wide stop with 20 bars lookback
// for the SL level and a 2:1 reward ratio Take Profit .
// These parameters can be modified in the Inputs section of the strategy panel.

// "an entry signal it's a cross down or up on
// the stochastics. if you're in a downtrend
// on the hourly time frame you
// must also be in a downtrend on the five
// minute so the five period has to be below the 144
// as long as the five period is still trading below
// the 144 period on both the hourly and the five minutes
// we are looking for these short signals crosses down
// in the overbought region of the stochastic. Viceversa for longs"

//@version=4
strategy("Stoch + WMA + SMA strat", overlay=true)

//SL & TP Inputs
i_SL=input(true, title="Use Swing Lo/Hi Stop Loss & Take Profit")
i_SwingLookback=input(20, title="Swing Lo/Hi Lookback")
i_SLExpander=input(defval=10, step=1, title="SL Expander")
i_TPExpander=input(defval=30, step=1, title="TP Expander")
i_reverse=input(false, title="Reverse Trades")
i_TStop =input(false, title="Use Trailing Stop")

//Strategy Inputs
src4 = input(close, title="RSI Source")
stochOS=input(defval=20, step=5, title="Stochastics Oversold Level")
stochOB=input(defval=80, step=5, title="Stochastics Overbought Level")

//Stoch rsi Calculations
smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
lengthRSI = input(14, minval=1)
lengthStoch = input(14, minval=1)
rsi1 = rsi(src4, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
h0 = hline(80, linestyle=hline.style_dotted)
h1 = hline(20, linestyle=hline.style_dotted)

//MA
wmalen=input(defval=144, title="WMA Length")
WMA = security(syminfo.tickerid, "60", wma(close, wmalen))
SMA = security(syminfo.tickerid, "60", sma(close, 5))
minWMA = wma(close, wmalen)
minSMA = sma(close, 5)

//Entry Logic
stobuy = crossover(k, d) and k < stochOS
stosell = crossunder(k, d) and k > stochOB
mabuy = minSMA > minWMA
daymabuy = SMA > WMA

//SL & TP Calculations
SwingLow=lowest(i_SwingLookback)
SwingHigh=highest(i_SwingLookback)
bought=strategy.position_size != strategy.position_size[1]
LSL=valuewhen(bought, SwingLow, 0)-((valuewhen(bought, atr(14), 0)/5)*i_SLExpander)
SSL=valuewhen(bought, SwingHigh, 0)+((valuewhen(bought, atr(14), 0)/5)*i_SLExpander)
lTP=(strategy.position_avg_price + (strategy.position_avg_price-(valuewhen(bought, SwingLow, 0)))+((valuewhen(bought, atr(14), 0)/5)*i_TPExpander))
sTP=(strategy.position_avg_price - (valuewhen(bought, SwingHigh, 0) - strategy.position_avg_price))-((valuewhen(bought, atr(14), 0)/5)*i_TPExpander)
islong=strategy.position_size > 0
isshort=strategy.position_size < 0

//TrailingStop
dif=(valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0))
 -strategy.position_avg_price
trailOffset     = strategy.position_avg_price - LSL
var tstop = float(na)
if strategy.position_size > 0
    tstop := high- trailOffset - dif
    if tstop<tstop[1]
        tstop:=tstop[1]
else
    tstop := na
StrailOffset     = SSL - strategy.position_avg_price
var Ststop = float(na)
Sdif=strategy.position_avg_price-(valuewhen(strategy.position_size<0 
 and strategy.position_size[1]>=0, low,0))
if strategy.position_size < 0
    Ststop := low+ StrailOffset + Sdif
    if Ststop>Ststop[1]
        Ststop:=Ststop[1]
else
    Ststop := na
    
//Stop Selector
SL= islong ? LSL : isshort ? SSL : na
if i_TStop 
    SL:= islong ? tstop : isshort ? Ststop : na
TP= islong ? lTP : isshort ? sTP : na


//Entries
if stobuy and mabuy and daymabuy
    strategy.entry("long", long=not i_reverse?true:false)
if stosell and not mabuy and not daymabuy
    strategy.entry("short", long=not i_reverse?false:true)


//Exit
if i_SL
    strategy.exit("longexit", "long", stop=SL, limit=TP)
    strategy.exit("shortexit", "short", stop=SL, limit=TP)

//Plots
plot(i_SL ? SL : na, color=color.red, style=plot.style_cross)
plot(i_SL ? TP : na, color=color.green, style=plot.style_cross)
plot(minWMA)
plot(minSMA, color=color.green)




더 많은