
이 전략은 양평선 기반의 지능형 트렌드 추적 시스템으로, 고위점과 낮은 점의 이동 평균과 기울기 지표를 계산하여 시장의 트렌드를 식별하고, 동적 스톱 스톱 손실 메커니즘과 결합하여 위험 관리를 수행합니다. 전략의 핵심은 기울기 하락을 통해 가짜 신호를 필터링하고, 트레일링 스톱 동적 추적 방식을 사용하여 수익을 잠금하는 것입니다.
전략은 쌍평균선 시스템을 핵심 거래 논리로 삼고 있으며, 각각 최고 가격과 최저 가격의 순서로 이동 평균을 계산한다. 가격이 상향평균선을 뚫고 평균선 경사가 눈에 띄게 올라가면, 시스템은 여러 신호를 낸다. 가격이 상향평균선을 넘어서는 다음 평균선 경사가 눈에 띄게 내려가면, 시스템은 공백 신호를 낸다. 불안한 시장에서 자주 거래되는 것을 피하기 위해, 전략은 경사치 절감 장치를 도입했다. 경사치 경사가 설정된 절감값을 초과할 때만 트렌드의 유효성을 확인한다. 위험 측면에서, 전략은 동적 스톱포드 메커니즘을 설계했으며, 초기에는 상대적으로 급진적인 스톱포드를 설정했으며, 동시에 스톱포드 보호를 사용하여 얻은 이익을 추적했다.
이것은 트렌드 추적과 위험 관리를 유기적으로 결합한 양적 거래 전략이다. 쌍평선 시스템과 기울기 하락값의 조합을 통해 전략은 시장 추세를보다 정확하게 포착할 수 있으며, 동적 스톱 스톱 손실 메커니즘은 완벽한 위험 관리를 제공합니다. 전략은 파라미터 선택과 시장 적응성 측면에서 개선 할 여지가 있지만, 명확한 논리 프레임 워크와 유연한 시스템은 후속 최적화 파라미터를위한 좋은 기반을 제공합니다.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("SMA Buy/Sell Strategy with Significant Slope", overlay=true)
// Parametri configurabili
smaPeriod = input.int(20, title="SMA Period", minval=1)
initialTPPercent = input.float(5.0, title="Initial Take Profit (%)", minval=0.1) // Take Profit iniziale (ambizioso)
trailingSLPercent = input.float(1.0, title="Trailing Stop Loss (%)", minval=0.1) // Percentuale di trailing SL
slopeThreshold = input.float(0.05, title="Slope Threshold (%)", minval=0.01) // Soglia minima di pendenza significativa
// SMA calcolate su HIGH e LOW
smaHigh = ta.sma(high, smaPeriod)
smaLow = ta.sma(low, smaPeriod)
// Funzioni per pendenza significativa
isSignificantSlope(sma, threshold) =>
math.abs(sma - sma[5]) / sma[5] > threshold / 100
slopePositive(sma) =>
sma > sma[1] and isSignificantSlope(sma, slopeThreshold)
slopeNegative(sma) =>
sma < sma[1] and isSignificantSlope(sma, slopeThreshold)
// Condizioni di BUY e SELL
buyCondition = close > smaHigh and low < smaHigh and close[1] < smaHigh and slopePositive(smaHigh)
sellCondition = close < smaLow and high > smaLow and close[1] > smaLow and slopeNegative(smaLow)
// Plot delle SMA
plot(smaHigh, color=color.green, linewidth=2, title="SMA 20 High")
plot(smaLow, color=color.red, linewidth=2, title="SMA 20 Low")
// Gestione TP/SL dinamici
longInitialTP = strategy.position_avg_price * (1 + initialTPPercent / 100)
shortInitialTP = strategy.position_avg_price * (1 - initialTPPercent / 100)
// Trailing SL dinamico
longTrailingSL = close * (1 - trailingSLPercent / 100)
shortTrailingSL = close * (1 + trailingSLPercent / 100)
// Chiusura di posizioni attive su segnali opposti
if strategy.position_size > 0 and sellCondition
strategy.close("Buy", comment="Close Long on Sell Signal")
if strategy.position_size < 0 and buyCondition
strategy.close("Sell", comment="Close Short on Buy Signal")
// Apertura di nuove posizioni con TP iniziale e Trailing SL
if buyCondition
strategy.entry("Buy", strategy.long, comment="Open Long")
strategy.exit("Long TP/Trailing SL", from_entry="Buy", limit=longInitialTP, stop=longTrailingSL)
if sellCondition
strategy.entry("Sell", strategy.short, comment="Open Short")
strategy.exit("Short TP/Trailing SL", from_entry="Sell", limit=shortInitialTP, stop=shortTrailingSL)