이 전략은 슬라이드 트래킹 스톱 메커니즘을 채택하여 가격 변동의 폭에 따라 스톱 라인을 이동하여 동적 스톱을 구현한다. 가격이 지정된 수익 수준을 달성한 후 트래킹 스톱을 시작하여 수익을 보호함과 동시에 스톱이 너무 일찍 유발 될 가능성을 최소화한다. 일반적인 스톱 전략의 개선 및 최적화에 속한다.
이 전략은 쌍평평선 판단 트렌드 방향에 기초하여 입구 신호는 빠른 평평선 위에 느린 평평선을 횡단한다.
이 프로젝트의 혁신은 손해 방지 장치의 디자인에 있습니다.
스톱로스 시작 라인을 설정한다. 가격이 이 라인을 뚫을 때 스톱로스 추적이 시작된다.
스톱 라인은 설정된 슬라이드 Percentage에 따라 이동 추적한다. 3%의 슬라이드 포인트를 설정하면 스톱 라인은 최저 가격의 3%보다 낮아진다.
가격이 불리한 방향으로 돌아와 추적 스톱 라인을 터치하면 평점 스톱
이 디자인은 스톱 로드가 자동으로 수익을 추적하도록 보장하고 수익이 좋은 상태에서 손실을 막는 가능성을 줄여줍니다.
위험은 다음과 같은 방법으로 줄일 수 있습니다.
이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.
다른 빠른 선과 느린 선의 조합 변수를 테스트합니다.
직접 추적 스톱을 활성화하거나 다른 품종에 따라 다른 매개 변수를 설정
다양한 품종에 대한 최적의 스틸포트 비율을 찾아내는 방법
스톱로즈 탈퇴 후 재입장 조건 설정
시장의 변동이 커지면 적절하게 손해배상 범위를 완화할 수 있습니다.
이 전략은 슬라이드 트래킹 스톱 방식을 채택하고, 시작 라인 후 스톱 위치를 동적으로 조정한다. 이 스톱 방식은 시장 변동에 따라 자동으로 스톱 손실을 조정할 수 있으며, 수익을 보호하고 불필요한 스톱 손실을 줄이는 사이의 균형을 달성한다. 그러나 품종 특성에 맞는 최적화 파라미터를 필요로 하며, 평형 라인 판단과 같은 다른 기술 지표를 보조하여 진입의 정확성을 향상시킵니다. 동시에 재 진입 메커니즘은 초기의 스톱 손실 위험을 줄일 수 있습니다.
/*backtest
start: 2022-09-14 00:00:00
end: 2023-09-20 00:00:00
period: 2d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//@author=Daveatt
SystemName = "BEST Trailing Stop 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,
// pyramiding=InitPyramidMax, initial_capital=InitCapital, default_qty_type=DefaultQtyType, default_qty_value=InitPosition, commission_type=strategy.commission.percent,
// commission_value=InitCommission, calc_on_order_fills=CalcOnorderFills, calc_on_every_tick=CalcOnTick, precision=2)
src = close
// Calculate moving averages
fastSMA = sma(close, 15)
slowSMA = sma(close, 45)
// 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
change_trend = (buy_trend and sell_trend[1]) or (sell_trend and buy_trend[1])
//plot(buy_trend ? 1 : 0, title='buy_trend', transp=100)
//plot(sell_trend ? 1 : 0, title='sell_trend', transp=100)
// get the entry price
entry_price = valuewhen(enterLong or enterShort, close, 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")
// Configure trail stop level with input
StopTrailPerc = input(title="Trail Loss (%)", type=input.float, minval=0.0, step=0.1, defval=3) * 0.01
// Will trigger the take profit trailing once reached
use_SL_Trigger = input(true, "Use stop Loss Trigger")
StopTrailTrigger = input(2.0, "SL Trigger (%)",minval=0,step=0.5,type=input.float) * 0.01
StopLossPriceTrigger = 0.0
StopLossPriceTrigger := if (use_SL_Trigger)
if buy_trend
entry_price * (1 + StopTrailTrigger)
else
entry_price * (1 - StopTrailTrigger)
else
-1
var SL_Trigger_Long_HIT = false
SL_Trigger_Long_HIT := useSL and use_SL_Trigger and buy_trend and high >= StopLossPriceTrigger
? true : SL_Trigger_Long_HIT[1]
var SL_Trigger_Short_HIT = false
SL_Trigger_Short_HIT := useSL and use_SL_Trigger and sell_trend and low <= StopLossPriceTrigger
? true : SL_Trigger_Short_HIT[1]
display_long_SL_trigger = useSL and buy_trend and use_SL_Trigger
and SL_Trigger_Long_HIT == false and StopLossPriceTrigger != -1
display_short_SL_trigger = useSL and sell_trend and use_SL_Trigger
and SL_Trigger_Short_HIT == false and StopLossPriceTrigger != -1
display_SL_trigger = display_long_SL_trigger or display_short_SL_trigger
plot(display_SL_trigger ? StopLossPriceTrigger : na, title='SLPriceTrigger', transp=0,
color=color.maroon, style=plot.style_circles, linewidth=3)
// Determine trail stop loss prices
longStopPrice = 0.0, shortStopPrice = 0.0
longStopPrice := if useSL and buy_trend
stopValue = low * (1 - StopTrailPerc)
max(stopValue, longStopPrice[1])
else
0
shortStopPrice := if useSL and sell_trend
stopValue = high * (1 + StopTrailPerc)
min(stopValue, shortStopPrice[1])
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])
and (SL_Trigger_Long_HIT or use_SL_Trigger == false)
cond_short_stop_loss_hit = useSL and sell_trend and crossover(high, shortStopPrice[1])
and (SL_Trigger_Short_HIT or use_SL_Trigger == false)
// Plot stop loss values for confirmation
plot(series=useSL and buy_trend and low >= longStopPrice
and (SL_Trigger_Long_HIT or use_SL_Trigger == false)
? longStopPrice : na,
color=color.fuchsia, style=plot.style_cross,
linewidth=2, title="Long Trail Stop")
plot(series=useSL and sell_trend and high <= shortStopPrice
and (SL_Trigger_Short_HIT or use_SL_Trigger == false)
? 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)
if change_trend
SL_Trigger_Long_HIT := false
SL_Trigger_Short_HIT := false