최고의 ATR 정지 복수 전략

저자:차오장, 날짜: 2024-02-21 14:24:22
태그:

img

전반적인 설명

베스트 ATR 스톱 멀티플 전략 (Best ATR Stop Multiple strategy) 은 트렌드를 따르는 전략으로, 스톱 로스 포인트를 설정하고 위험을 동적으로 조정하기 위해 평균 참 범위 (ATR) 의 배수를 사용합니다. 가격 트렌드가 변경되면 엄청난 손실을 피하기 위해 적시에 포지션을 종료 할 수 있습니다.

전략 논리

이 전략은 먼저 빠른 SMA와 느린 SMA 기간의 간단한 이동 평균을 계산합니다. 빠른 SMA가 느린 SMA를 넘을 때 길고 빠른 SMA가 느린 SMA를 넘을 때 짧습니다.

입력 후, 그것은 실시간으로 ATR 값을 모니터링 합니다. ATR은 특정 룩백 기간 동안 평균 변동성을 나타냅니다. 전략은 우리가 ATR 기간 (예정 14) 및 곱셈 (예정 2) 을 설정 할 수 있습니다. 시스템은 입력 시 ATR 값을 계산하고 정지 거리로 설정 된 곱셈으로 곱합니다.

예를 들어, 입점 후 ATR이 50 포인트이고, 인수는 2로 설정되면 정지 거리는 100 포인트입니다. 가격이 100 포인트 이상 이동하면 정지 손실 순서가 활성화됩니다. 이는 과도한 손실을 피하기 위해 신속한 정지 손실을 허용합니다.

이 전략은 또한 트렌드 결정도 고려한다. 긴 스톱 손실은 구매 신호가 상승 추세와 일치할 때만 활성화된다. 짧은 스톱 손실은 하락 추세와 일치한다.

스톱 로스 라인은 차트에 그려져 있습니다. 실시간으로 확인할 수 있습니다. 스톱 로스 조건이 트리거되면 해당 포지션은 자동으로 시스템에서 닫습니다.

이점 분석

이 전략의 가장 큰 장점은 스톱 로스 거리를 동적으로 조정하고 시장 변동성 변화에 따라 위험 노출을 자동으로 수정한다는 것입니다. 변동성이 증가하면 스톱 로스 거리가 증가하여 스톱 로스가 발생할 가능성을 줄여줍니다. 낮은 변동성 시장에서 스톱 거리는 감소합니다.

고정된 스톱 로스 거리와 비교하면 이 접근법은 트렌드를 추적하면서 거래당 손실을 효과적으로 제어합니다. 이윤 방위뿐만 아니라 위험을 관리합니다.

또한 트렌드 결정과 결합하여 이러한 스톱 로스 방법은 통합 구역에서 윙사 (whipsaws) 에 의해 중단 될 가능성을 줄일 수 있습니다.

위험 분석

이 전략의 주요 위험은 포지션 중에 가격이 단기적으로 후퇴하여 스톱 로스를 유발할 가능성이 있습니다. 특히 ATR 기간이 너무 짧으면 스톱 거리는 단기 변동의 영향을 완전히 필터링할 수 없습니다.

또 다른 위험은 가격이 폭력적인 움직임에서 스톱 로스 수준을 통과 할 수 있다는 것입니다. 이것은 더 큰 ATR 곱셈 설정이 필요하지만 수익 잠재력이 감소한다는 것을 의미합니다.

마지막으로, 전략은 ATR 값에 대한 오후 및 시장 전 거래의 영향을 고려하지 않습니다. 이것은 ATR 데이터의 부적절한 계산으로 이어질 수 있습니다.

최적화 방향

이 전략은 몇 가지 측면에서 최적화 될 수 있습니다.

  1. ATR 기간 매개 변수를 최적화하고 다른 시장에 대한 최상의 조합을 테스트합니다.

  2. 수익의 관점에서 고정 대 동적 ATR 곱셈을 비교합니다.

  3. ATR 계산에 시간 후 데이터를 포함 하 여 오픈에 대한 격차를 줄이기

  4. ATR 조건 설정: ATR이 특정 수준에 도달 할 때만 중지 할 수 있습니다. 낮은 변동성 환경에서 불필요한 중단을 피합니다.

  5. 더 많은 필터를 포함합니다. 주요 트렌드, 부피/동력 지표 등.

결론

베스트 ATR 스톱 멀티플 전략 (Best ATR Stop Multiple Strategy) 은 스톱 거리를 동적으로 조정함으로써 트렌드 따라와 리스크 통제를 효과적으로 균형 잡습니다. 고정 스톱에 비해 손실을 효과적으로 제한하면서 수익 잠재력을 보장합니다.

물론 가격 격차와 과민적인 스톱과 같은 몇몇 위험은 남아 있습니다. 여러 차원에서의 추가 최적화는 안정성과 수익을 향상시킬 수 있습니다.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
//@author=Daveatt
//This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

SystemName = "BEST ATR Stop Multiple Strategy"
TradeId = "BEST"

InitCapital = 100000
InitPosition = 100
InitCommission = 0.075
InitPyramidMax = 1
CalcOnorderFills = true
CalcOnTick = true
DefaultQtyType = strategy.fixed
DefaultQtyValue = strategy.fixed
Precision = 2
Overlay=true


strategy(title=SystemName, shorttitle=SystemName, overlay=Overlay )

fastSMAperiod = input(defval=15, title='Fast SMA', type=input.integer, minval=2, step=1)
slowSMAperiod = input(defval=45, title='Slow SMA', type=input.integer, minval=2, step=1)

src = close
// Calculate moving averages
fastSMA = sma(src, fastSMAperiod)
slowSMA = sma(src, slowSMAperiod)

// Calculate trading conditions
enterLong  = crossover(fastSMA, slowSMA)
enterShort = crossunder(fastSMA, slowSMA)

// trend states
since_buy  = barssince(enterLong)
since_sell = barssince(enterShort)
buy_trend  = since_sell > since_buy
sell_trend = since_sell < since_buy 

is_signal = enterLong or enterShort

// get the entry price
entry_price = valuewhen(enterLong or enterShort, src, 0)

// Plot moving averages
plot(series=fastSMA, color=color.teal)
plot(series=slowSMA, color=color.orange)

// Plot the entries
plotshape(enterLong, style=shape.circle, location=location.belowbar, color=color.green, size=size.small)
plotshape(enterShort, style=shape.circle, location=location.abovebar, color=color.red, size=size.small)



///////////////////////////////
//======[ Trailing STOP ]======//
///////////////////////////////

// use SL?
useSL = input(true, "Use stop Loss")
// ATR multiple Stop
stop_atr_length         = input(14,title="ATR Length", minval=1, type=input.integer)
stop_atr_mult           = input(2,title="ATR Multiple", minval=0.05, step=0.1, type=input.float)

// Global STOP

stop_price = 0.0, stop_price := nz(stop_price[1])

// STOP ATR
var stop_atr      = 0.0
var entry_stop_atr   = 0.0

stop_atr          := nz(atr(stop_atr_length))

if enterLong or enterShort
    entry_stop_atr := stop_atr * stop_atr_mult

// display the ATR value multiple
plotshape(enterLong, title='ATR Long Stop value', style=shape.labelup, 
 location=location.bottom, color=color.green, transp=0, text='', textcolor=color.navy, editable=true, size=size.small, show_last=1, size=size.small)

// var label atr_long_label = na
// var label atr_short_label = na
lapos_y_entry_up = lowest(30)
lapos_y_entry_dn = highest(30)

// text_label = "ATR value: " + tostring(stop_atr, '#.#') + "\n\nATR Multiple value: " + tostring(entry_stop_atr, '#.#')

// if enterLong

//     label.delete(atr_long_label)

//     atr_long_label := label.new(bar_index, lapos_y_entry_up, text=text_label, 
//      xloc=xloc.bar_index, yloc=yloc.price, color=color.green, style=label.style_labelup, textcolor=color.white, 
//      size=size.normal)    

// if enterShort

//     label.delete(atr_short_label)

//     atr_short_label := label.new(bar_index, lapos_y_entry_dn, text=text_label, 
//      xloc=xloc.bar_index, yloc=yloc.price, color=color.red, style=label.style_labeldown, textcolor=color.black, 
//      size=size.normal)    

// Determine trail stop loss prices
longStopPrice = 0.0, shortStopPrice = 0.0

longStopPrice := if useSL and buy_trend
    stopValue = entry_price - entry_stop_atr
else
    0

shortStopPrice := if useSL and sell_trend
    stopValue = entry_price + entry_stop_atr
else
    999999

//////////////////////////////////////////////////////////////////////////////////////////
//*** STOP LOSS HIT CONDITIONS TO BE USED IN ALERTS  ***//
//////////////////////////////////////////////////////////////////////////////////////////

cond_long_stop_loss_hit  = useSL and buy_trend and crossunder(low, longStopPrice[1]) 

cond_short_stop_loss_hit = useSL and sell_trend and crossover(high, shortStopPrice[1]) 


// Plot stop loss values for confirmation
plot(series=useSL and buy_trend and low >= longStopPrice 
 ? longStopPrice : na,
 color=color.fuchsia, style=plot.style_cross,
 linewidth=2, title="Long Trail Stop")

plot(series=useSL and sell_trend and high <= shortStopPrice 
 ? shortStopPrice : na,
 color=color.fuchsia, style=plot.style_cross,
 linewidth=2, title="Short Trail Stop")

close_long  = cond_long_stop_loss_hit
close_short = cond_short_stop_loss_hit

// Submit entry orders
strategy.entry(TradeId + " L", long=true, when=enterLong)
strategy.close(TradeId + " L", when=close_long)

//if (enterShort)
strategy.entry(TradeId + " S", long=false, when=enterShort)
strategy.close(TradeId + " S", when=close_short)


더 많은