적응형 이동 정지 이동 평균 거래 전략


생성 날짜: 2024-02-21 16:07:20 마지막으로 수정됨: 2024-02-21 16:07:20
복사: 1 클릭수: 687
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

적응형 이동 정지 이동 평균 거래 전략

개요

이 전략의 핵심 아이디어는 T3 평균선과 ATR을 사용하여 이동 스톱로스에 적응하여 트렌드에 대한 입출소를 포착하는 것입니다. 트렌드 추적 유형 전략에 속합니다. 가격이 T3 평균선을 돌파 할 때 거래 신호를 생성하고, 돌파점에서 ATR 값을 사용하여 중지 손실 및 중지 위치를 설정하여 자동으로 중지 스톱을 구현합니다.

전략 원칙

이 전략은 주로 T3 평균선 지표, ATR 지표, ATR 이동식 중지 장치로 구성된다.

T3평균선은 평평성을 갖는 이동 평균으로 곡선의 지연성을 줄여서 가격 변화에 더 빨리 반응할 수 있다. 가격이 평평선 아래 방향에서 돌파할 때 구매 신호를 발생시키고, 가격이 평평선 위 방향에서 돌파할 때 판매 신호를 발생시킨다.

ATR 지표는 시장의 변동 정도를 계산하고 스톱로스를 설정하는 데 사용됩니다. ATR 값이 클수록 시장의 변동이 클수록 더 넓은 스톱로스를 설정해야 합니다. ATR 값이 작을수록 시장의 변동이 작을수록 더 좁은 스톱로스를 설정할 수 있습니다.

ATR 모바일 스톱 메커니즘은 ATR 값에 따라 스톱 라인의 위치를 실시간으로 조정하여 스톱 라인이 가격과 함께 작동하고 합리적인 범위 내에서 유지되도록합니다. 이렇게 스톱 라인이 너무 가까이 떨어져서 흔들리는 것을 방지하고 스톱 라인이 너무 넓어서 위험을 효과적으로 제어 할 수 없도록 방지합니다.

T3 지표 판단 방향, ATR 지표 계산 변동성 및 ATR 이동 중지 메커니즘을 통합하여, 이 전략은 보다 효율적인 트렌드 캡처 및 위험 관리를 실현한다.

장점

이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. T3 평균선의 적용은 트렌드를 잡는 정확도를 향상시킵니다.

  2. ATR 지표는 동적으로 시장의 변동률, 스톱로스 및 스톱포스트를 계산하는 것이 더 합리적입니다.

  3. ATR 모바일 스톱 메커니즘은 스톱 라인을 실시간으로 가격에 따라 움직여서 위험을 효과적으로 제어할 수 있도록 합니다.

  4. 지표 판단 및 손해 차단 장치를 통합하여 트렌드 추적 거래를 자동화합니다.

  5. 외부 거래 플랫폼을 연결하는 웹 후크를 통해 자동화 주문을 할 수 있습니다.

위험과 해결책

이 전략에는 몇 가지 위험도 있습니다.

  1. T3 평균선 파라미터를 잘못 설정하여 우수한 트렌드 기회를 놓칠 수 있다. 다른 주기에서 파라미터를 테스트하여 최적의 파라미터를 찾을 수 있다.

  2. ATR 값이 정확하지 않고, 막이 너무 크거나 너무 작아서 위험을 효과적으로 제어할 수 없습니다. ATR 주기 파라미터를 시장의 변동율 특성과 결합하여 조정할 수 있습니다.

  3. 급격한 변동이 있을 때, 스톱 라인이 뚫려서 과도한 손실이 발생할 수 있다. 합리적인 총 손실 라인을 설정하여 단일 손실이 너무 크지 않도록 할 수 있다.

  4. 양방향 반복 시에서, 스톱데이가 자주 트리거되는 상황이 발생할 수 있다. ATR 이동 스톱데이의 거리를 적절히 완화할 수 있다.

최적화 방향

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

  1. T3 평균선 파라미터를 최적화하여 가장 적합한 평형주기를 찾습니다.

  2. 다양한 ATR 주기 변수를 테스트하여 시장의 변동성을 가장 잘 반영하는 ATR 값을 계산합니다.

  3. ATR의 이동 중지 거리의 탄력 범위를 최적화하여 너무 민감한 중단을 방지한다.

  4. 적절한 필터링 조건을 추가하여 양방향 진동 시장의 빈번한 거래를 피하십시오.

  5. 트렌드 판단 지표와 결합하여 수익 방향 판단의 정확도를 높인다.

  6. 기계 학습 방법을 사용하여 매개 변수를 자동으로 최적화하십시오.

요약하다

이 전략은 트렌드 방향을 판단하는 T3 평균선, ATR 지표 계산 스톱 스톱 및 ATR 이동 스톱 메커니즘을 통합하여 스톱 거리를 조정하여 트렌드를 자동으로 추적하고 효율적인 위험 관리를 구현하는 신뢰할 수있는 트렌드 추적 전략입니다. 실제 응용에서는 현재 시장 환경에 가장 적합한 파라미터 조합을 찾기 위해 지속적인 테스트와 최적화가 필요합니다.

전략 소스 코드
/*backtest
start: 2024-01-21 00:00:00
end: 2024-02-20 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy(title='UT Bot Alerts (QuantNomad) Strategy', overlay=true)
T3 = input(100)//600
// Input for Long Settings
// Input for Long Settings


xPrice3 = close
xe1 = ta.ema(xPrice3, T3)
xe2 = ta.ema(xe1, T3)
xe3 = ta.ema(xe2, T3)
xe4 = ta.ema(xe3, T3)
xe5 = ta.ema(xe4, T3)
xe6 = ta.ema(xe5, T3)

b3 = 0.7
c1 = -b3*b3*b3
c2 = 3*b3*b3+3*b3*b3*b3
c3 = -6*b3*b3-3*b3-3*b3*b3*b3
c4 = 1+3*b3+b3*b3*b3+3*b3*b3
nT3Average = c1 * xe6 + c2 * xe5 + c3 * xe4 + c4 * xe3

//plot(nT3Average, color=color.white, title="T3")

// Buy Signal - Price is below T3 Average
buySignal3 = xPrice3 < nT3Average
sellSignal3 = xPrice3 > nT3Average
// Inputs
a = input(1, title='Key Value. "This changes the sensitivity"')
c = input(50, title='ATR Period')
h = input(true, title='Signals from Heikin Ashi Candles')
riskRewardRatio = input(1, title='Risk Reward Ratio')

xATR = ta.atr(c)
nLoss = a * xATR

src = h ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close, lookahead=barmerge.lookahead_off) : close

xATRTrailingStop = 0.0
iff_1 = src > nz(xATRTrailingStop[1], 0) ? src - nLoss : src + nLoss
iff_2 = src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), src + nLoss) : iff_1
xATRTrailingStop := src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), src - nLoss) : iff_2

pos = 0
iff_3 = src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)
pos := src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0) ? 1 : iff_3

xcolor = pos == -1 ? color.red : pos == 1 ? color.green : color.blue

ema = ta.ema(src, 1)
above = ta.crossover(ema, xATRTrailingStop)
below = ta.crossunder(ema, xATRTrailingStop)

buy = src > xATRTrailingStop and above
sell = src < xATRTrailingStop and below

barbuy = src > xATRTrailingStop
barsell = src < xATRTrailingStop

plotshape(buy, title='Buy', text='Buy', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(sell, title='Sell', text='Sell', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)

barcolor(barbuy ? color.new(color.green, 90) : na)
barcolor(barsell ? color.new(color.red, 90) : na)

var float entryPrice = na
var float takeProfitLong = na
var float stopLossLong = na
var float takeProfitShort = na
var float stopLossShort = na

if buy and buySignal3
    entryPrice := src
    takeProfitLong := entryPrice + nLoss * riskRewardRatio
    stopLossLong := entryPrice - nLoss
    takeProfitShort := na
    stopLossShort := na

if sell and sellSignal3
    entryPrice := src
    takeProfitShort := entryPrice - nLoss * riskRewardRatio
    stopLossShort := entryPrice + nLoss
    takeProfitLong := na
    stopLossLong := na

// Strategy order conditions
acct = "Sim101"
ticker = "ES 12-23"
qty = 1

OCOMarketLong = '{ "alert": "OCO Market Long", "account": "' + str.tostring(acct) + '", "ticker": "' + str.tostring(ticker) + '", "qty": "' + str.tostring(qty) + '", "take_profit_price": "' + str.tostring(takeProfitLong) + '", "stop_price": "' + str.tostring(stopLossLong) + '", "tif": "DAY" }'
OCOMarketShort = '{ "alert": "OCO Market Short", "account": "' + str.tostring(acct) + '", "ticker": "' + str.tostring(ticker) + '", "qty": "' + str.tostring(qty) + '", "take_profit_price": "' + str.tostring(takeProfitShort) + '", "stop_price": "' + str.tostring(stopLossShort) + '", "tif": "DAY" }'
CloseAll = '{ "alert": "Close All", "account": "' + str.tostring(acct) + '", "ticker": "' + str.tostring(ticker) + '" }'

strategy.entry("Long", strategy.long, when=buy and buySignal3, alert_message=OCOMarketLong)
strategy.entry("Short", strategy.short, when=sell and sellSignal3, alert_message=OCOMarketShort)

// Setting the take profit and stop loss for long trades
strategy.exit("Take Profit/Stop Loss", "Long", stop=stopLossLong, limit=takeProfitLong,alert_message=CloseAll)

// Setting the take profit and stop loss for short trades
strategy.exit("Take Profit/Stop Loss", "Short", stop=stopLossShort, limit=takeProfitShort,alert_message=CloseAll)

// Plot trade setup boxes
bgcolor(buy ? color.new(color.green, 90) : na, transp=0, offset=-1)
bgcolor(sell ? color.new(color.red, 90) : na, transp=0, offset=-1)

longCondition = buy and not na(entryPrice)
shortCondition = sell and not na(entryPrice)

// var line longTakeProfitLine = na
// var line longStopLossLine = na
// var line shortTakeProfitLine = na
// var line shortStopLossLine = na

// if longCondition
//     longTakeProfitLine := line.new(bar_index, takeProfitLong, bar_index + 1, takeProfitLong, color=color.green, width=2)
//     longStopLossLine := line.new(bar_index, stopLossLong, bar_index + 1, stopLossLong, color=color.red, width=2)
//     // label.new(bar_index + 1, takeProfitLong, str.tostring(takeProfitLong, "#.#####"), color=color.green, style=label.style_none, textcolor=color.green, size=size.tiny)
//     // label.new(bar_index + 1, stopLossLong, str.tostring(stopLossLong, "#.#####"), color=color.red, style=label.style_none, textcolor=color.red, size=size.tiny)

// if shortCondition
//     shortTakeProfitLine := line.new(bar_index, takeProfitShort, bar_index + 1, takeProfitShort, color=color.green, width=2)
//     shortStopLossLine := line.new(bar_index, stopLossShort, bar_index + 1, stopLossShort, color=color.red, width=2)
//     // label.new(bar_index + 1, takeProfitShort, str.tostring(takeProfitShort, "#.#####"), color=color.green, style=label.style_none, textcolor=color.green, size=size.tiny)
//     // label.new(bar_index + 1, stopLossShort, str.tostring(stopLossShort, "#.#####"), color=color.red, style=label.style_none, textcolor=color.red, size=size.tiny)

alertcondition(buy, 'UT Long', 'UT Long')
alertcondition(sell, 'UT Short', 'UT Short')