スーパートレンド戦略に基づく


作成日: 2024-02-02 11:11:48 最終変更日: 2024-02-02 11:11:48
コピー: 0 クリック数: 782
1
フォロー
1617
フォロワー

スーパートレンド戦略に基づく

概要

この策略は,価格の傾向を判断するために超トレンド指標を使用し,トレンドが変化したときに多額の取引または短額の取引に入ります. この策略は,ATR周期とATR倍数を調整してパラメータを最適化することができます. さらに,この策略は,ATR計算方法を変更して,わずかに異なる結果を生成するオプションも提供しています.

また,戦略には,日時範囲設定と特定の時間帯内での取引のみの機能が内蔵されている.これは,日内取引の株式に特に有用である.時間帯オプションを有効にすると,時間帯の開始時にすぐに現在のポジションに入ることを選択するか,トレンドの転換後に最初の順位に入ることを選択することができます.

この戦略は,パーセントに基づいてストップとストップを設定することもできます.ほとんどの場合,超トレンド自体が提供するATRベースのストップのため,追加のストップを設定する必要はありません.したがって,退出メカニズムを最適化するためにストップのみを有効にすることができます.

最後に,この戦略は,自動取引サービスで使用できるカスタマイズされた取引入場と退出のアラート情報機能を持っています.

戦略原則

超トレンド戦略は以下の基本原理に基づいて動作します.

  1. ATR値の計算:SMA計算を使用する選択があり,内蔵されたATR指標を使用することもできます. SMAバージョンの公式は:
   atr2 = sma(tr, Periods) 
  1. 上線と下線を計算する.上線は価格とATRの倍数,下線は価格とATRの倍数,ATRの倍数.
   up = close - (Multiplier * atr)
   dn = close + (Multiplier * atr)
  1. 価格と上下軌道の関係を判断し,トレンドの方向を計算する。価格が上下軌道を突破する時は多頭トレンドであり,価格が下下軌道を突破する時は空頭トレンドである。
   trend := trend == -1 and close > dn ? 1 : trend == 1 and close < up ? -1 : trend 
  1. トレンド転換時に取引シグナルを生成する,例えば多頭から空頭に転換する時に売り出しシグナルを生成する:
   sellSignal = trend == -1 and trend[1] == 1
  1. 取引シグナルやその他の条件によってフィルタリングされ,入場かどうかを選択する.

  2. 利潤を固定したりリスクを回避するために,ストップとストップを設定します.

これは超トレンド戦略の重要なポイントであり,パラメータの最適化と組み合わせて,より良い取引結果を得ることができます.

戦略的優位性

この戦略は以下の利点があります.

  1. 超トレンド指数は,価格の動向を判断するのに有効であり,常用ストップ・トラッキングツールである.

  2. ATRパラメータは調整可能で,異なる品種に最適なパラメータの組み合わせを得るために最適化できます.SMA計算方法も別の選択肢を提供します.

  3. 回測と实体取引の時間帯を設定し,異なる取引時間のニーズに適応します.

  4. 品種特性に応じて,ファースト・リストに即座に入るか,信号を待つかの選択肢を提供する.

  5. 内蔵のストップ・ストップ設定は,戦略のリスク抵抗性を向上させたり,より多くの利益をロックさせたりできます.

  6. カスタマイズされた取引提示情報は,自動化またはロボット取引システムに統合され,無人監視を実現します.

戦略リスク

この戦略にはいくつかのリスクがあります.

  1. 超トレンド指標は偽信号を多く発生させ,他の指標と組み合わせたフィルタリングが必要である.

  2. ATRパラメータが不適切である場合,取引の頻度やトレンドを逃す可能性があります.最適のバランスを得るためにパラメータを最適化する必要があります.

  3. ストップ・ロスの近くでは,有利なポジションから早めに撤退し,ストップ・ロスの近くでは,十分な利益を得られない可能性があります.

  4. タイムスケープの設定が不適切で,主要取引時間を逃したり,保証金を無駄に占めることもあります.

上記のリスクに対して,適切なパラメータの調整またはフィルタリング条件の追加で対処することができ,戦略の安定性を高めることができます.

戦略最適化の方向性

この戦略は,以下の点でさらに最適化できます.

  1. 異なるATR周期パラメータを試して,適切なバランスポイントを見つけます.一般的には10-20の間の比較が理想的です.

  2. 異なるATR倍数パラメータをテストし,一般的には2-5が適している.最適値を見つけるために段階的に調整することができる.

  3. 偽信号をフィルタリングするために,MACD,KDなどの多空方向性を判断する他の指標を追加してみてください.

  4. 止損停止パラメータを最適化して,最適なパラメータの組み合わせを見つけます. 動的止損停止を導入できます.

  5. 異なる取引時間帯の設定をテストする. 短時間帯に適した日内ショートラインの品種.

  6. 自動で契約を選択し,流動性や波動性の高い指数を追跡してみてください.

要約する

この超トレンド戦略は,全体として,より一般的で実用的なトレンド追跡戦略である. それは,パラメータが調節可能であり,効率的なトレンド追跡の特徴を有し,また,回避する必要がある一定のリスクがある.パラメータ最適化とCONDITIONSを追加することにより,この戦略を,信頼性の高い定量取引システムに最適化して,安定したAlphaを取得することができます.

ストラテジーソースコード
/*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)