2단계 스톱 로스 전략

저자:차오장, 날짜: 2023-10-25 18:11:30
태그:

img

전반적인 설명

이 전략의 주요 아이디어는 두 가지 수익 목표를 설정하고 첫 번째 목표가 달성 된 후 Stop Loss를 입상 가격으로 이동하여 Stop Loss 사냥을 피하는 것입니다.

전략 논리

이 전략은 볼링거 밴드 및 스토카스틱 지표에 기반한 거래를 수행합니다. 가격이 볼링거 상단 범위를 초과 할 때 짧고 스토카스틱이 과판을 표시 할 때 길게됩니다.

구체적으로, 입력 논리는:

  1. 클로지는 볼링거 하단역 아래로 들어가고 스토카스틱 K는 D 아래로 넘어가면 장면을 입력합니다.

  2. 클로즈가 볼린거 상단 위에 있고 스토카스틱 K가 D를 넘을 때 쇼트를 입력합니다.

이 전략은 두 가지 수익 목표를 설정합니다. TP1은 200 포인트, TP2는 500 포인트로 결정됩니다.

가격이 움직이고 TP1가 트리거되면 전략은 Stop Loss를 엔트리 가격으로 이동합니다. 이것은 첫 단계부터 이익을 잠금하고 Stop Loss 사냥을 방지합니다.

이 전략은 TP2 또는 스톱 로즈가 발생하면 모든 포지션을 닫습니다.

이점 분석

이 두 단계 스톱 손실 접근 방식의 가장 큰 장점은 스톱 손실 사냥을 방지하면서 수익을 잠금 할 수 있다는 것입니다. 스톱 손실을 엔트리 가격으로 이동함으로써 스톱 손실 사냥의 가능성을 줄이고 이익을 보호합니다.

또 다른 장점은 변동성 범위를 측정하는 볼링거 밴드와 과잉 구매/ 과잉 판매에 대한 스토카스틱의 조합이 보다 정확한 항목을 제공합니다.

위험 분석

주요 위험은 볼링거 밴드 및 스토카스틱 지표의 잠재적 인 잘못된 신호에서 비롯됩니다. 잘못된 볼링거 범위는 실종 항목 또는 나쁜 신호로 이어질 수 있습니다. 스토카스틱 잘못된 브레이크 또한 잘못된 항목을 유발합니다.

또한 엔트리 가격으로 이동 한 후 다시 스톱 로스가 사냥 될 위험이 있습니다. V 모양의 반전은 두 번째 스톱 로스를 유발할 수 있습니다.

이 위험은 두 지표의 매개 변수를 최적화하고 스톱 손실 사이의 거리를 늘림으로써 줄일 수 있습니다.

최적화 방향

이 전략에 대한 추가 최적화:

  1. 최적의 볼링거와 스토카스틱 매개 변수를 찾기 위해 다른 매개 변수 조합을 테스트합니다.

  2. 이상적인 구성을 찾기 위해 다른 이익/손실 목표를 테스트합니다.

  3. 더 높은 정확성을 위해 멀티 지표 시스템을 만들기 위해 이동 평균과 같은 다른 지표를 추가합니다.

  4. 다른 스톱 로스 포지셔닝 로직을 연구하세요. 입시 가격 대신 입시로부터의 고정 거리를요.

  5. 스톱 로스 움직임의 발생을 3단계 이상으로 늘려야 합니다.

결론

이 전략은 입시에 볼링거 밴드 (Bollinger Band) 와 스토카스틱 (Stochastic) 을 사용하며, 두 가지 수익 목표를 설정하고, 첫 번째 목표가 달성 된 후 스톱 손실을 입시에 이동하여 두 단계 스톱 손실을 형성합니다. 이것은 수익을 효과적으로 잠금하고 스톱 손실 사냥을 방지합니다. 전략은 명확한 장점이 있지만 매개 변수 최적화, 멀티 지표 시스템 및 스톱 손실 논리 조정을 통해 개선할 여지가 있습니다.


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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © fpsd4ve

//@version=5

// Add Bollinger Bands indicator (close, 20, 2) manually to visualise trading conditions
strategy("2xTP, SL to entry", 
     overlay=false,
     pyramiding=0,
     calc_on_every_tick=false,
     default_qty_type=strategy.percent_of_equity,
     default_qty_value=25,
     initial_capital=1000,
     commission_type=strategy.commission.percent,
     commission_value=0.01
     )

// PARAMETERS
// Assumes quote currency is FIAT as with BTC/USDT pair
tp1=input.float(200, title="Take Profit 1")
tp2=input.float(500, title="Take Profit 2")
sl=input.float(200, title="Stop Loss")
stOBOS = input.bool(true, title="Use Stochastic overbought/oversold threshold")

// Colors
colorRed = #FF2052
colorGreen = #66FF00


// FUNCTIONS
// Stochastic
f_stochastic() =>
    stoch = ta.stoch(close, high, low, 14)
    stoch_K = ta.sma(stoch, 3)
    stoch_D = ta.sma(stoch_K, 3)
    stRD = ta.crossunder(stoch_K, stoch_D)
    stGD = ta.crossover(stoch_K, stoch_D)
    [stoch_K, stoch_D, stRD, stGD]


// VARIABLES
[bbMiddle, bbUpper, bbLower] = ta.bb(close, 20, 2)
[stoch_K, stoch_D, stRD, stGD] = f_stochastic()


// ORDERS
// Active Orders
// Check if strategy has open positions
inLong = strategy.position_size > 0
inShort = strategy.position_size < 0
// Check if strategy reduced position size in last bar
longClose = strategy.position_size < strategy.position_size[1]
shortClose = strategy.position_size > strategy.position_size[1]

// Entry Conditions
// Enter long when during last candle these conditions are true:
// Candle high is greater than upper Bollinger Band
// Stochastic K line crosses under D line and is oversold
longCondition = stOBOS ?
     low[1] < bbLower[1] and stGD[1] and stoch_K[1] < 25 :
     low[1] < bbLower[1] and stGD[1]

// Enter short when during last candle these conditions are true:
// Candle low is lower than lower Bollinger Band
// Stochastic K line crosses over D line and is overbought
shortCondition = stOBOS ?
     high[1] > bbUpper[1] and stRD[1] and stoch_K[1] > 75 :
     high[1] > bbUpper[1] and stRD[1]

// Exit Conditions
// Calculate Take Profit 
longTP1 = strategy.position_avg_price + tp1
longTP2 = strategy.position_avg_price + tp2
shortTP1 = strategy.position_avg_price - tp1
shortTP2 = strategy.position_avg_price - tp2

// Calculate Stop Loss
// Initialise variables
var float longSL = 0.0
var float shortSL = 0.0

// When not in position, set stop loss using close price which is the price used during backtesting
// When in a position, check to see if the position was reduced on the last bar
// If it was, set stop loss to position entry price. Otherwise, maintain last stop loss value
longSL := if inLong and ta.barssince(longClose) < ta.barssince(longCondition)
    strategy.position_avg_price
else if inLong
    longSL[1]
else
    close - sl

shortSL := if inShort and ta.barssince(shortClose) < ta.barssince(shortCondition)
    strategy.position_avg_price
else if inShort
    shortSL[1]
else
    close + sl

// Manage positions
strategy.entry("Long", strategy.long, when=longCondition)
strategy.exit("TP1/SL", from_entry="Long", qty_percent=50, limit=longTP1, stop=longSL)
strategy.exit("TP2/SL", from_entry="Long", limit=longTP2, stop=longSL)

strategy.entry("Short", strategy.short, when=shortCondition)
strategy.exit("TP1/SL", from_entry="Short", qty_percent=50, limit=shortTP1, stop=shortSL)
strategy.exit("TP2/SL", from_entry="Short", limit=shortTP2, stop=shortSL)


// DRAW
// Stochastic Chart
plot(stoch_K, color=color.blue)
plot(stoch_D, color=color.orange)

// Circles
plot(stOBOS ? stRD and stoch_K >= 75 ? stoch_D : na : stRD ? stoch_D : na, color=colorRed, style=plot.style_circles, linewidth=3)
plot(stOBOS ? stGD and stoch_K <= 25 ? stoch_D : na : stGD ? stoch_K : na, color=colorGreen, style=plot.style_circles, linewidth=3)

// Levels
hline(75, linestyle=hline.style_dotted)
hline(25, linestyle=hline.style_dotted)

더 많은