スウィング・トレーディング戦略

作者: リン・ハーンチャオチャン,日付: 2023年10月11日 16:29:37
タグ:

概要

これは移動平均のクロスオーバーに基づいたトレンドフォロー戦略で,ストップ損失/取利益管理とレバレッジ効果を組み合わせて,複数の市場のトレンドを特定し,利益を最大化することを目的としています.

戦略の論理

この戦略は,快速移動平均値とスロー移動平均値のクロスオーバーを取引信号として使用する. 速いMAがスローMAを超えると長くなり,速いMAがスローMAを下回ると短くなります.

小規模なトレンドからノイズトレードをフィルタリングするために,トレンドフィルターとして200日MAも使用します.価格が200日MA以上または下にある場合にのみトレードシグナルが生成されます.

この戦略はレンジ取引ストップを使用する.エントリー後,固定パーセントストップ損失と利益のレベルが設定されます.例えば,1%ストップ損失と1%利益を取ります.価格がストップ損失または利益を取るとポジションは閉鎖されます.

レバレッジ効果は,取引利益を増強するために用いられる.異なる市場の特徴に基づいて,適切なレバレッジ比率を選択することができる.例えば10倍.

利点分析

  • 仮想通貨,株式,先物など複数の市場のトレンドを特定でき,戦略を広く適用できるという利点があります

  • 急速/遅いMAクロスオーバーとトレンドフィルタを使用することで,トレンド方向をより正確に特定し,トレンド市場での良い勝利率を達成することができます.

  • 範囲取引停止は,対応可能な範囲内で単一の取引損失を制御し,戦略の安定した実行を可能にします.

  • 利息効果は取引利益を拡大し,戦略の利点を最大限に活用します

  • ビール・ベア市場では 異なる背景色で 視覚的なインターフェースを設計することで 市場を直感的に把握できます

リスク分析

  • 戦略は傾向に準拠しているため,波動が激しい,レンジ・バインド市場では劣る可能性があります. ポジションサイズを制御する必要があります.

  • 固定パーセントのストップ・ロスト/テイク・プロフィートは,ストップ・アウトされる危険性がある.レベルは,特定の市場の変動に基づいて調整されるべきである.

  • レバレッジは,ポジションの大きさだけでなくリスクも増幅します.過剰な損失を避けるためにレバレッジ比を制御する必要があります.

  • 移動平均値の遅延は,取引信号の遅延を引き起こす可能性があります.

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

  • 異なるパラメータの組み合わせをテストし,最適な高速/遅いMA長さを選択する.

  • 精度を向上させるため,他の指標やモデルをフィルター信号として組み込む.例えば,ATR停止,RSIなど.

  • ADXのような他のトレンド識別ツールを探求し,トレンドキャプチャ能力をさらに強化します.

  • 戦略信号を最適化し,より効果的なエントリー/出口ポイントを見つけるために機械学習モデルを使用します.

  • より合理的なストップをするために,変動と市場条件に基づいて動的ストップ・ロスト/テイク・プロフィートを考慮してください.

概要

この戦略は,体系的なトレンドフォローアプローチを採用し,リスクを制御し利益を増大するためにストップ/テイク・プロフィートとレバレッジを使用する.安定アルファの可能性のある市場では広く適用される.長期的成功のためにパラメータ最適化,リスク制御,戦略繰り返しを注意すべきである.


/*backtest
start: 2023-09-10 00:00:00
end: 2023-10-10 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

////////////////////////////////////////////////////////////////////////////////
// Bozz Strategy
// Developed for Godstime
// Version 1.1
// 11/28/2021
////////////////////////////////////////////////////////////////////////////////

//@version=4
// strategy("Bozz Strategy", "", true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, margin_long=0, margin_short=0)

// ----------------------------- Inputs ------------------------------------- //
source_ma_type = input("EMA", "Source MA Type", options=["SMA", "EMA"])
source_ma_length = input(50, "Source MA Length")
fast_ma_length = input(20, "Fast MA Length")
slow_ma_length = input(50, "Slow MA Length")
use_trend_filter = input(true, "Trend Filter")
trend_filter_ma_type = input("EMA", "Trend Filter MA Type", options=["SMA", "EMA"])
trend_filter_ma_length = input(200, "Trend Filter MA Period")
show_mas = input(true, "Show MAs")
swing_trading_mode = input(false, "Swing Trading")

// -------------------------- Calculations ---------------------------------- //
fast_ma = ema(close, fast_ma_length)
slow_ma = ema(close, slow_ma_length)
source_ma = source_ma_type == "EMA"? ema(close, source_ma_length): 
                                     sma(close, source_ma_length)
trend_filter_ma = trend_filter_ma_type == "EMA"? ema(close, trend_filter_ma_length): 
                                                 sma(close, trend_filter_ma_length)

// --------------------------- Conditions ----------------------------------- //
uptrend = not use_trend_filter or close > trend_filter_ma
buy_cond = crossover(fast_ma, slow_ma) and uptrend

downtrend = not use_trend_filter or close < trend_filter_ma
sell_cond = crossunder(fast_ma, slow_ma) and downtrend

// ---------------------------- Plotting ------------------------------------ //
bgcolor(use_trend_filter and downtrend? color.red: use_trend_filter? color.green: na)
plot(show_mas? fast_ma: na, "Fast MA", color.green)
plot(show_mas? slow_ma: na, "Slow MA", color.red)
plot(show_mas? source_ma: na, "Source MA", color.purple)
plot(show_mas? trend_filter_ma: na, "Trend Filter MA", color.blue)


// ---------------------------- Trading  ------------------------------------ //
// Inputs
sl_perc = input(1.0, "Stop Loss (in %)", group="Backtest Control")/100
tp_perc = input(1.0, "Take Profit (in %)", group="Backtest Control")/100
leverage = input(10, "Leverage", maxval=100, group="Backtest Control")
bt_start_time = input(timestamp("2021 01 01"), "Backtest Start Time", input.time, group="Backtest Control")
bt_end_time = input(timestamp("2021 12 31"), "Backtest End Time", input.time, group="Backtest Control")

// Trading Window
in_trading_window = true
trade_qty = (strategy.equity * leverage) / close 

// Long Side
strategy.entry("Long Entry", strategy.long,  when=buy_cond and in_trading_window)
long_tp = strategy.position_avg_price * (1 + tp_perc)
long_sl = strategy.position_avg_price * (1 - sl_perc)
if not swing_trading_mode
    strategy.exit("Long Exit", "Long Entry", limit=long_tp, stop=long_sl)

// Short Side
strategy.entry("Short Entry", strategy.short, when=sell_cond and in_trading_window)
short_tp = strategy.position_avg_price * (1 - tp_perc)
short_sl = strategy.position_avg_price * (1 + sl_perc)
if not swing_trading_mode
    strategy.exit("Short Exit", "Short Entry", limit=short_tp, stop=short_sl)

// End of trading window close
strategy.close_all(when=not in_trading_window)

もっと