적응적인 이동 스톱 라인 거래 전략

저자:차오장, 날짜: 2024-02-21 16:07:20
태그:

img

전반적인 설명

이 전략의 핵심 아이디어는 트렌드를 따라 엔트리 및 출구 지점을 캡처하기 위해 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')


더 많은