
이 전략은 빠른 EMA 평균선 ((9주기) 과 느린 EMA 평균선 ((21주기) 의 교차를 입문 신호로 사용하고, 이동한 스톱로스를 결합하여 이익을 잠금화하여 과대 인출을 피한다.
빠른 EMA 라인이 아래쪽에서 느린 EMA 라인을 뚫을 때, 구매 신호를 생성한다. 빠른 EMA 라인이 위쪽에서 아래쪽에서 느린 EMA 라인을 뚫을 때, 판매 신호를 생성한다.
일단 입시되면, 전략은 실시간으로 최고 가격을 추적하고, 현재 최고 가격보다 2% 낮으면 이동식 스톱로스를 트리거하여 수익을 잠금합니다.
위험 해결 방법:
이 전략은 트렌드 판단과 손해 관리의 장점을 통합하여 순차적으로 수행 할 수 있으며 위험을 효과적으로 제어 할 수 있습니다. 매개 변수를 조정하고 최적화하여 다양한 유형의 시장과 거래 품종에 적용 할 수 있으며 더 많은 테스트를 할 가치가 있습니다.
/*backtest
start: 2023-12-12 00:00:00
end: 2023-12-19 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("EMA Crossover with Trailing Stop-Loss", overlay=true)
fastEMA = ema(close, 9)
slowEMA = ema(close, 21)
// Entry conditions
longCondition = crossover(fastEMA, slowEMA)
shortCondition = crossunder(fastEMA, slowEMA)
// Trailing stop-loss calculation
var float trailingStop = na
var float highestHigh = na
if (longCondition)
highestHigh := na
trailingStop := na
if (longCondition and high > highestHigh)
highestHigh := high
if (strategy.position_size > 0)
trailingStop := highestHigh * (1 - 0.02) // Adjust the trailing percentage as needed
// Execute trades
strategy.entry("Long", strategy.long, when=longCondition)
strategy.entry("Short", strategy.short, when=shortCondition)
// Apply trailing stop-loss to long positions
strategy.exit("Long", from_entry="Long", loss=trailingStop)
// Plot EMAs and Trailing Stop-Loss
plot(fastEMA, color=color.green, title="Fast EMA")
plot(slowEMA, color=color.red, title="Slow EMA")
plot(trailingStop, color=color.orange, title="Trailing Stop-Loss", linewidth=2)