
이 전략은 간단한 이동 평균 ((SMA) 의 기울기를 기반으로 상승 추세를 식별하고 특정 조건이 충족되면 더 많은 위치를 열습니다. 또한, 선택적인 추적 중지 메커니즘을 도입하여 중지 손실 가격을 동적으로 조정하여 이익을 보호합니다. 또한, 이 전략은 가격이 너무 높을 때 다시 입지를 구축하는 것을 막기 위해 중지 된 후 다시 입장을 설정하는 조건을 설정합니다. 이러한 기능을 통해 이 전략은 상승 추세를 효과적으로 포착하고 위험을 제어하고 규율 된 거래를 구현 할 수 있습니다.
이 전략은 SMA 트렌드 추적, 스톱 추적 및 징계 재입장과 같은 메커니즘을 사용하여 상승 추세를 포착하면서 위험을 제어합니다. 최적화된 매개 변수 설정, 위험 관리 강화, 양방향 거래 및 다중 시간 프레임 확인을 지원하는 방법과 같은 방법을 통해 전략의 적응성과 강도를 더욱 향상시킬 수 있습니다.
/*backtest
start: 2023-05-28 00:00:00
end: 2024-06-02 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("MA Incline Strategy with Optional Trailing Stop-Loss", overlay=true, calc_on_every_tick=true)
// Input parameters
windowSize = input.int(20, title="Window Size")
maLength = input.int(150, title="Moving Average Length")
minSlope = input.float(0.1, title="Minimum Slope")
useTrailingStop = input.bool(true, title="Use Trailing Stop-Loss")
trailingStopPercentage = input.float(2.8, title="Trailing Stop Percentage (%)") / 100
// Calculate the moving average
ma = ta.sma(close, maLength)
// Calculate the slope of the moving average over the window size
previousMa = ta.sma(close[windowSize], maLength)
slopeMa = (ma - previousMa) / windowSize
// Check conditions
isAboveMinSlope = slopeMa > minSlope
isAboveMa = close > ma
// Buy condition
buyCondition = isAboveMinSlope and isAboveMa
// Execute strategy
if (buyCondition and strategy.opentrades == 0)
strategy.entry("Long", strategy.long)
// Trailing stop-loss (optional)
if (strategy.opentrades == 1 and useTrailingStop and isAboveMa)
// Calculate the trailing stop price
trailPrice = close * (1 - trailingStopPercentage)
// Use the built-in strategy.exit function with the trailing stop
strategy.exit("Trail Stop", "Long", stop=trailPrice)
// Exit condition
sellCondition = ta.crossover(ma, close)
if (sellCondition and strategy.opentrades == 1)
strategy.close("Long")