T3 및 ATR 기반 자동 추세 추종 전략


생성 날짜: 2024-01-03 11:58:25 마지막으로 수정됨: 2024-01-03 11:58:25
복사: 1 클릭수: 697
avatar of ChaoZhang ChaoZhang
1
집중하다
1621
수행원

T3 및 ATR 기반 자동 추세 추종 전략

개요

이 전략의 핵심은 T3 지표의 평평한 이동 평균과 ATR 지표의 동적 스톱을 사용하여 트렌드 방향을 식별하고 트렌드를 추적하는 것입니다. 이 전략은 트렌드 추적과 트렌드 반전 기회를 결합하여 트렌드 상황에서 더 많은 수익을 얻으려는 것입니다.

전략 원칙

이 전략은 T3 지표의 평평한 이동 평균을 사용하여 가격을 계산하고 ATR 지표의 평균 실제 변동 범위를 계산합니다. ATR 동적 스톱 라인을 통과하면 거래 신호가 발생합니다. 특히, ATR 스톱 라인을 통과하면 구매 신호가 발생하고 ATR 스톱 라인을 통과하면 판매 신호가 발생합니다.

가짜 신호를 필터링하기 위해, 이 전략은 추가적으로 가격도 T3 이동 평균을 뚫고 신호를 확인해야 한다고 요구한다. 또한, 전략은 ATR 값을 통해 중지 손실과 중지 위치를 계산하여 위험 관리를 구현한다.

우위 분석

전통적인 이동 평균에 비해, T3 지표는 더 높은 민감성과 더 적은 지연성을 가지고 있으며, 가격 추세의 변화를 더 빨리 포착할 수 있다. 또한, T3는 수학적인 계산의 장점을 가지고 있어, 보다 정확하고 부드러운 이동 평균을 제공할 수 있다.

ATR 값은 현재 시장의 변동성 및 위험 수준을 반영한다. ATR은 동적으로 포지션 규모를 조정하여 추세 상황에서 더 많은 수익을 얻을 수 있으며, 충격적인 상황에서 손실을 줄일 수 있다.

위험 분석

이 전략은 지표 계산에 의존하고 있으며, 중매될 위험이 있다. 또한, T3 평평한 이동 평균과 ATR 동적 스톱은 모두 뒤쳐진 문제로, 가격이 빠르게 반전할 기회를 놓칠 수 있다. 적절한 변수를 조정하거나 다른 지표와 결합하여 최적화 할 수 있다.

트렌드 흔들림이 역전될 때, 스톱로드는 파격되어 손실이 증가할 수 있다. 스톱로드 범위를 적절히 느슨하게 하거나, Handle 값과 같은 다른 매개 변수를 스톱로드 근거로 사용할 수 있다.

최적화 방향

  • T3 지표 파라미터를 조정하여 민감도를 최적화 할 수 있습니다.

  • 다양한 ATR 주기 변수를 테스트하여 최적의 값을 찾을 수 있다.

  • 다양한 리스크/이익 인수를 시도하여 최적의 파라미터를 결정할 수 있다.

  • 다른 지표 필터링 신호를 추가할 수 있습니다. 예를 들어, Money Flow Index.

  • 기계 학습 방법을 사용하여 파라미터 조합을 자동으로 최적화 할 수 있습니다.

요약하다

이 전략은 T3 평평한 이동 평균의 트렌드 추적 능력과 ATR의 동적 스톱 로드 조정 능력을 통합한다. 파라미터를 최적화하고 위험을 통제하는 상황에서 좋은 수익률을 얻을 수 있다. 이 전략은 트렌드 추적과 반전 기회를 고려하며, 범용형의 양적 거래 전략이다.

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

//@version=5
strategy(title='NinjaView Example 1 (UTBA "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')