高速および低速のデュアル移動平均取引戦略


作成日: 2023-10-27 16:41:24 最終変更日: 2023-10-27 16:41:24
コピー: 0 クリック数: 464
1
フォロー
1237
フォロワー

高速および低速のデュアル移動平均取引戦略

概要

双均線取引戦略は,高速移動平均と遅い移動平均を計算し,両移動平均の交差状況に基づいて取引信号を生成する.高速移動平均の上に遅い移動平均を横切るときは,多頭戦略をとり,高速移動平均の下に遅い移動平均を横切るときは,空頭戦略をとり.この戦略は,トレンド取引にも,逆転取引にも使用できます.

戦略原則

この戦略は,まず,高速移動平均の長さを fastLength と遅い移動平均の長さを maSlowLength と設定する. そして,高速移動平均の fastMA と遅い移動平均の slowMA を計算する. 急速移動平均は価格の変化に敏感で,現在のトレンドを判断するために使用できます. 遅い移動平均は価格の変化に反応して,トレンドの方向を判断するために使用できます.

速い移動平均線上をゆっくり移動平均線を横切るとき,多策をとり,goLong () 信号を生じます. 速い移動平均線の下をゆっくり移動平均線を横切るとき,平仓を多頭にして,killLong () 信号を生じます.

longonly,shorting,または両方向の取引のスワッピングを選択できます.

多策策を行うとき,goLong() 信号が出る時に多ポジションを;killLong() 信号が出る時に平ポジションを.

空き策では,killLong () 信号が出る時に空きを入れ,goLong () 信号が出る時に平仓する.

双方向取引では,goLong () 信号が出たときに多ポジションを開く.killLong () 信号が出たときに多ポジションを平にして空ポジションを開く.

また,ストップ,ストップトラッキング,取引通知の提示などの機能が設定され,使用するかどうかを柔軟に選択できます.

戦略的優位性

  1. 戦略はシンプルで理解し,実行しやすい.

  2. 選択するのも自由です.

  3. リスク管理機能の選択の柔軟性がある.

  4. 顧客が顧客に直接連絡し,顧客が顧客に連絡し,顧客が顧客に連絡し,顧客が顧客に連絡し,顧客が顧客に連絡し,

  5. 市場動向の変化に敏感で,より強いトレンドを捉えることができる.

  6. 戦略のパラメータは調整可能で,異なる市場に対応してパラメータを調整できます.

戦略リスク

  1. 市場が明らかにトレンドしていないとき,偽のシグナルが多く現れ,過剰取引を引き起こします.

  2. 均線システムは突発事件への反応に敏感で,突発の機会を逃す可能性があります.

  3. 平均線パラメータの合理的な選択が必要で,パラメータの選択が不適切である場合,戦略の効果に影響する.

  4. 任意の取引を避けるため,戦略信号を厳格に遵守する必要があります.

  5. 取引コストが戦略の収益性に影響を及ぼすことに注目する必要があります.

戦略最適化の方向性

  1. RSIなどの他の指標を導入することで,取引信号を検証し,誤った信号を発生させないようにすることができます.

  2. パラメータ最適化機能が設定され,最適なパラメータの組み合わせを自動的に探すことができます.

  3. ダイナミックストップを設定して,利潤をロックし,適切な時にストップポイントを調整できます.

  4. 機械学習のモデルを組み込むことでトレンドの方向性を判断できます.

  5. メッセージの提示機能を最適化して,自分の取引習慣に合わせることができます.

要約する

二線均一取引戦略は,全体的に比較してシンプルで実用的で,市場傾向の変化に敏感で,より強い傾向がもたらす取引機会を捉えることができる.しかし,傾向のない市場の誤取引を防ぐことに注意し,異なる市場環境に対応するためにパラメータを適切に調整する必要があります.さらに,適切な補助技術指標と最適化機能を追加することで,戦略の安定性と適応性をさらに高めることができます.

ストラテジーソースコード
/*backtest
start: 2022-10-20 00:00:00
end: 2023-10-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

strategy("SMA Strategy", shorttitle="SMA Strategy", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// === Inputs ===
// short ma
maFastSource = input(defval=close, title="Fast MA Source")
maFastLength = input(defval=3, title="Fast MA Period", minval=1)

// long ma
maSlowSource = input(defval=close, title="Slow MA Source")
maSlowLength = input(defval=9, title="Slow MA Period", minval=1)

// Trade direction
shorting = input(defval=false, title="Short only?")
longonly = input(defval=true, title="Long only?")
swapping = input(defval=false, title="Swap orders?")
// risk management
useStop = input(defval=false, title="Use Initial Stop Loss?")
slPoints = input(defval=25, title="Initial Stop Loss Points", minval=1)
useTS = input(defval=false, title="Use Trailing Stop?")
tslPoints = input(defval=120, title="Trail Points", minval=1)
useTSO = input(defval=false, title="Use Offset For Trailing Stop?")
tslOffset = input(defval=20, title="Trail Offset Points", minval=1)

// Messages for buy and sell
message_long_entry  = input("Long entry message", title="Long entry message")
message_long_exit   = input("Long exit message", title="Long exit message")
message_short_entry = input("Short entry message", title="Short entry message")
message_short_exit  = input("Short exit message", title="Short exit message")

// Calculate start/end date and time condition
startDate  = input(timestamp("2021-01-01T00:00:00"), type = input.time)
finishDate = input(timestamp("2021-12-31T00:00:00"), type = input.time)
 
time_cond  = true
// === Vars and Series ===
fastMA = sma(maFastSource, maFastLength)
slowMA = sma(maSlowSource, maSlowLength)

plot(fastMA, color=color.blue)
plot(slowMA, color=color.purple)

goLong() =>
    crossover(fastMA, slowMA)
killLong() =>
    crossunder(fastMA, slowMA)
    
// Long only
if longonly
    strategy.entry("Buy", strategy.long, when=goLong() and time_cond, alert_message = message_long_entry)
    strategy.close("Buy", when=killLong() and time_cond, alert_message = message_long_exit)

// Short only
if shorting
    strategy.entry("Sell", strategy.short, when=killLong() and time_cond, alert_message = message_short_entry)
    strategy.close("Sell", when=goLong() and time_cond, alert_message = message_short_exit)
    
// Order Swapping
if swapping
    strategy.entry("Buy", strategy.long, when=goLong() and time_cond, alert_message = message_long_entry)
    strategy.entry("Sell", strategy.short, when=killLong() and time_cond, alert_message = message_short_entry)

if useStop
    strategy.exit("XLS", from_entry="Buy", stop=strategy.position_avg_price / 1.08, alert_message = message_long_exit)
    strategy.exit("XSS", from_entry="Sell", stop=strategy.position_avg_price * 1.08, alert_message = message_short_exit)