T3 및 ATR에 기반한 자동 트렌드 추적 전략

저자:차오장, 날짜: 2024-01-03 11:58:25
태그:

img

전반적인 설명

이 전략의 핵심은 트렌드 방향을 파악하고 트렌드를 추적하기 위해 T3 지표 평형 이동 평균 및 ATR 지표 동적 스톱 손실을 사용하는 데 있습니다. 이 전략은 트렌드 추적과 트렌드 역전 기회를 결합하여 트렌드 시장에서 더 큰 이익을 달성하는 것을 목표로합니다.

전략 논리

이 전략은 평형 이동 평균을 계산하기 위해 T3 지표를 사용하며, 현재 주기의 실제 평균 범위를 계산하기 위해 ATR 지표를 사용한다. 거래 신호는 가격이 ATR 동적 스톱 로스를 넘을 때 생성된다. 구체적으로, 가격이 ATR 스톱 로스 라인을 넘을 때 구매 신호가 생성되고, 가격이 ATR 스톱 로스 라인을 넘을 때 판매 신호가 생성된다.

거짓 신호를 필터하기 위해 전략은 추가적으로 신호를 확인하기 전에 가격이 T3 이동 평균을 통과해야 한다고 요구합니다. 또한 전략은 위험 관리를 구현하기 위해 ATR 값을 기반으로 스톱 로스를 계산하고 이익을 취합니다.

이점 분석

전통적인 이동 평균에 비해 T3 지표는 더 높은 민감도와 더 적은 지연을 가지고 있으며 가격 트렌드의 변화를 더 빨리 파악 할 수 있습니다. 또한 T3는 더 정확하고 매끄러운 이동 평균을 제공할 수있는 수학적 이점을 가지고 있습니다.

ATR 값은 현재 시장의 변동성과 위험 수준을 반영합니다. ATR 동적 추적 스톱 및 이익은 트렌딩 시장에서 더 큰 수익을 달성하고 변동 시장에서 손실을 줄이기 위해 역동적으로 포지션 크기를 조정할 수 있습니다.

위험 분석

이 전략은 지표 계산과 중재되는 위험에 의존한다. 또한, T3 평형 이동 평균 및 ATR 동적 정지에는 빠른 가격 반전을위한 기회를 놓칠 수 있는 지체 문제가 있다. 매개 변수는 그에 따라 조정되거나 최적화를 위해 다른 지표와 결합될 수 있다.

트렌드가 변동하고 역전될 때, 스톱 손실은 더 큰 손실로 이어질 수 있습니다. 스톱 손실 범위의 합리적인 확대 또는 핸들 번호와 같은 다른 매개 변수를 사용하여 탐색 할 수 있습니다.

최적화 방향

  • 감수성을 최적화하기 위해 T3 지표 매개 변수를 조정합니다.

  • 최적의 값을 찾기 위해 다른 ATR 사이클 매개 변수를 테스트합니다.

  • 가장 좋은 매개 변수를 결정하기 위해 다른 위험 보상 비율을 시도해보세요.

  • 자금 흐름 지표와 같은 다른 지표를 필터 신호에 추가합니다.

  • 기계 학습 방법을 사용하여 자동으로 매개 변수 조합을 최적화합니다.

요약

이 전략은 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')


더 많은