
この戦略は,短期的高低点と短期的および長期的平均コストの間の均差を活用してトレンドを判断する指標策である.この戦略は,短線感度を高め,前後平均平滑関数を拡大することによって,収束の損失を減らすことを目的としており,収束中の小損失を減らすため,波段が発生するときに大きな利益を維持する.
短期コストを計算する:ta.highestとta.lowestの関数を使用して,最近のショートTerm根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)