변동성 조정 이동 평균 거래 전략

저자:차오장, 날짜: 2023-11-07 17:18:05
태그:

img

전반적인 설명

이 전략은 구매 및 판매 신호를 식별하기 위해 T3 이동 평균, ATR 지표 및 Heikin Ashi의 조합을 활용하며, 거래 후 트렌드를위한 스톱 로스 및 수익 수준을 계산하기 위해 ATR을 사용합니다. 이 전략의 장점은 거래 위험을 제어하면서 빠른 반응입니다.

원칙 분석

지표 계산

  • T3 이동 평균: 트렌드 방향을 결정하기 위해 평형 T3 이동 평균 (예정기 100) 을 계산합니다.

  • ATR: 정지 손실/이익 취득 크기를 결정하는 데 사용되는 평균 실제 범위를 계산합니다.

  • ATR Trailing Stop: 가격 변화와 변동성에 따라 조정되는 ATR에 기초한 Stop Loss을 계산합니다.

무역 논리

  • 구매 신호: ATR 후속 정지 상에서 클로즈 크로스 하에 T3 이동 평균 하에 발생

  • 판매 신호: ATR 후속 정지 이하의 클로즈를 통과하고 T3 이동 평균보다 높을 때 시작됩니다.

  • 스톱 로스/트랙 이윤: ATR 및 사용자 정의 리스크/이익 비율에 기초하여 계산된 입력, 스톱 로스 및 트랙 이윤 가격 이후

출입 및 출입

  • 롱 엔트리: 스톱 로스는 엔트리 가격 빼기 ATR, 취득은 엔트리 가격 더하기 ATR * 리스크/이익 비율

  • 코트 엔트리: 스톱 로스는 엔트리 가격 더 ATR, 취득은 엔트리 가격 빼기 ATR * 리스크/어워드 비율

  • 가격이 스톱 로스 또는 영업 마이너스 수준에 도달했을 때 출입

이점 분석

신속 한 반응

T3 이동 평균 부당 기간은 100, 가격 변화에 더 빠르게 반응하기 위해 전형적인 이동 평균보다 더 민감합니다.

위험 관리

ATR 후속 스톱은 정지되지 않도록 시장 변동과 함께 움직입니다. ATR에 기반한 스톱 손실/이익 취득은 거래 당 위험/이익을 제어합니다.

추세

ATR 트레일링 스톱은 추세를 따르고, 단기적 인 인퇴에도 조기 출퇴를 피합니다.

매개 변수 최적화

T3 및 ATR의 기간은 안정성을 향상시키기 위해 다른 시장에 최적화 될 수 있습니다.

위험 분석

손익분기 절감

심각한 가격 움직임은 손실을 유발하는 스톱 로스를 침투 할 수 있습니다. ATR 기간과 스톱 거리를 넓힐 수 있습니다.

트렌드 반전

트렌드가 역전되고 가격이 트레일링 스톱을 넘으면 손실이 발생할 수 있습니다. 역전을 식별하기 위해 다른 지표를 포함 할 수 있습니다.

최적화 과잉 조정

매개 변수 최적화는 제한된 역사적 데이터에 너무 적합 할 위험이 있습니다. 시장 / 시간 프레임에 걸쳐 강력한 최적화가 필요합니다.

개선 할 기회

  • 다양한 T3 이동 평균 기간을 테스트하여 최적의 감수성과 안정성 균형을 찾으십시오.

  • ATR 기간을 최적화하여 가장 좋은 위험 통제 및 균형 다음 트렌드를 찾습니다.

  • 전환점에 잘못된 거래를 피하기 위해 RSI, MACD를 통합하십시오.

  • 최적의 자동화된 매개 변수를 위한 기계 학습, 수동 편향을 줄이는

  • 더 나은 리스크 통제를 위해 위치 크기의 규칙을 추가

요약

이 전략은 T3 및 ATR의 장점을 결합하여 위험 통제와 함께 빠른 반응을 가능하게합니다. 매개 변수 최적화 및 추가 필터로 안정성과 효율성을 더욱 향상시킬 수 있습니다. 그러나 거래자는 여전히 반전 및 손익분기 위험을 경계하고 백테스트 결과에 과도하게 의존하는 것을 피해야합니다.


/*backtest
start: 2022-10-31 00:00:00
end: 2023-11-06 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy(title='UT Bot Alerts (QuantNomad) Strategy w/ NinjaView', 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 ,alert_message=OCOMarketLong)
strategy.entry("Short", strategy.short, when=sell , 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')


더 많은