다중 지표 골든 스윙 거래 전략

저자:차오장, 날짜: 2023-09-11 15:18:08
태그:

이 거래 전략은 거래 신호를 생성하기 위해 RSI, 스토카스틱, 볼링거 밴드 및 슈퍼 트렌드를 포함한 여러 지표를 결합합니다.

특히, 50 이상의 RSI와 D 이상의 스토카스틱 K 값은 상승 신호로 간주됩니다. 슈퍼 트렌드 이하의 가격은 상승 추세를 나타냅니다. BB 중간 밴드 이하의 슈퍼 트렌드는 긴 신호를 형성합니다.

반대로, 50 이하의 RSI와 D 이하의 스토카스틱 K는 하향 신호를 제공합니다. 슈퍼 트렌드 이상의 가격은 하향 추세를 나타냅니다. BB 중위 밴드 이상의 슈퍼 트렌드는 짧은 신호를 만듭니다.

다중 지표 조합은 신호 신뢰성을 향상시키는 효과적인 필터로 작용합니다. 전략은 또한 위험을 제어하기 위해 스톱 손실 및 수익 조건을 설정합니다.

그러나 지표를 결합하는 것은 또한 지연을 도입하여 최적의 항목을 잠재적으로 놓치고 있습니다. 전체 경제 영향을 모니터링하는 것과 함께 매개 변수들의 실시간 조정이 여전히 필요합니다. 종합적인 위험 관리는 장기적인 안정적인 이윤에 중요합니다.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-03-10 00:00:00
period: 45m
basePeriod: 5m
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/
// © rajm14

//@version=5
strategy(title = "Golden Swing Strategy - Souradeep Dey", shorttitle = "GSS", overlay = true, process_orders_on_close = true, default_qty_type = strategy.cash, default_qty_value=100000, currency = currency.USD)

// Indicator - RSI - 20
rsiSrc = input(defval = close, title = "RSI Source")
rsiLen = input.int(defval = 20, title = "RSI Length", minval = 0, maxval = 200, step = 1)
rsi = ta.rsi(rsiSrc, rsiLen)
//plot(rsi)

// Indicator - Stochastic (55,34,21)
kLength = input.int(defval = 55, title="Stoch %K Length", minval=1)
kSmooth = input.int(defval = 34, title="Stoch %K Smoothing", minval=1)
dLength = input.int(defval = 21, title="Stoch %D Smoothing", minval=1)
kLine = ta.sma(ta.stoch(close, high, low, kLength), kSmooth)
dLine = ta.sma(kLine, dLength)
// plot(kLine, color=color.red)
// plot(dLine, color=color.green)

// Indicator - ATR(5)
atrLength = input(5, "ATR Length")
atr = ta.atr(5)
// plot(atr)

// Indicator - SuperTrend(10,2)
atrPeriod = input(10, "SuperTrend ATR Length")
stSrc = hl2
stfactor = input.float(2.0, "SuperTrend Multiplier", step = 0.1)
stAtr = ta.atr(atrPeriod)
[supertrend, direction] = ta.supertrend(stfactor, atrPeriod)
bodyMiddle = (open + close) / 2
upTrend = direction < 0 ? supertrend : na
downTrend = direction < 0? na : supertrend
// plot(bodyMiddle, display=display.none)
// plot(upTrend)
// plot(downTrend)


// Indicator - Bollinger Bands (20,2)
bblength = input.int(defval = 20, title = "BB Length")
bbsource = input(defval = close, title = "BB Source")
bbStdDev = input.float(defval = 2.0, title = "BB Std Dev", step = 0.1)
bbmultiplier = bbStdDev * ta.stdev(bbsource, bblength)
bbMband = ta.sma(bbsource, bblength)
bbUband = bbMband + bbmultiplier
bbLband = bbMband - bbmultiplier
// plot (bbUband, color = color.red, linewidth = 2)
// plot (bbMband, color = color.black, linewidth = 2)
// plot (bbLband, color = color.green, linewidth = 2)

// Trade Entry

LongEntry = rsi >= 50 and kLine > dLine and low < supertrend and direction < 0 and supertrend < bbMband
ShortEntry = rsi <= 50 and kLine < dLine and high > supertrend and direction > 0 and supertrend > bbMband
plotshape(LongEntry, style = shape.triangleup,  text = "Long", location = location.belowbar, size = size.large, color = color.green)
plotshape(ShortEntry, style = shape.triangledown,  text = "Short", location = location.abovebar, size = size.large, color = color.red)

//Trade execution
if LongEntry
    strategy.entry(id = "Buy", direction = strategy.long, limit = close * .5 * atr)

closelong = close >= strategy.position_avg_price * 2.2 * atr
stoplong = close <=  strategy.position_avg_price * 1.1 * atr

if closelong
    strategy.close(id = "Buy")
    
if stoplong
    strategy.close(id = "Buy")
    
if ShortEntry
    strategy.entry(id = "Sell", direction = strategy.long, limit = close * .5 * atr)

closeshort = close <= strategy.position_avg_price * 2.2 * atr
stopshort = close >=  strategy.position_avg_price * 1.1 * atr

if closeshort
    strategy.close(id = "Sell")
    
if stopshort
    strategy.close(id = "Sell")



더 많은