
이것은 부피 가중 이동 평균 (VWMA) 과 지수 이동 평균 (EMA) 에 기반한 트렌드 추적 전략이며, 가격 각도 분석과 동적 추적 스톱스 메커니즘을 결합한다. 이 전략은 주로 VWMA와 빠른 이동 평균의 교차를 모니터링하면서 가격 운동의 각도 조건과 결합하여 진입 시기를 결정하며, 비율 추적 스톱스를 사용하여 위험을 관리한다.
전략의 핵심 논리는 다음과 같은 핵심 구성 요소를 기반으로 합니다.
이것은 잘 구성된 트렌드 추적 전략으로, 앵글 분석과 다중 이동 평균의 조합을 통해 주요 트렌드에서 더 나은 성능을 얻을 수 있습니다. 약간의 뒤처짐과 변수 민감성의 문제가 있지만, 제안된 최적화 방향을 통해 전략은 여전히 개선할 수 있습니다. 특히 더 긴 시간 주기 트렌드 거래에서 적용하기에 적합합니다.
/*backtest
start: 2024-02-18 00:00:00
end: 2024-10-16 00:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("PVSRA Trailing Strategy with Angle Condition (40-50 degrees)", overlay=true)
// === INPUTS ===
priceData = input.source(close, title="Price Data")
maLength = input.int(25, title="Moving Average Length", minval=2)
useBias = input.bool(false, title="Long/Short just above/below 200 EMA")
useTrailing = input.bool(true, title="Use Trailing Stop")
trailPerc = input.float(1.0, title="Trailing Stop Percentage", minval=0.1)
anglePeriod = input.int(14, title="Period for Angle Calculation", minval=1)
// === CÁLCULOS ===
maValue = ta.vwma(priceData, maLength)
maLong = ta.ema(high, 50)
maShort = ta.ema(low, 50)
maFast = ta.vwma(close, 8)
bias = ta.ema(close, 200)
longBias = useBias ? close > bias : true
shortBias = useBias ? close < bias : true
// === CÁLCULO DO ÂNGULO DA MÉDIA MÓVEL DE 50 ===
ma50 = ta.ema(close, 50)
angle = math.atan((ma50 - ma50[anglePeriod]) / anglePeriod) * (180 / math.pi) // Converte radianos para graus
// === CONDIÇÃO DE ÂNGULO ===
validAngleL = angle >= 45
validAngleS = angle <= 45
// === PLOTS ===
plot(maValue, color=color.orange, title="Moving Average")
plot(maFast, color=color.green, title="Fast MA")
plot(ma50, color=color.blue, title="50 EMA")
plotshape(series=(strategy.position_size > 0) ? maValue : na,
color=color.red, style=shape.circle, location=location.absolute,
title="Long Stop")
plotshape(series=(strategy.position_size < 0) ? maValue : na,
color=color.red, style=shape.cross, location=location.absolute,
title="Short Stop")
// === CONDIÇÕES DE ENTRADA ===
enterLong = close > maValue and ta.crossover(maFast, maValue) and close > maLong and longBias and validAngleL
enterShort = close < maValue and ta.crossunder(maFast, maValue) and close < maShort and shortBias and validAngleS
// === CONDIÇÕES DE SAÍDA ===
exitLong = ta.crossunder(maFast, maValue) and strategy.position_size > 0
exitShort = ta.crossover(maFast, maValue) and strategy.position_size < 0
// === EXECUÇÃO DA ESTRATÉGIA ===
if (enterLong)
strategy.entry("EL", strategy.long)
if (enterShort)
strategy.entry("ES", strategy.short)
if (exitLong or exitShort)
strategy.close_all()
// === TRAILING STOP ===
if (useTrailing and strategy.position_size > 0)
trailPrice = close * (1 - trailPerc / 100)
strategy.exit("Trailing Long", from_entry="EL", stop=trailPrice)
if (useTrailing and strategy.position_size < 0)
trailPrice = close * (1 + trailPerc / 100)
strategy.exit("Trailing Short", from_entry="ES", stop=trailPrice)