
이 전략의 핵심은 인덱스 평평한 이동 평균을 구매/판매 신호로 사용하여, 후속 중지 및 손실 비율을 결합하여 수익을 잠금하고 위험을 제어하는 것이다. 이 전략은 간단하게 실행할 수 있으며, 주식 및 기타 금융 상품의 정량 거래에 적용된다.
빠른 EMA와 느린 EMA를 계산한다. 빠른 EMA의 주기는 20일이고, 느린 EMA의 주기는 50일이다. 빠른 EMA 위에 느린 EMA를 통과할 때 구매 신호를 생성한다. 빠른 EMA 아래에 느린 EMA를 통과할 때 판매 신호를 생성한다.
입수 후 후속 손실을 설정하고, 포지션 지향에 따라 각각 다중 포지션 후속 손실과 빈 포지션 후속 손실의 비율을 설정합니다. 예를 들어 7% ᅲ 후속 손실은 K 라인마다 자동으로 조정되어 최대 가능한 수익을 잠금합니다.
동시에, 포지션 보유 방향과 입점 가격에 따라 각각 다중 포지션 중지 가격과 빈 포지션 중지 가격의 비율을 설정합니다. 예를 들어 2% ᆞ 포지션 중지 위치를 고정하여 과도한 손실을 방지합니다.
스톱로스 가격과 스톱로스 가격을 비교하고, 시장 가격에 가까운 스톱로스 위치를 선택하여 스톱로스 명령을 발급한다.
이동 평균 신호는 이해하기 쉽고, 실행하기 쉽습니다.
추적 손실 차단은 수익을 최대한 고정시키면서도 잘못된 판단으로 인해 불필요한 손실을 방지합니다.
거래당 최대 손실을 제어할 수 있는 인프라를 제공합니다.
후속 손실과 고정 손실을 결합하여 수익을 잠금하고 위험을 통제합니다.
이동 평균 전략은 잘못된 신호를 발생시키며, 더 강한 필터링 조건을 도입합니다.
尾随止损는 때때로 조기 중단될 수 있으며, 적절히 緩解止损幅度를 수 있다.
고정 스톱 포지션 설정이 부적절할 경우 너무 급진적이거나 보수적이어서 테스트를 통해 퍼센티지 파라미터를 조정해야 한다.
기계적으로 상쇄하면 시장의 역전 기회를 놓칠 수 있으며, 기술 지표와 결합하여 상쇄를 판단할 수 있다.
다양한 EMA 조합을 시도하여 최적의 균형을 찾습니다.
트랜스포메이션을 추가하여 트랜스포메이션을 필터링합니다.
더 많은 주식을 테스트하여 적절한 스톱로스를 찾습니다.
이동식 스톱을 추가하여 시장에 따라 스톱 위치를 조정하십시오.
RSI와 같은 지표와 결합하여 상쇄 시간을 판단하십시오.
이 전략은 이동 평균 거래 신호, 후속 상쇄 및 비율 상쇄를 통합하고, 변수 최적화를 통해 여러 주식 및 상품에 적용할 수 있으며, 안정적인 수익을 창출하면서 위험을 엄격하게 제어 할 수 있으며, 거래자의 연구 연습을 수량화하고 지속적으로 최적화 할 가치가 있습니다.
/*backtest
start: 2023-12-26 00:00:00
end: 2024-01-02 00:00:00
period: 10m
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/
// © wouterpruym1828
//@version=5
strategy(title=" Combining Trailing Stop and Stop loss (% of instrument price)",
overlay=true, pyramiding=1, shorttitle="TSL&SL%")
//INDICATOR SECTION
// Indicator Input options+
i_FastEMA = input.int(title = "Fast EMA period", minval = 0, defval = 20)
i_SlowEMA = input.int(title = "Slow EMA period", minval = 0, defval = 50)
// Calculate moving averages
fastEMA = ta.ema(close, i_FastEMA)
slowEMA = ta.ema(close, i_SlowEMA)
// Plot moving averages
plot(fastEMA, title="Fast SMA", color=color.blue)
plot(slowEMA, title="Slow SMA", color=color.orange)
//STRATEGY SECTION
// Calculate trading conditions
buy = ta.crossover(fastEMA, slowEMA)
sell = ta.crossunder(fastEMA, slowEMA)
// STEP 1:
// Configure trail stop loss level with input options (optional)
longTrailPerc = input.float(title="Long Trailing Stop (%)", minval=0.0, step=0.1, defval=7) * 0.01
shortTrailPerc = input.float(title="Short Trailing Stop (%)", minval=0.0, step=0.1, defval=7) * 0.01
//Configure stop loss level with input options (optional)
longStopPerc = input.float(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=2)*0.01
shortStopPerc = input.float(title="Short Stop Loss (%)", minval=0.0, step=0.1, defval=2)*0.01
// STEP 2:
// Determine trail stop loss prices
longTrailPrice = 0.0, shortTrailPrice = 0.0
longTrailPrice := if (strategy.position_size > 0)
stopValue = high * (1 - longTrailPerc)
math.max(stopValue, longTrailPrice[1])
else
0
shortTrailPrice := if (strategy.position_size < 0)
stopValue = low * (1 + shortTrailPerc)
math.min(stopValue, shortTrailPrice[1])
else
999999
// Determine stop loss prices
entryPrice = 0.0
entryPrice := strategy.opentrades.entry_price(strategy.opentrades - 1)
longLossPrice = entryPrice * (1 - longStopPerc)
shortLossPrice = entryPrice * (1 + shortStopPerc)
// Plot stop loss values for confirmation
plot(series=(strategy.position_size > 0) ? longTrailPrice : na,
color=color.fuchsia, style=plot.style_cross,
linewidth=2, title="Long Trail Stop")
plot(series=(strategy.position_size < 0) ? shortTrailPrice : na,
color=color.fuchsia, style=plot.style_cross,
linewidth=2, title="Short Trail Stop")
plot(series=(strategy.position_size > 0) ? longLossPrice : na,
color=color.olive, style=plot.style_cross,
linewidth=2, title="Long Stop Loss")
plot(series=(strategy.position_size < 0) ? shortLossPrice : na,
color=color.olive, style=plot.style_cross,
linewidth=2, title="Short Stop Loss")
// Submit entry orders
if (buy)
strategy.entry("Buy", strategy.long)
if (sell)
strategy.entry("Sell", strategy.short)
//Evaluating trailing stop or stop loss to use
longStopPrice = longTrailPrice < longLossPrice ? longLossPrice : longTrailPrice
shortStopPrice = shortTrailPrice > shortLossPrice ? shortLossPrice : shortTrailPrice
// STEP 3:
// Submit exit orders for stop price
if (strategy.position_size > 0)
strategy.exit(id="Buy Stop", stop=longStopPrice)
if (strategy.position_size < 0)
strategy.exit(id="Sell Stop", stop=shortStopPrice)