이 전략은 단기 높은 낮은 점과 단기 및 장기 평균 비용 사이의 중간 차이를 사용하여 추세를 판단하는 지표 전략이다. 이 전략은 짧은 선의 감성을 높이고, 전후 평균 평준화 함수를 확대하여 회수 손실을 줄이기 위해 회수에서 작은 손실을 줄이고, 파동이 발생했을 때 큰 수익을 유지하는 것을 목표로 한다.
단기 비용 계산: ta.highest와 ta.lowest 함수를 사용하여 최근 shortTerm 루트 K 선의 최고 가격과 최저 가격을 계산하고, 그 다음 평균을 단기 비용으로 계산한다.
장기 비용 계산: ta.sma 함수를 사용하여 최근 longTerm 루트 K 선의 종전 가격의 간단한 이동 평균을 장기 비용으로 계산
평균비율: 단기 비용에서 장기 비용을 다
부드러운 평균차: 평균차를 부드럽게 처리하여 오판을 줄이기 위해, 여기서 ta.sma를 사용하여 간단한 이동 평균을 수행합니다.
추세 판단: 절벽값 임계값을 설정하여, 평평이 임계값보다 크면 상승 추세로 판단하고, 마이너스 임계값보다 작으면 하락 추세로 판단
출전/출전: 더 많은 시간에 상승 추세, 더 많은 시간에 하락 추세
위험 해결 방법:
이 전략은 전체적으로 매우 간단하고 직접적인 트렌드 추적 전략이다. 일반적인 이동 평균 등에 비해, 단기 및 장기 비용의 평균 차이를 계산하여 트렌드 전환을 더 빨리 판단할 수 있다. 동시에, 부드러운 처리는 또한 그것의 파라미터를 최적화 할 수 있는 공간을 더 넓히고, 부드러운 파라미터를 조정하여 민감도와 오차율을 균형을 잡을 수 있다.
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dead0001ing1
//@version=5
strategy("Trend-Following Indicator", overlay=true)
// 設置參數
shortTerm = input(5, "Short Term")
longTerm = input(20, "Long Term")
smooth = input(5, "Smoothing")
threshold = input(0, "Threshold")
// 計算短期成本
shortH = ta.highest(high, shortTerm)
shortL = ta.lowest(low, shortTerm)
shortCost = (shortH + shortL) / 2
// 計算長期成本
longCost = ta.sma(close, longTerm)
// 計算均差
deviation = shortCost - longCost
// 平滑均差
smoothedDeviation = ta.sma(deviation, smooth)
// 判斷順勢
isTrendingUp = smoothedDeviation > threshold
isTrendingDown = smoothedDeviation < -threshold
// 顯示順勢信號
plotshape(isTrendingUp, title="Trending Up", location=location.belowbar, color=color.green, style=shape.labelup, text="Up", size=size.small)
plotshape(isTrendingDown, title="Trending Down", location=location.abovebar, color=color.red, style=shape.labeldown, text="Down", size=size.small)
// 定義進出場策略
if isTrendingUp
strategy.entry("Long", strategy.long)
strategy.close("Long", when=isTrendingDown)
if isTrendingDown
strategy.entry("Short", strategy.short)
strategy.close("Short", when=isTrendingUp)