동적 후속 손절매 전략


생성 날짜: 2023-12-21 15:58:54 마지막으로 수정됨: 2023-12-21 15:58:54
복사: 1 클릭수: 761
avatar of ChaoZhang ChaoZhang
1
집중하다
1623
수행원

동적 후속 손절매 전략

개요

이 전략은 일선을 기반으로 트렌드 방향을 결정하고, 15분 K선으로 형성된 새로운 최고점 또는 최저점을 중지 지점으로 사용하거나 중지 지점을 추적하고, 더 많은 이익을 잠금하기 위해 동적으로 조정되는 중지 지점을 구현합니다.

전략 원칙

  1. 하루 K 선의 종결 가격과 전날의 최고 가격과 최저 가격의 비교를 사용하여 트렌드 방향을 판단한다. 종결 가격이 전날의 최고 가격보다 높으면 상승 추세로 정의되며, 종결 가격이 전날의 최저 가격보다 낮으면 하락 추세로 정의된다.

  2. 상승 추세에서, 15분 K 선의 종결 가격이 이전 15분 K 선의 최고 가격보다 높을 때, 더 많이; 하향 추세에서, 15분 K 선의 종결 가격이 이전 15분 K 선의 최저 가격보다 낮을 때, 더 적다.

  3. 더하면, 이전 15분 K 선의 최저가격이 중지 지점 ᅲ.

  4. 15분 K선에서 다시 새로운 고점이나 낮은 점이 생성되면, 스톱피스를 조정한다. 초과하면 새로운 낮은 점으로 조정하고, 공백하면 새로운 높은 점으로 조정하여, 동적 추적 스톱피스를 구현한다.

우위 분석

이 전략의 가장 큰 장점은 동적으로 스톱 손실을 조정할 수 있다는 것입니다. 위험 통제를 보장하면서 수익을 최대한 고정하고, 스톱 손실이 충격을 받을 확률을 줄일 수 있습니다.

이 장점은 다음과 같습니다:

  1. 트렌드 연산에 기반하여 시장의 흐름을 판단하고 올바른 거래 방향을 선택할 수 있습니다.

  2. 15분급 거래로 더 많은 기회를 잡을 수 있습니다.

  3. 동적으로 스톱 로드 전략을 조정하여 스톱 로드가 새로운 고도 또는 새로운 낮은 것에 따라 충격을 받을 위험을 줄일 수 있습니다.

  4. 정지상황은 합리적으로 설정되어, 불필요한 손실을 최대한 방지한다.

위험 분석

이 전략의 주요 위험은 트렌드 판단의 오류에서 비롯된다. 구체적인 위험점은 다음과 같다:

  1. 일선 트렌드 판단에 오류가 발생하여 거래 방향이 잘못될 수 있다.

  2. 거래가 단기간에 급격하게 변동하면 15분 스톱로디가 넘어갈 가능성이 높습니다.

  3. 트렌드 전환점을 잘못 인식하면 손실이 발생할 수 있습니다.

대응방법은 다음과 같습니다.

  1. 다른 시간주기 지표를 더하여 종합적인 판단을 하여, 단 하나의 주기만으로 오류가 발생하지 않도록 한다.

  2. 시장의 변동성을 평가하고, 변동성이 큰 경우에 적절하게 손해배상 범위를 완화한다.

  3. 트렌드 전환점 판단 기계를 추가하고, 전환 전에 적시에 포지션을 평정한다.

최적화 방향

이 전략에는 더 많은 최적화할 여지가 있습니다.

  1. 다른 주기적 지표 판단을 추가하고, 트렌드를 최적화한다.

  2. 다양한 스톱 손실 비율 설정을 테스트하고 최적의 매개 변수를 선택하십시오.

  3. 양력 지표를 늘리고, 양력에서 벗어나서 잘못된 거래가 발생하지 않도록 한다.

  4. 트렌드 회전 메커니즘을 추가하고, Exit 포인트를 최적화한다.

  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)