
この戦略の主な考えは,可能な限り正確なトレンド追跡戦略を実現することである.この戦略は,過去一定数の閉店価格の置信度を計算して,現在の線形トレンドの継続の可能性を判断する.この戦略は,信度が一定のレベルを超えると,進行中の線形トレンドが継続する可能性が高いことを仮定する.
この策略は,通常の線形回帰方法によって過去N回の閉盘価格の線形適合を計算し,その傾斜率kと閉盘価格との偏差基準差σ . を得し,その後,トレンド不信度をk/σ . と定義する.
トレンドの信頼が多入場値を超えると,多出場する. 多平仓値を下回ると,平仓する. 同様に,トレンドの信頼が空入場値を下回ると,平仓する.空平仓値を超えると,平仓する.
価格の動きが,明らかに線形的なトレンドに従わない場合,その信号をフィルターします.
この戦略は,トレンド追跡と統計学の線形回帰の方法と組み合わせて,短期的な価格変動を避け,長期的なトレンドのみに従うことで,取引頻度が低く,勝利率が高くなる.
この策略のパラメータは調整スペースが広く,パラメータを異なる品種と時間周期に適用することで,良い汎用性を達成することができる.
この戦略は,ブートレードされるリスクがあります.価格が明らかにトレンドを逆転すると,戦略は大きな損失を発生します.また,パラメータの不適切な設定は,過度取引または良い取引機会を逃す可能性があります.
損失のリスクを制御するためにストップを設定できます. 同時に,パラメータの選択を慎重に評価し,過度の最適化を避ける必要があります.
この戦略は,以下の点でさらに改善できます.
利潤を固定し,リスクをコントロールするために,ストップ・ロズ,ストップ・ストップ・ロジックを追加します.
パラメータを動的に調整できるようにモジュールを最適化します.
トレンドの転換点を判断する機械学習モデルを追加し,戦略の勝利率をさらに向上させる
異なる品種と時間帯の適応性を試し,汎用性を向上させる
この戦略は,全体として,長期トレンドをベースに,リスクを制御する量化戦略である.これは,トレンド追跡と線形回帰の方法を融合し,ノイズ取引信号をフィルターすることができる.パラメータ調整によって,それは,異なる品種と周期にうまく適応し,研究と改善を重点的に価値ある有効な戦略である.
/*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)