多レベルシフト移動平均取引戦略

作者: リン・ハーンチャオチャン開催日:2023年9月23日 15:55:20
タグ:

概要

多レベルシフト移動平均取引戦略は,異なるパラメータを持つ複数のシフト移動平均線を設定することで,複数のレベルで損失を入力し,停止する.戦略は最初に3つの長い線と3つの短い線を計算する.長い線が短い線を下回ると長行し,短い線が長い線を下回ると短行する.この戦略は,移動平均期,シフト比率,取引可能な時間範囲などのパラメータのカスタマイズを可能にします.中長期トレンド取引に適しています.

戦略の論理

  1. 基準線として,SRC価格のLEN期間の単純な移動平均を計算する.

  2. 長線と短線の数を長線と短線パラメータに基づいて設定します.

  3. ロングライン1等は,ロングレベル1等比に応じてベースラインを移動することによって設定されます.ショートラインは同様に設定されます.

  4. 取引可能な時間内に価格が線を越えた場合,複数のレベルでの取引をします.

  5. 価格がベースラインに触れたらストップ損失です

  6. 終止戦後,すべての位置を閉鎖します.

利点分析

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

  1. 複数のレベルでのエントリーにより 傾向の異なる段階で利益を得ることができます

  2. 異なる製品や取引スタイルのためのパラメータで高度にカスタマイズできます

  3. 移動平均値に基づいた信頼性の高いブレイクアウトシステム

  4. 取引可能な時間帯を設定することで大きなイベントを避ける.

  5. ストップ・ロスを通して損失を抑える.

リスク分析

戦略のリスクは

  1. ピラミッド型ポジションのリスクが高い 十分な資本が必要

  2. 不適切なパラメータは過剰な取引につながります

  3. 決まった出口時間は遅いトレンド利益を見逃す可能性があります.

  4. オーバーナイト・ポジションとキャリーコストは考慮されません.

  5. 位置のサイズを制御できない

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

戦略は以下の点で改善できる:

  1. 固定出口時間ではなく,ストップ損失を後押しします.

  2. オーバーナイトポジションのコストを考慮してください.

  3. 遅れの利益を得るため,ストップ損失を追加します.

  4. 動的に,現在の露出に基づいて位置をサイズします.

  5. 異なる製品でパラメータをテストし,構築最適化方法.

  6. ストップ・ロスのレベルを最適化して不要なストップを避ける

概要

多レベルシフト移動平均戦略は,移動平均に基づいて多レベルエントリを通じてトレンドから利益を得ます.取引可能な時間とストップ損失制御はリスクが良い.キャリーコスト制御,パラメータ最適化,ストップ損失最適化などのさらなる改善は戦略を向上させ,調査に値します.


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

//Noro
//2019

//@version=4
strategy(title = "Noro's ShiftMA-multi Strategy v1.1", shorttitle = "ShiftMA-multi", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 3)

//Settings
long = input(3, defval = 3, minval = 0, maxval = 3, title = "Lines for long")
short = input(3, defval = 3, minval = 0, maxval = 3, title = "Lines for short")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot")
len = input(3, minval = 1, title = "MA Length")
src = input(ohlc4, title = "MA Source")
shortlevel3 = input(15.0, title = "Short line 3")
shortlevel2 = input(10.0, title = "Short line 2")
shortlevel1 = input(5.0, title = "Short line 1")
longlevel1 = input(-5.0, title = "Long line 1")
longlevel2 = input(-10.0, title = "Long line 2")
longlevel3 = input(-15.0, title = "Long line 3")
needoffset = input(true, title = "Offset")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//Variables
size = strategy.position_size
mult = 1 / syminfo.mintick

//MA
ma = sma(src, len)
longline1 = long >= 1 ? round(ma * ((100 + longlevel1) / 100) * mult) / mult : close
longline2 = long >= 2 ? round(ma * ((100 + longlevel2) / 100) * mult) / mult : close
longline3 = long >= 3 ? round(ma * ((100 + longlevel3) / 100) * mult) / mult : close
shortline1 = short >= 1 ? round(ma * ((100 + shortlevel1) / 100) * mult) / mult : close
shortline2 = short >= 2 ? round(ma * ((100 + shortlevel2) / 100) * mult) / mult : close
shortline3 = short >= 3 ? round(ma * ((100 + shortlevel3) / 100) * mult) / mult : close

//Lines
colorlong1 = long >= 1 ? color.lime : na
colorlong2 = long >= 2 ? color.lime : na
colorlong3 = long >= 3 ? color.lime : na
colorshort1 = short >= 1 ? color.red : na
colorshort2 = short >= 2 ? color.red : na
colorshort3 = short >= 3 ? color.red : na
offset = needoffset ? 1 : 0
plot(shortline3, offset = offset, color = colorshort1)
plot(shortline2, offset = offset, color = colorshort2)
plot(shortline1, offset = offset, color = colorshort3)
plot(ma, offset = offset, color = color.blue)
plot(longline1, offset = offset, color = colorlong1)
plot(longline2, offset = offset, color = colorlong2)
plot(longline3, offset = offset, color = colorlong3)

//Trading
lot = 0.0
lot := size == 0 ? strategy.equity / close * capital / 100 : lot[1]
lots = 0.0
needtime = time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)
if ma > 0
    lots := round(size / lot)
    strategy.entry("L1", strategy.long, lot, limit = longline1, when = (lots == 0 and long >= 1 and needtime))
    lots := round(size / lot)
    strategy.entry("L2", strategy.long, lot, limit = longline2, when = (lots <= 1 and long >= 2 and needtime))
    lots := round(size / lot)
    strategy.entry("L3", strategy.long, lot, limit = longline3, when = (lots <= 2 and long >= 3 and needtime))
    
    lots := round(size / lot)
    strategy.entry("S1", strategy.short, lot, limit = shortline1, when = (lots == 0 and short >= 1 and needtime))
    lots := round(size / lot)
    strategy.entry("S2", strategy.short, lot, limit = shortline2, when = (lots >= -1 and short >= 2 and needtime))
    lots := round(size / lot)
    strategy.entry("S3", strategy.short, lot, limit = shortline3, when = (lots >= -2 and short >= 3 and needtime))
if size > 0
    strategy.entry("TPL", strategy.short, 0, limit = ma)
if size < 0
    strategy.entry("TPS", strategy.long, 0, limit = ma)
if time > timestamp(toyear, tomonth, today, 23, 59)
    strategy.close_all()

もっと