세 개의 기하급수적인 이동 평균 및 스토카스틱 상대 강도 지수 거래 전략

저자:차오장, 날짜: 2024-01-30 16:52:48
태그:

img

전반적인 설명

이 전략은 트리플 익스포넌셜 이동 평균 (EMA) 과 스토카스틱 상대 강도 지수 (Stoch RSI) 를 결합하여 거래 신호를 생성하는 트렌드 다음 전략이다. 빠른 EMA가 중간 EMA를 넘고 중간 EMA가 느린 EMA를 넘을 때 길게 갈 수 있습니다. 반대로 발생할 때 짧게 갈 수 있습니다. 전략은 또한 보조 지표로 스토크 RSI를 사용합니다.

원칙

  1. 8, 14, 50일 EMA를 사용한다. 8일 EMA > 14일 EMA > 50일 EMA가 되면 장거리, 반대로 되면 단거리.

  2. 보조 지표로 스토카스틱 RSI를 사용한다. 먼저 14일 RSI를 계산하고, 그 다음 RSI에 대한 스토카스틱을 계산하고, 마지막으로 3일 SMA를 K선으로 계산하고, 3일 SMA를 K선으로 D선으로 계산한다. D를 넘은 K는 긴 신호를 준다.

  3. 긴 신호에서 8일 EMA를 닫을 때 긴 거래를 입력합니다. 짧은 신호에서 8일 EMA를 닫을 때 짧은 거래를 입력합니다.

  4. 스톱 로즈는 입상 가격 아래/상단 1 ATR 거리에 설정됩니다. 수익은 입상 가격 위/상단 4 ATR 거리에 설정됩니다.

강점

  1. 기본 지표로서의 EMA는 트렌드를 효과적으로 추적 할 수 있습니다. 트리플 EMA는 여러 기간을 으로써 단기 및 장기적 경향을 모두 포착합니다.

  2. 스톡 RSI를 추가하면 잘못된 신호를 필터링하고 입력 정확도를 높일 수 있습니다.

  3. ATR 기반의 스톱 로스 및 영업 영업은 시장 변동성을 동적으로 추적하여 부적절한 투입을 피할 수 있습니다.

  4. 이 전략은 잘 조정 된 매개 변수를 가지고 있으며 트렌드 기간 동안 훌륭한 성능을 발휘합니다. 마감량은 작고 이익은 장기 거래에 일관적입니다.

위험성

  1. 여러 지표의 조합은 윙사 리스크를 증가시킨다. EMA와 스톡 RSI 사이의 충돌 신호는 나쁜 수준으로 진입할 수 있다. 이러한 경우 가격 추세 자체는 모니터링이 필요하다.

  2. 보수적 인 스톱 로스 및 영업 설정은 거대한 시장 변동으로 인해 위반 될 수 있으며, 추가 트렌드를 놓치는 조기 출출을 유발할 수 있습니다. ATR 매개 변수를 조정하거나 SL / TP 배수를 증가시키는 것이 도움이 될 수 있습니다.

  3. 트리플 EMA 설정은 빠른 라인과 중간 라인이 역전될 때 일정 지연을 가지고 있습니다. 가격 트렌드 자체는 입시를 결정하기 위해 모니터링이 필요합니다.

  4. 이 전략은 트렌딩 시장을 선호합니다. 옆시장은 잘 수행되지 않을 것입니다. MA 기간을 조정하거나 다른 보조 지표를 추가하는 것이 도움이 될 수 있습니다.

개선

  1. MACD와 같은 지표를 추가해 더 나은 엔트리를 얻습니다.

  2. ATR에 대한 긴 / 짧은 테스트 매개 변수를 최적화합니다. 예를 들어 1 ATR에서 1.5 ATR로 스톱 손실을 조정하고 더 나은 결과를 위해 4 ATR에서 3 ATR로 이익을 취하십시오.

  3. 스톡 RSI를 제거하고 소음을 필터링하고 더 안정적인 수익을 위해 MA만 유지합니다.

  4. 트렌드를 판단하는 더 많은 기준을 추가하는 것, 거래량처럼, 상당한 수준 아래에서 작동하는 것.

결론

이 전략은 트렌드를 결정하기 위해 트리플 EMA와 스톡 RSI를 결합합니다. 엄격한 엔트리 신호는 불필요한 거래를 줄입니다. ATR에 기반한 동적 SL 및 TP는 매개 변수를 적응력있게 만듭니다. 백테스트는 트렌드 기간 동안 더 작은 드라우다운과 일관된 이익으로 훌륭한 결과를 보여줍니다. 추가 최적화는 더 나은 결과를 가져올 수 있습니다.


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

//              3ESRA
//              v0.2a

// Coded by Vaida Bogdan

// 3ESRA consists of a 3 EMA cross + a close above (for longs) the quickest EMA
// or below (for shorts). Note that I've deactivated the RSI Cross Over/Under
// (you can modify the code and activate it). The strategy also uses a stop loss
// that's at 1 ATR distance from the entry price and a take profit that's at
// 4 times the ATR distance from the entry price.

// Feedback:
// Tested BTCUSDT Daily
// 1. Stoch-RSI makes you miss opportunities.
// 2. Changing RR to 4:1 times ATR works better.

//@version=4
strategy(title="3 EMA + Stochastic RSI + ATR", shorttitle="3ESRA", overlay=true, pyramiding=1,
     process_orders_on_close=true, calc_on_every_tick=true,
     initial_capital=1000, currency = currency.USD, default_qty_value=10, 
     default_qty_type=strategy.percent_of_equity,
     commission_type=strategy.commission.percent, commission_value=0.1, slippage=2)

startDate = input(title="Start Date", type=input.integer,
     defval=1, minval=1, maxval=31, group="Backtesting range")
startMonth = input(title="Start Month", type=input.integer,
     defval=1, minval=1, maxval=12, group="Backtesting range")
startYear = input(title="Start Year", type=input.integer,
     defval=1900, minval=1800, maxval=2100, group="Backtesting range")
endDate = input(title="End Date", type=input.integer,
     defval=1, minval=1, maxval=31, group="Backtesting range")
endMonth = input(title="End Month", type=input.integer,
     defval=1, minval=1, maxval=12, group="Backtesting range")
endYear = input(title="End Year", type=input.integer,
     defval=2040, minval=1800, maxval=2100, group="Backtesting range")

// Date range filtering
inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and
     (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 23, 59))
     
fast = input(8, minval=8, title="Fast EMA", group="EMAs")
medium = input(14, minval=8, title="Medium EMA", group="EMAs")
slow = input(50, minval=8, title="Slow EMA", group="EMAs")
src = input(close, title="Source")

smoothK = input(3, "K", minval=1, group="Stoch-RSI", inline="K&D")
smoothD = input(3, "D", minval=1, group="Stoch-RSI", inline="K&D")
lengthRSI = input(14, "RSI Length", minval=1, group="Stoch-RSI", inline="length")
lengthStoch = input(14, "Stochastic Length", minval=1, group="Stoch-RSI", inline="length")
rsiSrc = input(close, title="RSI Source", group="Stoch-RSI")

length = input(title="Length", defval=14, minval=1, group="ATR")
smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"], group="ATR")

// EMAs
fastema = ema(src, fast)
mediumema = ema(src, medium)
slowema = ema(src, slow)

// S-RSI
rsi1 = rsi(rsiSrc, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
sRsiCrossOver = k[1] < d[1] and k > d
sRsiCrossUnder = k[1] > d[1] and k < d

// ATR
ma_function(source, length) =>
	if smoothing == "RMA"
		rma(source, length)
	else
		if smoothing == "SMA"
			sma(source, length)
		else
			if smoothing == "EMA"
				ema(source, length)
			else
				wma(source, length)
atr = ma_function(tr(true), length)

// Trading Logic
longCond1 = (fastema > mediumema) and (mediumema > slowema)
longCond2 = true
// longCond2 = sRsiCrossOver
longCond3 = close > fastema
longCond4 = strategy.position_size <= 0
longCond = longCond1 and longCond2 and longCond3 and longCond4 and inDateRange

shortCond1 = (fastema < mediumema) and (mediumema < slowema)
shortCond2 = true 
// shortCond2 = sRsiCrossUnder
shortCond3 = close < fastema
shortCond4 = strategy.position_size >= 0
shortCond = shortCond1 and shortCond2 and shortCond3 and shortCond4 and inDateRange

var takeProfit = float(na), var stopLoss = float(na)
if longCond and strategy.position_size <= 0
    takeProfit := close + 4*atr
    stopLoss := close - 1*atr
    // takeProfit := close + 2*atr
    // stopLoss := close - 3*atr

else if shortCond and strategy.position_size >= 0
    takeProfit := close - 4*atr
    stopLoss := close + 1*atr
    // takeProfit := close - 2*atr
    // stopLoss := close + 3*atr
    
// Strategy calls
strategy.entry("3ESRA", strategy.long, comment="Long", when=longCond and strategy.position_size <= 0)
strategy.entry("3ESRA", strategy.short, comment="Short", when=shortCond and strategy.position_size >= 0)
strategy.exit(id="TP-SL", from_entry="3ESRA", limit=takeProfit, stop=stopLoss)
if (not inDateRange)
    strategy.close_all()
    
// Plot EMAs
plot(fastema, color=color.purple, linewidth=2, title="Fast EMA")
plot(mediumema, color=color.teal, linewidth=2, title="Medium EMA")
plot(slowema, color=color.yellow, linewidth=2, title="Slow EMA")
// Plot S-RSI
// plotshape((strategy.position_size > 0) ? na : sRsiCrossOver, title="StochRSI Cross Over", style=shape.triangleup, location=location.belowbar, color=color.teal, text="SRSI", size=size.small)
// Plot trade
bgcolor(strategy.position_size > 0 ? color.new(color.green, 75) : strategy.position_size < 0 ? color.new(color.red,75) : color(na))
// Plot Strategy
plot((strategy.position_size != 0) ? takeProfit : na, style=plot.style_linebr, color=color.green, title="TP")
plot((strategy.position_size != 0) ? stopLoss : na, style=plot.style_linebr, color=color.red, title="SL")



더 많은