
이 전략은 계단식 스톱포드를 사용하여 슬라이드포드 손실을 결합한 탈퇴 전략이다. 첫 번째 스톱포드를 달성한 후에 스톱포드를 손실의 균형점으로 이동시키고, 두 번째 스톱포드를 달성한 후에 스톱포드를 첫 번째 스톱포드로 이동하여, 계단식 스톱포드 슬라이드 메커니즘을 구현한다. 이것은 수익의 일부를 잠금시키면서 큰 수익 공간을 유지할 수 있다.
이 전략은 주로 다음과 같은 부분들을 통해 단계별로 스리핑 중지점을 구현합니다:
구체적으로, 그것은 100점의 중지 거리와 100/200/300점의 3개의 중지 거리를 먼저 설정한다. 그리고는 현재 가격과 포지션 개시 가격을 기반으로 이득을 계산하는 함수를 정의한다.curProfitInPts, 점수 거리에 따른 스톱 로스 함수calcStopLossPrice。
그 핵심 논리는getCurrentStage함수, 현재 포지션이 있는지 여부를 판단하고, 이득이 어느 스톱포인트를 넘었는지 여부를 판단하고, 그 이상이면 다음 단계로 이동한다. 예를 들어, 100 스톱포인트를 달성한 후 2 단계로 이동하고, 200 스톱포인트를 달성한 후 3 단계로 이동한다.
마지막으로 단계에 따라 다른 중지 손실 가격을 수정하여 슬라이드 스톱을 달성합니다. 첫 번째 단계의 중지 손실은 원래 설정을 유지합니다. 두 번째 단계는 손해 균형으로 이동합니다. 세 번째 단계는 첫 번째 중지 포인트로 이동합니다.
이 계단식 스틸 스라이드 포인트 전략은 다음과 같은 장점이 있습니다.
이 전략에는 위험도 있습니다.
이 전략은 다음과 같은 방향으로 최적화될 수 있습니다.
/*backtest
start: 2023-11-20 00:00:00
end: 2023-11-27 00:00:00
period: 3m
basePeriod: 1m
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/
// © adolgov
// @description
// when tp1 is reached, sl is moved to break-even
// when tp2 is reached, sl is moved to tp1
// when tp3 is reached - exit
//@version=4
strategy("Stepped trailing strategy example", overlay=true)
// random entry condition
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
// sl & tp in points
sl = input(100)
tp1 = input(100)
tp2 = input(200)
tp3 = input(300)
curProfitInPts() =>
if strategy.position_size > 0
(high - strategy.position_avg_price) / syminfo.mintick
else if strategy.position_size < 0
(strategy.position_avg_price - low) / syminfo.mintick
else
0
calcStopLossPrice(OffsetPts) =>
if strategy.position_size > 0
strategy.position_avg_price - OffsetPts * syminfo.mintick
else if strategy.position_size < 0
strategy.position_avg_price + OffsetPts * syminfo.mintick
else
0
calcProfitTrgtPrice(OffsetPts) =>
calcStopLossPrice(-OffsetPts)
getCurrentStage() =>
var stage = 0
if strategy.position_size == 0
stage := 0
if stage == 0 and strategy.position_size != 0
stage := 1
else if stage == 1 and curProfitInPts() >= tp1
stage := 2
else if stage == 2 and curProfitInPts() >= tp2
stage := 3
stage
stopLevel = -1.
profitLevel = calcProfitTrgtPrice(tp3)
// based on current stage set up exit
// note: we use same exit ids ("x") consciously, for MODIFY the exit's parameters
curStage = getCurrentStage()
if curStage == 1
stopLevel := calcStopLossPrice(sl)
strategy.exit("x", loss = sl, profit = tp3, comment = "sl or tp3")
else if curStage == 2
stopLevel := calcStopLossPrice(0)
strategy.exit("x", stop = stopLevel, profit = tp3, comment = "breakeven or tp3")
else if curStage == 3
stopLevel := calcStopLossPrice(-tp1)
strategy.exit("x", stop = stopLevel, profit = tp3, comment = "tp1 or tp3")
else
strategy.cancel("x")
// this is debug plots for visulalize TP & SL levels
plot(stopLevel > 0 ? stopLevel : na, style = plot.style_linebr)
plot(profitLevel > 0 ? profitLevel : na, style = plot.style_linebr)