スーパートレンド戦略

作者: リン・ハーンチャオチャン, 日付: 2024-02-02 11:11:48
タグ:

img

概要

この戦略は,価格動向を決定するためにスーパートレンド指標を使用し,トレンドが変化するとロングまたはショートポジションに入ります.この戦略は,パラメータを最適化するためにATR期間と倍数値を調整することができます.また,少し異なる結果のためにATR計算方法を変更するオプションを提供します.

この戦略は,バックテスト日付範囲と,日中の特定の時間内にのみ取引し,その時間枠の終わりにすべての取引を終了する機能が組み込まれています. これは,日取引株にとって特に有用です. タイムフレームオプションが有効になると,タイムフレームが始まるとすぐに現在のポジションを入力するか,最初のポジションに入るためにトレンド変化を待つことができます.

ストップ・ロスは,ストップ・ロスは,ストップ・ロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストップロスは,ストロスは,ストロスは,ストロスは,ストロスは,ストロスは,スト

最後に,自動取引サービスで使用される入力および終了メッセージのためのカスタムアラートフィールドがあります.

戦略の論理

スーパートレンド戦略は以下の基本原則に基づいています

  1. ATR値を計算する: SMA計算または組み込みATR指標を選択できます. SMA公式:

    atr2 = sma(tr, Periods)
    
  2. 上部と下部帯を計算します.上部帯は,マイナスATR倍数×ATRに近くなっています.下部帯は,近くなっています.プラス倍数×ATRです.

    up = close - (Multiplier * atr) 
    dn = close + (Multiplier * atr)
    
  3. 価格を帯と比較してトレンド方向を決定する.価格が下帯を超えると上昇傾向.価格が上帯を超えると下傾向.

    trend := trend == -1 and close > dn ? 1 : trend == 1 and close < up ? -1 : trend
    
  4. トレンド変化に関する取引信号を生成する.例えば,上向きから下向きに変化するときに売り信号を生成する.

    sellSignal = trend == -1 and trend[1] == 1 
    
  5. シグナルと追加条件に基づいて入力をフィルターします.

  6. ストップ・ロストと 利得を取って 利益を固定したり リスクを制限したりします

これはSupertrend戦略の裏にある主要な原理です.パラメータ最適化と組み合わせると,良い取引結果を生むことができます.

利点

スーパートレンド戦略にはいくつかの利点があります.

  1. スーパートレンド自体は,トレンドを効果的に識別し,通常トレーリングストップに使用されます.

  2. パーソナライズ可能なATRパラメータは,最適なフィットのために製品間で最適化することができます. SMA計算は別のオプションを提供します.

  3. 設定可能なバックテストとライブ取引時間の範囲は,異なる取引セッションに適しています.

  4. 最初の取引を即座に開始するか,シグナルを待つオプションは,異なる製品に対応します.

  5. ストップ・ロストとテイク・プロフィートの組み込みは リスク管理を改善したり 利益を増やすのに役立ちます

  6. 自動取引システムとボットとの統合のためのカスタマイズ可能な取引アラート.

リスク

考慮すべきリスクもいくつかあります.

  1. スーパートレンドは誤った信号を生成し 追加の条件でフィルタリングする必要があります

  2. 誤ったATRパラメータは,過剰な取引またはトレンドの欠落につながる可能性があります.最適なバランスのために最適化が必要です.

  3. ストップ・ロスは 利潤のある取引から早急に退場する可能性があります 利潤を取ることは 余裕がない場合 お金を失ってしまう可能性があります

  4. 時間枠の設定が不十分であれば 取引セッションを逃したり 余計な利回りを得ることもできます

これらのリスクは,パーマータを適切に調整したり,安定性を向上させるための追加のフィルターで対処することができます.

最適化 の 機会

戦略をさらに最適化できるいくつかの方法:

  1. 適切なバランスを見つけるために異なるATR期間をテストします 通常は10〜20がうまく機能します

  2. 異なるATR倍数値を試す 2-5は通常適切で 最適な値を見つけるために調整します

  3. MACD,RSIなどのフィルターを追加して 誤った信号を減らします

  4. ストップ・ロストを最適化し,最高の結果を得るため,利益レベルを取ります. ダイナミック・トラッキング・メカニズムを考えてください.

  5. 異なる取引時間帯をテストします.より短い期間は,日中および高周波戦略に適しています.

  6. 自動シンボルの選択を実行して,高いモメンタムや波動を追跡する.

結論

一般的に,これはかなり一般的な実践的なトレンドフォロー戦略である. 効率的にカスタマイズ可能なパラメータでトレンドを追跡するが,管理する固有のリスクも有する. 最適化と追加の条件により,一貫したアルファを持つ堅牢な量子取引システムに精製することができる.


/*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 source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © REV0LUTI0N

//@version=4

// Strategy
strategy("Supertrend Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)
Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
enableentry = input(true, title="Enter First Trade ASAP")
waitentry = input(false, title="Wait To Enter First Trade")

atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
Long = (trend == 1 ? up : na)
buySignal = trend == 1 and trend[1] == -1

dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
Short = (trend == 1 ? na : dn)
sellSignal = trend == -1 and trend[1] == 1

// Strategy Backtesting
startDate  = input(timestamp("2021-01-01T00:00:00"), type = input.time, title='Backtesting Start Date')
finishDate = input(timestamp("2021-12-31T00:00:00"), type = input.time, title='Backtesting End Date')

time_cond  = true

//Time Restriction Settings
startendtime = input("", title='Time Frame To Enter Trades')
enableclose = input(false, title='Enable Close Trade At End Of Time Frame')
timetobuy = (time(timeframe.period, startendtime))
timetoclose = na(time(timeframe.period, startendtime))

// Stop Loss & Take Profit % Based
enablesl = input(false, title='Enable Stop Loss')
enabletp = input(false, title='Enable Take Profit')
stopTick = input(5.0, title='Stop Loss %', type=input.float, step=0.1) / 100
takeTick = input(10.0, title='Take Profit %', type=input.float, step=0.1) / 100

longStop = strategy.position_avg_price * (1 - stopTick)
shortStop = strategy.position_avg_price * (1 + stopTick)
shortTake = strategy.position_avg_price * (1 - takeTick)
longTake = strategy.position_avg_price * (1 + takeTick)

plot(strategy.position_size > 0 and enablesl ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 and enablesl ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
plot(strategy.position_size > 0 and enabletp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")
plot(strategy.position_size < 0 and enabletp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")

// Alert messages
message_enterlong  = input("", title="Long Entry message")
message_entershort = input("", title="Short Entry message")
message_closelong = input("", title="Close Long message")
message_closeshort = input("", title="Close Short message")

// Strategy Execution
if Long and time_cond and timetobuy and enableentry
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
    
if Short and time_cond and timetobuy and enableentry
    strategy.entry("Short", strategy.short, alert_message = message_entershort)
    
if buySignal and time_cond and timetobuy and waitentry
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
    
if sellSignal and time_cond and timetobuy and waitentry
    strategy.entry("Short", strategy.short, alert_message = message_entershort)
    
if strategy.position_size > 0 and timetoclose and enableclose
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and timetoclose and enableclose
    strategy.close_all(alert_message = message_closeshort)
    
if strategy.position_size > 0 and enablesl and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enablesl and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)
    
if strategy.position_size > 0 and enabletp and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enabletp and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)






もっと