동적 트레일링 스톱 로스 전략

저자:차오장, 날짜: 2023-12-21 15:58:54
태그:

img

전반적인 설명

이 전략은 매일 촛불을 기반으로 트렌드 방향을 결정하고 15 분 촛불로 형성 된 새로운 최고 또는 낮은 지점을 중지 손실 가격 또는 후속 중지 손실 가격으로 사용하여 동적으로 중지 손실을 조정하고 더 많은 이익을 잠금합니다.

전략 논리

  1. 트렌드 방향을 결정하기 위해 일일 촛불의 폐쇄 가격을 이전 일일 촛불의 최고 및 최저 가격과 비교합니다. 종료 가격이 전날의 최고 가격보다 높으면 상승 추세로 정의됩니다. 종료 가격이 전날의 최저 가격보다 낮으면 하락 추세로 정의됩니다.

  2. 상승 추세에 있을 때, 15분 촛불의 닫기 가격이 이전 15분 촛불의 가장 높은 가격보다 높을 때, 긴 시장을 가지게 된다. 하락 추세에 있을 때, 15분 촛불의 닫기 가격이 이전 15분 촛불의 가장 낮은 가격보다 낮을 때 짧은 시장을 가지게 된다.

  3. 이전 15분 촛불의 가장 낮은 가격을 장거리 이후의 스톱 로스 가격으로 설정합니다. 이전 15분 촛불의 가장 높은 가격을 쇼트 후의 스톱 로스 가격으로 설정합니다.

  4. 15분 촛불이 다시 새로운 최고 또는 낮은 지점을 만들 때, 그에 따라 스톱 로스 가격을 조정하십시오. 긴 후에 새로운 낮은 지점에 조정하십시오. 짧은 후에 새로운 높은 지점에 조정하십시오. 이것은 동적 인 트레일링 스톱 로스를 실현합니다.

이점 분석

이 전략의 가장 큰 장점은 스톱 로스 가격을 동적으로 조정할 수 있다는 것입니다. 위험 통제를 보장하면서 수익을 극대화하고 스톱 로스 타격의 확률을 감소시킵니다.

특히 이점은 다음과 같습니다.

  1. 트렌드 운영에 기반한 판단은 시장 추세를 적시에 결정하고 올바른 거래 방향을 선택할 수 있습니다.

  2. 15분 시간 프레임 거래는 더 많은 기회를 잡기 위해 빈번한 입출출을 허용합니다.

  3. 새로운 최고 또는 최저에 기초한 동적 스톱 로스 조정은 스톱 로스가 타격되는 위험을 줄여줍니다.

  4. 합리적인 스톱 로스 포지셔닝은 불필요한 손실을 크게 피합니다.

위험 분석

이 전략의 주요 위험은 트렌드 판단의 오류에서 비롯됩니다.

  1. 잘못된 일일 트렌드 판단은 잘못된 거래 방향으로 이어질 수 있습니다.

  2. 가격이 단기적으로 격렬하게 변동할 수 있고, 15분간의 스톱 로스가 발생할 확률이 높아집니다.

  3. 트렌드 반전 지점을 잘못 파악하면 손실이 발생할 수 있습니다.

대응 솔루션:

  1. 종합적인 판단을 위해 다른 시간 프레임의 지표를 추가하여 하나의 시간 프레임에 의존하는 것을 피합니다.

  2. 시장의 변동성을 평가하고 높은 변동성 시 스톱 로스 범위를 적절히 완화합니다.

  3. 트렌드 전환점 식별 메커니즘을 추가하여 전환 전에 적시에 포지션을 닫습니다.

최적화 방향

아직 더 많은 최적화를 할 수 있습니다.

  1. 트렌드 포착을 최적화하기 위해 다른 시간 프레임 지표를 추가합니다.

  2. 최적의 매개 변수를 찾기 위해 다른 스톱 손실 비율 설정을 테스트합니다.

  3. 부피 변동으로 인한 오류를 피하기 위해 부피 지표를 추가합니다.

  4. 출구점을 최적화하기 위해 트렌드 역전 메커니즘을 추가합니다.

  5. 트레일 스톱 가격 간격을 넓히는 것을 평가하여 스톱 손실이 발생할 위험을 더욱 줄이십시오.

요약

이 전략의 전반적인 성능은 좋다. 논리는 명확하고 이해하기 쉽다. 동적 스톱 로스 조정, 빈번한 거래, 트렌드에 따라 거래와 같은 장점이 있다. 효과적으로 위험을 제어하고 수익을 잠금 할 수 있으며 추가 테스트와 최적화에 가치가 있다. 그러나 여전히 개선의 여지가 있다. 전략의 안정성과 수익성을 더욱 강화하기 위해 여러 각도에서 포괄적인 판단, 매개 변수 최적화, 트렌드 역전 식별 메커니즘 추가 등과 같은 측면에서 개선하는 것이 좋습니다.


/*backtest
start: 2023-12-13 00:00:00
end: 2023-12-15 02:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Anand's Strategy", overlay=true)

// Get the high and low of the previous day's candle
prev_high = request.security(syminfo.tickerid, "D", high[2])
prev_low = request.security(syminfo.tickerid, "D", low[2])

// var float prev_high = na
// var float prev_low = na

prev_close = request.security(syminfo.tickerid, "D", close[1])


getDayIndexedHighLow(_bar) =>
    _indexed_high = request.security(syminfo.tickerid, "D", high[_bar])
    _indexed_low = request.security(syminfo.tickerid, "D", low[_bar])
    [_indexed_high, _indexed_low]

var index = 2

while index >= 0
    [indexed_high_D, indexed_low_D] =  getDayIndexedHighLow(index)
  
    if prev_close > indexed_high_D or prev_close < indexed_low_D
        prev_high := indexed_high_D
        prev_low := indexed_low_D
        break
    // Decrease the index to move to the previous 15-minute candle
    index := index - 1


// Determine the trade direction based on the candle criterion
trade_direction = prev_close > prev_high ? 1 : (prev_close < prev_low ? -1 : 0)

// Get the current close from 15-minute timeframe
current_close = request.security(syminfo.tickerid, "15", close[1])
prev_high_15m = request.security(syminfo.tickerid, "15", high[2])
prev_low_15m = request.security(syminfo.tickerid, "15", low[2])

// var float prev_high_15m = na
// var float prev_low_15m = na

getIndexedHighLow(_bar) =>
    _indexed_high = request.security(syminfo.tickerid, "15", high[_bar])
    _indexed_low = request.security(syminfo.tickerid, "15", low[_bar])
    [_indexed_high, _indexed_low]


// Loop through previous 15-minute candles until the condition is met
var  i = 2

while i >= 2
    [indexed_high_15m, indexed_low_15m] =  getIndexedHighLow(i)
  
    if current_close > indexed_high_15m or current_close < indexed_low_15m
        prev_high_15m := indexed_high_15m
        prev_low_15m := indexed_low_15m
        break
    // Decrease the index to move to the previous 15-minute candle
    i := i - 1



buy_condition = trade_direction == 1 and current_close > prev_high_15m
stop_loss_buy = prev_low_15m

// Sell Trade Criteria in Negative Trend
sell_condition = trade_direction == -1 and current_close < prev_low_15m
stop_loss_sell = prev_high_15m


// Trailing Stop Loss for Buy Trade
// Custom Trailing Stop Function for Buy Trade
var float trail_stop_buy = na
trailing_buy_condition = buy_condition and current_close > trail_stop_buy
if trailing_buy_condition
    trail_stop_buy := current_close

// Custom Trailing Stop Function for Sell Trade
var float trail_stop_sell = na
trailing_sell_condition = sell_condition and current_close < trail_stop_sell
if trailing_sell_condition
    trail_stop_sell := current_close

// Take Buy Trade with Stop Loss
if (buy_condition)
    strategy.entry("Buy", strategy.long)
    strategy.exit("Buy Stop Loss", "Buy", stop=stop_loss_buy)

// Take Sell Trade with Stop Loss
if (sell_condition)
    strategy.entry("Sell", strategy.short)
    strategy.exit("Sell Stop Loss", "Sell", stop=stop_loss_sell)

// Set the background color based on the trade direction
bgcolor(trade_direction == 1 ? color.new(color.green, 90) : trade_direction == -1 ? color.new(color.red, 90) : na)

더 많은