トレンドをフォローする戦略

作者: リン・ハーンチャオチャン開催日:2023年11月22日15時50分07秒
タグ:

img

概要

この戦略の主な考え方は,可能な限り正確なトレンドフォロー戦略を実装することである.この戦略は,過去閉盤価格の一定数の"信頼度"を計算することによって,現在の線形トレンドの継続可能性を判断する.この戦略は,信頼度が一定のレベルを超えると,進行中の線形トレンドが継続する可能性が高いと仮定する.

戦略原則

この戦略は,通常の線形回帰を用いて過去Nの閉値の線形適合を計算し,閉値からの偏差の傾斜kと標準偏差 σを得ます.その後,トレンド信頼度 (trend confidence) をk/σで定義します.

トレンドの信頼が"長入口"の値を超えると,ロングで; "長出口"の値に下落すると,ロングで閉じる. 同様に,トレンドの信頼が"短入口"の値を下回ると,ショートで; "短出口"の値を超えると,ショートで閉じる.

明確な線形トレンドに従わない ワイルド価格の動きからの信号をフィルタリングできます

利点分析

この戦略は,短期的な価格変動を避け,長期的トレンドのみを追跡することで,低取引頻度と高勝率を得ることができる統計におけるトレンドフォローと線形回帰方法を組み合わせています.

この戦略にはパラメータ調整スペースが大きく,パラメータを調整することで異なる製品と時間枠に適応し,一般的な可能性が高くなります.

リスク分析

この戦略には,罠にかかるリスクがあります.重要なトレンド逆転が起こると大きな損失を生むでしょう.また,不適切なパラメータ設定は,過剰取引または良い取引機会を逃すこともあります.

ダウンサイドリスクを制御するためにストップロスを設定できます.同時に,過剰なフィットメントを避けるためにパラメータの選択を慎重に評価する必要があります.

オプティマイゼーションの方向性

この戦略は,次の側面においてさらに最適化することができる.

  1. ストップ・ロスト/取利益ロジックを追加し,利益を固定し,リスクを制御する

  2. ダイナミックパラメータ調整のための適応最適化モジュールを追加

  3. 傾向の逆転点を決定し,さらに勝利率を改善するために機械学習モデルを追加します

  4. 一般化を改善するために,異なる製品とタイムフレームで適応性をテストする

結論

一般的には,これはリスク制御による長期トレンドフォロー戦略である.トレンドフォローと線形回帰方法を組み合わせてノイズ取引信号をフィルタリングする.パラメータチューニングを通じて,異なる製品とタイムフレームにうまく適応することができ,深入的な研究と改善に値する効果的な戦略である.


/*backtest
start: 2022-11-15 00:00:00
end: 2023-11-21 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCamel61097

// ################################################################################################

// "This is a trend following strategy that performed very well on the past 5 years"
// "Intended to be used on BTC-USDT, 4hr timeframe"

// "A factor 2 Leverage can be added by changing Order Size to 200% of equity"
// "Higher leverage is not recommended due to big drawdowns"

// "Also seems to work on 1D timeframe, although ideal parameters may be different"
// "Also seems to work on ETH-USDT and some other altcoins, although ideal parameters are different"

// ################################################################################################

//@version=5
strategy("Trend Following based on Trend Confidence", overlay=false )

// Inputs

source      = input(close)

since       = input(timestamp('2000-01-01'), title='Start trading interval')
till        = input(timestamp('2030-01-01'), title='End trading interval')

length      = input(30, title='Length')

longs_on    = input.bool(true, title='Longs')
shorts_on   = input.bool(true, title='Shorts')

// Parameters for best performance 2018 - 2022
// long_entry  = input.float(0.26, step=0.01, title='Long entry threshold')
// long_exit   = input.float(-0.10, step=0.01, title='Long exit threshold')
// short_entry = input.float(-0.24, step=0.01, title='Short entry threshold')
// short_exit  = input.float(-0.04, step=0.01, title='Short exit threshold')

long_entry  = input.float(0.25, step=0.01, title='Long entry threshold')
long_exit   = input.float(-0.10, step=0.01, title='Long exit threshold')
short_entry = input.float(-0.25, step=0.01, title='Short entry threshold')
short_exit  = input.float(-0.05, step=0.01, title='Short exit threshold')

stop_loss   = input.float(10, step=1, title='Stop loss (percentage)') / 100

// Trend Confidence

linreg = ta.linreg(source, length, 0)
linreg_p = ta.linreg(source, length, 0+1)

x = bar_index
slope = linreg - linreg_p
intercept = linreg - x*slope
deviationSum = 0.0
for i = 0 to length-1
    deviationSum := deviationSum + math.pow(source[i]-(slope*(x-i)+intercept), 2)
deviation = math.sqrt(deviationSum/(length))

slope_perc = slope / source[0]
deviation_perc = deviation / source[0]
trend_confidence = slope_perc / deviation_perc

// Strategy

in_interval = true

sl_long = strategy.position_avg_price * (1 - stop_loss)
sl_short = strategy.position_avg_price * (1 + stop_loss)

if in_interval and longs_on and ta.crossover(trend_confidence, long_entry)
    strategy.entry("TC Long Entry", strategy.long)
    strategy.exit("TC Long Exit", stop=sl_long)
if in_interval and longs_on and ta.crossunder(trend_confidence, long_exit)
    strategy.close("TC Long Entry")

if in_interval and shorts_on and ta.crossunder(trend_confidence, short_entry)
    strategy.entry("TC Short Entry", strategy.short)
    strategy.exit("TC Short Exit", stop=sl_short)
if in_interval and shorts_on and ta.crossover(trend_confidence, short_exit)
    strategy.close("TC Short Entry")

// Plots 

plot(trend_confidence, "Trend Confidence", color.rgb(255, 255, 255))

plot(long_entry, "", color.rgb(0, 255, 0), linewidth=1)
plot(long_exit, "", color.rgb(255, 0, 0), linewidth=1)
plot(short_entry, "", color=bar_index % 10 == 0 ? color.rgb(0, 255, 0) : #00000000, linewidth=1)
plot(short_exit, "", color=bar_index % 10 == 0 ? color.rgb(255, 0, 0) : #00000000, linewidth=1)


もっと