적응적인 이동 평균과 함께 다중 요인 조합 전략

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

img

I. 전략 개요

적응적인 이동 평균과 함께 다중 요인 조합 전략은 HA 라인, 이동 평균, 스토카스틱 크로스오버 및 내일 바의 사용을 결합 한 복합 전략입니다. 그것은 더 많은 거래 기회를 발견하고 황소 시장에서 더 높은 누적 수익을 달성하는 것을 목표로합니다.

II. 전략 논리

이 전략의 핵심 논리는 여러 가지 기술 지표를 결합하여 구매 및 판매 신호를 점수화하고 일치하는 결과를 기반으로 다양한 강점을 가진 거래 신호를 생성하는 것입니다.

특히 전략에서 사용되는 네 가지 주요 기술 지표는 다음과 같습니다.

  1. 이 전략은 가격 추세를 결정하기 위해 일내 바의 색을 사용합니다. 두 개의 연속 녹색 실체 HA 바는 구매 신호를 주고, 두 개의 연속 빨간 홀 HA 바는 판매 신호를 제공합니다.

  2. 이동 평균. 이 전략은 서로 다른 매개 변수 설정을 가진 빠른, 느린 및 필터 이동 평균을 동시에 사용합니다. 빠른 선이 느린 선 위에 넘어가고 느린 선이 필터 선 위에 넘어가면 구매 신호를 제공합니다. 그리고 반대로. 이동 평균은 중장기 트렌드를 결정하는 데 좋습니다.

  3. 스토카스틱 인디케이터. 이 인디케이터는 상승과 하락의 크로스오버의 시기를 결정합니다. %K 라인이 아래에서 %D 라인을 뚫을 때 구매 신호를 제공합니다. 그리고 %K가 위에서 %D를 뚫을 때 판매 신호를 제공합니다.

  4. 매칭 스코어 메커니즘. 위의 요인의 매칭에 따라 전략은 점수 메커니즘을 채택합니다. 더 많은 매칭 요인, 대응 거래 신호가 강합니다.

여러 가지 요인을 종합적으로 판단함으로써 전략은 중장기 및 단기간에 더 미묘한 거래 기회를 포착하여 황금 시장에서 초과 수익을 얻을 수 있습니다.

III. 장점

이 다중 요인 전략의 가장 큰 장점은 거래 신호의 신뢰성을 향상시키는 것입니다. 단일 기술적 지표는 잘못된 신호를 생성하는 경향이 있습니다. 여러 지표를 결합함으로써이 전략은 잘못된 신호의 간섭을 효과적으로 줄일 수 있습니다.

또한, 단 하나의 지표를 따르는 것과 비교할 때, 다중 요인 조합은 거래의 승률을 향상시킬 수 있습니다. 황소 시장에서 더 높은 누적 수익을 얻을 수 있습니다.

IV. 위험

이 전략의 주요 위험은 다중 요인 조합 자체가 전략의 복잡성을 증가시키는 것입니다. 그것은 매개 변수 설정, 동시에 여러 지표의 빈번한 조정을 돌볼 필요가 있습니다.

또한, 곰시장에서는 보유 시간이 너무 길어질 수 있습니다. 스톱 로스가 설치되어 있더라도 상당한 손실이 발생할 수 있습니다.

또한, 스토카스틱 및 HA 라인 같은 기술적 지표는 블랙 스완 이벤트에 의해 영향을 받을 수 있으며, 이는 잘못된 신호를 생성하고 불필요한 손실을 유발하는 경향이 있습니다.

V. 개선 아이디어

이 전략은 다음과 같은 측면에서 최적화 될 수 있습니다.

  1. 최적의 조합을 찾기 위해 각 지표의 매개 변수 설정을 최적화합니다.

  2. 모델 트레이닝과 실시간 매개 변수 최적화를 위한 적응 매개 변수 모듈을 추가합니다.

  3. 최대 유출을 줄이기 위해 스톱 로스 전략을 추가합니다.

  4. 위치 제어 모듈을 추가하여 시장 조건에 따라 위치를 동적으로 조정합니다.

  5. 기계 학습 알고리즘을 통합하여 다중 요소 점수 시스템을 위한 신경 네트워크 모델을 구축합니다.

VI 결론

다중 요인 조합 전략과 적응 이동 평균은 여러 기술적 지표의 강점을 결합합니다. 이는 신호 품질을 효과적으로 향상시키고 황소 시장에서 초과 수익을 얻을 수 있습니다. 그러나 동시에 전략의 복잡성을 증가시켜 추가 테스트와 최적화를 요구합니다.


/*backtest
start: 2022-12-08 00:00:00
end: 2023-12-14 00:00:00
period: 1d
basePeriod: 1h
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/
// © cyrule
//@version=4
strategy("2nd Grade Strategy", overlay=true, shorttitle="2GTS", max_lines_count = 500, max_labels_count = 500, calc_on_every_tick = true, calc_on_order_fills = true, pyramiding = 1, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)

source = input(close, title = "Source")

// **********************
// * Heikin-Ahshi       *
// * kudos to garethyeo *
// **********************
showHA   = input(true, title = "Show Heikin Ashi?", group = "Heikin Ashi")
ha_open  = security(heikinashi(syminfo.tickerid), timeframe.period, open)
ha_high  = security(heikinashi(syminfo.tickerid), timeframe.period, high)
ha_low   = security(heikinashi(syminfo.tickerid), timeframe.period, low)
ha_close = security(heikinashi(syminfo.tickerid), timeframe.period, close)

bgcolor(iff(showHA and ha_open < ha_close , color.new(#53b987, transp = 92.5), na), title = 'Green HA')
bgcolor(iff(showHA and ha_open >= ha_close, color.new(#eb4d5c, transp = 92.5), na), title = 'Red HA'  )


// ******************
// * Moving Average *
// ******************
// MA Settings
showMA         = input(true, title = "Show Moving Averages?", group = "Moving Averages")
fastMALength   = input(title = "Fast MA Length", minval = 1, step = 1, defval = 20, group = "Moving Averages")
slowMALength   = input(title = "Slow MA Length", minval = 1, step = 1, defval = 50, group = "Moving Averages")
maType         = input(title = "Moving Average Type", defval = "SMA", options = ["SMA", "EMA", "RMA", "WMA", "VWMA"], group = "Moving Averages")
filterMALength = input(title = "Filter MA Length", minval = 1, step = 1, defval = 200, group = "Moving Averages")
filterMAType   = input(title = "Filter MA Type", defval = "EMA", options = ["SMA", "EMA", "RMA", "WMA", "VWMA"], group = "Moving Averages")

// Calculate MA
var float maFast   = na
var float maSlow   = na
var float maFilter = na

if (maType   == "SMA")
    maFast   := sma(source, fastMALength)
    maSlow   := sma(source, slowMALength)
if (maType   == "EMA")
    maFast   := ema(source, fastMALength)
    maSlow   := ema(source, slowMALength)
if (maType   == "RMA")
    maFast   := rma(source, fastMALength)
    maSlow   := rma(source, slowMALength)
    maFilter := rma(source, filterMALength)
if (maType   == "WMA")
    maFast   := wma(source, fastMALength)
    maSlow   := wma(source, slowMALength)
if (maType   == "VWMA")
    maFast   := vwma(source, fastMALength)
    maSlow   := vwma(source, slowMALength)

if (filterMAType == "SMA")
    maFilter     := sma(source, filterMALength)
if (filterMAType == "EMA")
    maFilter     := ema(source, filterMALength)
if (filterMAType == "RMA")
    maFilter     := rma(source, filterMALength)
if (filterMAType == "WMA")
    maFilter     := wma(source, filterMALength)
if (filterMAType == "VWMA")
    maFilter     := vwma(source, filterMALength)

BiruAtasMerah = (maFast >= maSlow) and (maSlow >= maFilter)
MerahAtasBiru = (maFast <= maSlow) and (maSlow <= maFilter)

// Lukis MA
plot(series = showMA ? maFast   : na, color = color.blue, title = "MA Fast")
plot(series = showMA ? maSlow   : na, color = color.red,  title = "MA Slow")
plot(series = showMA ? maFilter : na, color = #FFCC00,    title = "MA Filter")


// **************
// * Stochastic *
// **************
// Stochastic Settings
showSSC = input(true, title = "Show Stochastic Crossovers?", group = "Stochastic")
Length = input (10, minval = 1, title = "%K Length", group = "Stochastic")
SmoothK = input (3, minval = 1, title = "%K Smoothing", group = "Stochastic")
SmoothD = input (3, minval = 1, title = "%D Smoothing", group = "Stochastic")

// Calculate Stochastic
var float K = na
var float D = na

if (maType ==  "SMA")
	K      := sma(stoch(source, high, low, Length), SmoothK)
	D      := sma(K, SmoothD)
if (maType ==  "EMA")
	K      := ema(stoch(source, high, low, Length), SmoothK)
	D      := ema(K, SmoothD)
if (maType ==  "RMA")
	K      := rma(stoch(source, high, low, Length), SmoothK)
	D      := rma(K, SmoothD)
if (maType ==  "WMA")
	K      := wma(stoch(source, high, low, Length), SmoothK)
	D      := wma(K, SmoothD)
if (maType ==  "VWMA")
	K      := vwma(stoch(source, high, low, Length), SmoothK)
	D      := vwma(K, SmoothD)

StochasticCrossOver  = crossover(K, D)
StochasticCrossUnder = crossunder(K, D)

// Lukis SS
plotshape(showSSC and StochasticCrossOver  and K <=  20            ? K : na, text = "Golden\nCrossover",  color = color.new(color.green, transp = 25), location = location.belowbar, size = size.tiny, title = "Golden Crossover" )
plotshape(showSSC and StochasticCrossUnder and K >=  80            ? D : na, text = "Deadly\nCrossover",  color = color.new(color.red, transp = 25),   location = location.belowbar, size = size.tiny, title = "Deadly Crossover" )
plotshape(showSSC and StochasticCrossOver  and K <=  80 and K > 20 ? K : na, text = "Bullish\nCrossover", color = color.new(color.green, transp = 50), location = location.belowbar, size = size.tiny, title = "Bullish Crossover")
plotshape(showSSC and StochasticCrossUnder and K >=  20 and K < 80 ? D : na, text = "Bearish\nCrossover", color = color.new(color.red, transp = 50),   location = location.belowbar, size = size.tiny, title = "Bearish Crossover")

showBull = input(true, title = "Show Bullish Signal?", group = "Signal")
showBear = input(false, title = "Show Bearish Signal?", group = "Signal")

bullishCriteria = 0
if (ha_open < ha_close) and (ha_open[1] < ha_close[1]) and (ha_open[2] >= ha_close[2])
    bullishCriteria := bullishCriteria + 1
if (maFast > maSlow) and (maSlow > maFilter)
    bullishCriteria := bullishCriteria + 1
if (K > D) and (K > K[1]) and (D > D[1])
    bullishCriteria := bullishCriteria + 1

bearishCriteria = 0
if (ha_open >= ha_close) and (ha_open[1] >= ha_close[1]) and (ha_open[2] < ha_close[2])
    bearishCriteria := bearishCriteria + 1
if (maFast < maSlow) and (maSlow < maFilter)
    bearishCriteria := bearishCriteria + 1
if (K < D) and (K < K[1]) and (D < D[1])
    bearishCriteria := bearishCriteria + 1

signal = color.new(color.white, transp = 0)
if bearishCriteria == 2
    signal := color.new(color.orange, transp = 50)
if bearishCriteria == 3
    signal := color.new(color.red, transp = 50)
if bullishCriteria == 2
    signal := color.new(color.aqua, transp = 50)
if bullishCriteria == 3
    signal := color.new(color.green, transp = 50)

bullishCriteria := showBull ? bullishCriteria : 0
bearishCriteria := showBear ? bearishCriteria : 0

bgcolor(iff(bullishCriteria > 1, signal, na), title = 'Bullish Signal')
bgcolor(iff(bearishCriteria > 1, signal, na), title = 'Bearish Signal')

longTPPerc  = input(title = "Take Profit Threshold (%)"            , minval = 0.0, step = 0.5, defval = 2.5, group = "Trading") / 100
profitRatio = input(title = "Profit-to-Loss ratio (risk tolerance)", minval = 1.0, step = 0.1, defval = 1.4, group = "Trading")
longSLPerc  = longTPPerc / profitRatio
takeProfit  = strategy.position_avg_price * (1 + longTPPerc)
stopLoss    = strategy.position_avg_price * (1 - longSLPerc)
strategy.initial_capital = 50000
strategy.entry("Long" , strategy.long , floor(strategy.initial_capital*.1/close), stop = strategy.position_avg_price * 1.25, when = bullishCriteria > 1)
strategy.entry("Short", strategy.short, floor(strategy.initial_capital*.1/close), stop = strategy.position_avg_price * 1.25, when = bearishCriteria > 1)
strategy.close("Long" , when = (open >= takeProfit) or (open <= stopLoss) or (high >= takeProfit) or (low <= stopLoss))
strategy.close("Short", when = (open >= takeProfit) or (open <= stopLoss) or (high >= takeProfit) or (low <= stopLoss))

plotshape(bullishCriteria, location = location.belowbar, color = color.new(color.black, transp = 100))
plotshape(bearishCriteria, location = location.belowbar, color = color.new(color.black, transp = 100))

더 많은