이중 MACD StochRSI 거래 전략

저자:차오장, 날짜: 2023-09-22 16:55:55
태그:

전반적인 설명

이 전략은 트레이드 신호를 위해 이중 MACD 지표와 StochRSI 오시일레이터를 결합합니다. 이중 MACD는 빠르고 느린 효과를 위해 다른 매개 변수를 사용하며 StochRSI는 모멘텀 분리를 확인합니다. 트렌드 필터와 스톱 로스는 또한 위험을 제어하는 데 추가됩니다.

전략 논리

트레이드 신호는 다음을 기반으로 합니다.

  • 이중 MACD: 빠른 MACD는 짧은 룩백 기간을 사용하며 느린 MACD는 평형 효과를 위해 긴 룩백 기간을 사용합니다.

  • 스톡RSI: RSI 상위/하위 범위를 계산하여 과잉 구매/ 과잉 판매 RSI 수준을 식별합니다.

입국 규칙:

  • 롱: 빠른 MACD가 제로 라인을 넘고 느린 MACD가 제로 라인을 넘습니다. StochRSI가 과판되고 K가 D를 넘습니다. 상승 추세입니다.

  • 짧은: 빠른 MACD는 0선 아래로 넘어가고 느린 MACD는 0선 아래로 넘어가고 있습니다. StochRSI는 과잉 구매되고 K는 D 아래로 넘어가고 있습니다. 하락 추세입니다.

장점

  • 이중 MACD는 더 높은 신호 품질을 위해 잘못된 파장을 피합니다.

  • StochRSI는 추격을 피하기 위해 과반 구매/ 과반 판매 수준을 식별합니다.

  • 역동적 손실을 줄이기 위해 전체 트렌드 방향을 고려합니다.

  • 크로스 타임프레임 검증은 신호의 효과를 향상시킵니다.

  • 스톱 손실은 위험을 통제합니다.

위험성

  • MACD는 잘못된 신호에 취약하고 추가 검증이 필요합니다.

  • 부진한 StochRSI 매개 변수는 거래를 놓칠 수 있습니다.

  • 스톱 로스 레벨은 너무 보수적이거나 공격적이 될 수 있습니다.

  • 동적 정지 위치 관리가 부족합니다.

개선 사항:

  1. 부피나 MA 기울기 같은 필터를 추가합니다.

  2. 다른 오시레이터를 최적화하거나 추가합니다.

  3. 동적 스톱 손실 추적

  4. 성능에 기반한 위치 크기를 추가합니다.

최적화

최적화해야 할 주요 분야:

  1. 지표 파라미터 최적화

  2. 잘못된 신호를 제거하기 위해 필터를 추가합니다.

  3. 역동적인 후속을 위해 정지를 최적화하십시오.

  4. 전략 성과에 기초한 포지션 크기를 포함합니다.

  5. 자동 최적화를 위한 기계 학습을 추가합니다.

요약

이 전략은 더 강한 신호를 위해 여러 지표를 결합하지만, 바람직하지 않은 거래를 줄이고 수익성을 향상시키기 위해 매개 변수, 필터링, 동적 정지 최적화가 필요합니다. 전반적으로 논리는 최적화 잠재력이 좋은 건전합니다.


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

//@version=2



//This strategy is an ongoing work in progress. Last updated 8/6/16.
//Feel free to modify it as you see fit, if you do borrow code then send me a link so I 
//can see and maybe borrow some of your code to improve this.
//Thanks to ChrisMoody who I stole the code for setting custom resolution from.
//
//more info in comments at end of script





strategy("MACDouble & StochRSI w/ safeties v0.3", overlay=true)

source = close
useCurrentRes = input(true, title="Uncheck to use custom res./intrv. for 2nd MACD indicator")
resCustom = input(title="Resolution/interval to use for 2nd MACD:",  defval="45")
res = useCurrentRes ? timeframe.period : resCustom

useCurrentRes2 = input(true, title="Uncheck to use custom res/intrv for StochRSI")
resCustom2 = input(title="Resolution to use for StochRSI indicator:",  defval="45")
res2 = useCurrentRes2 ? timeframe.period : resCustom2


//MACD1
fastLength = input(10, title="MACD fast length")
slowlength = input(21, title="MACD slow length")
sigLength = input(9, title="MACD signal length")

MACD = ema(source, fastLength) - ema(source, slowlength)
signal = sma(MACD, sigLength)
delta = MACD - signal



//MACD2
fastLength2 = input(31, title= "2nd MACD fast length")
slowlength2 = input(63, title= "2nd MACD slow length")
sigLength2 = input(30, title= "2nd MACD signal length")

MACD2 = ema(source, fastLength2) - ema(source, slowlength2)
signal2 = sma(MACD2, sigLength2)
delta2 = MACD2 - signal2

MACDRes = security(syminfo.tickerid, res, MACD2)
signalRes = security(syminfo.tickerid,res, signal2)
deltaRes = security(syminfo.tickerid, res, delta2)


uptrend = (close + high)/(close[1] + high[2])
downtrend = (close + low)/(close[1] + low[2])

smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
lengthRSI = input(11, minval=1)
lengthStoch = input(11, minval=1)
src = close

rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
RSI_buyTrig = input(90)
RSI_sellTrig = input(20)

kRes = security(syminfo.tickerid, res2, k)
dRes = security(syminfo.tickerid, res2, d)


if (delta > 0) and (year>2012) and (deltaRes > 0) and (uptrend > 1) and (  kRes and dRes < RSI_buyTrig) and (kRes > dRes)
    strategy.entry("buy", strategy.long, comment="buy")
    

if (delta < 0) and (year>2012) and (deltaRes < 0) and (downtrend < 1) and ( kRes and dRes > RSI_sellTrig) and (kRes < dRes)
    strategy.entry("sell", strategy.short, comment="sell")
	strategy.exit("sell", loss = 9000)



//  RELEASE NOTES, ETC
//
// The core starting idea for this backtesting script came from the desire to have two traditional
//MACD indicators: one 'fast' and one 'slow'. The slow one is to pretty much smooth out noisy signals
//so that short term changes in price are ignored (ideally). 
//	A brief version history
//		v0.1 - Basic two MACD indicators script
//      v0.2 - Added StochRSI indicator
//      v0.21- Added primitive uptrend/downtrend safety condition 
//      v0.22- Added changable time resolution for MACDslow
//      v0.23- Added exit safeties conditional on loss threshold   
//      v0.3 - Added changeable resolution for StochRSI
//	Future changes planned for next release:
//		-Fine tuning exit safeties
//      -Major overhaul of trade logic/triggers (may be forked as a different script)
//
//I am more than happy to discuss any difficulties you are having, questions about the script, or improvement suggestions.
//I am not a coder and my background is actually in economics, so feel free to debug ;)
//Feel free to tip me on the indcluded bitcoin address on TV as well
// tradingview.com/u/RyanMartin 
// rjmarti2@millersville.edu


더 많은