複数のEMAクロスオーバーに基づく適応型取引戦略

作者: リン・ハーンチャオチャン開催日:2023年9月26日 14:41:00
タグ:

概要

この戦略は,複数のセットのEMA指標を使用して適応型ロング/ショート取引を実施する.市場長期および短期動向に基づいて,エントリーとアウトシートの異なるパラメータを持つEMAを採用する.この戦略は,自動的にブル/ベア市場を認識し,リスクを制御するために独立したストップロスを使用する.

戦略の論理

この戦略は主にEMA指標のクロスオーバー原理を利用している.EMAが遅いEMAを超えると長,低くなると短.市場動向に基づいて複数のEMAを設定し,異なるパラメータを選択する.特に,長期トレンドが上昇傾向である場合,長い信号のために長い期間のEMAを使用する.下落期間のEMAは短に使用される.出口も異なる期間のEMAを採用する.ストップ損失はポジション方向に基づいて固定パーセントストップトライリングを使用する.

利点分析

  • 複数の適応型EMAセットが異なる市場で柔軟に動作します.
  • 雄牛と熊を区別することで 信号がより明確になります
  • 独立した入口/出口パラメータにより正確な位置付けが可能です.
  • リスクを効果的にコントロールします
  • 戦略の論理は直感的で理解し実行するのが簡単です

リスク と 改善

  • EMAは誤った信号を生成します パラメータ調整が鍵です
  • 固定ストップロスは,大きな変動を追跡できない可能性があります.
  • ボリュームのようなフィルターを追加して 頑丈さを高めます
  • マシン学習アルゴリズムで自動最適化できます
  • 固定の代わりにATRのような動的ストップ損失を使用することを検討します.

概要

この戦略は,複数のEMAクロスオーバーを活用して適応効果を達成し,EMAの優位性を維持し,戦略をより柔軟にします.適切なフィルターとダイナミックストップを追加すると,高度に実践的な自動取引システムになることができます.


/*backtest
start: 2023-08-26 00:00:00
end: 2023-09-07 00:00:00
period: 12h
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/
// © str1nger
//@version=4

// strategy(title="BTC - 4hr - Long/Short", shorttitle="BTC - 4hr - Long/Short", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=75,commission_type=strategy.commission.percent, commission_value=0.075)//////<---Uses a percentage of starting equity

//DATE RANGE//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
startDate = input(title="Start Date", type=input.integer,
     defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", type=input.integer,
     defval=1, minval=1, maxval=12)
startYear = input(title="Start Year", type=input.integer,
     defval=2020, minval=2000, maxval=2100)
endDate = input(title="End Date", type=input.integer,
     defval=1, minval=1, maxval=31)
endMonth = input(title="End Month", type=input.integer,
     defval=12, minval=1, maxval=12)
endYear = input(title="End Year", type=input.integer,
     defval=2021, minval=2000, maxval=2100)

inDateRange =  true


//EMAs//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//LONG
//11,33,3,40
lof= input(11, title="Long Open - Fast", step=1)
los= input(33, title="Long Open - Slow", step=1)
lcf= input(3, title="Long Close - Fast", step=1)
lcs= input(40, title="Long Close - Slow", step=1)
ema_long_open_fast = ema(close, lof)
ema_long_open_slow = ema(close, los)
ema_long_close_fast= ema(close, lcf)
ema_long_close_slow = ema(close, lcs)
//SHORT
//5,11,4,7
sof= input(5, title="Short Open - Fast", step=1)
sos= input(11, title="Short Open - Slow", step=1)
scf= input(4, title="Short Close - Fast", step=1)
scs= input(7, title="Short Close - Slow", step=1)
ema_short_open_fast = ema(close, sof)
ema_short_open_slow = ema(close, sos)
ema_short_close_fast = ema(close, scf)
ema_short_close_slow = ema(close, scs)


//CONDITIONS///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//LONG
openlong = crossover(ema_long_open_fast, ema_long_open_slow)
closelong = crossover(ema_long_close_slow, ema_long_close_fast)
//1.7%
long_loss_percent = input(title="Long Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=1.7) * 0.01
long_stop_price = strategy.position_avg_price * (1 - long_loss_percent)
//SHORT
openshort = crossover(ema_short_open_slow, ema_short_open_fast)
closeshort = crossover(ema_short_close_fast, ema_short_close_slow)
//0.4%
short_loss_percent = input(title="Short Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=0.4) * 0.01
short_stop_price = strategy.position_avg_price * (1 + short_loss_percent)


//PLOT EMAs////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//LONG
plot(ema_long_open_fast, "Long EMA open lower", linewidth=1, color=color.green)
plot(ema_long_open_slow, "Long EMA close upper", linewidth=1, color=color.green)
plot(ema_long_close_fast, "Long close lower", linewidth=1, color=color.red)
plot(ema_long_close_slow, "Long close upper", linewidth=1, color=color.red)
//SHORT
plot(ema_short_open_fast, "Short open fast", linewidth=1, color=color.green)
plot(ema_short_open_slow, "Short open slow", linewidth=1, color=color.green)
plot(ema_short_close_fast, "Short close fast", linewidth=1, color=color.red)
plot(ema_short_close_slow, "Short close slow", linewidth=1, color=color.red)


//LONG-TERM TRENDS
//LONG 144
long_term_trend_longs= input(144, title="Long-term trend - Longs", step=1)
lttl= ema(close, long_term_trend_longs)
plot(lttl, "Long-term trend - Longs", linewidth=2, color=color.blue)
//SHORT 89
long_term_trend_shorts= input(89, title="Long-term trend - Shorts", step=1)
ltts = ema(close, long_term_trend_shorts)
plot(ltts, "Long-term trend - Shorts", linewidth=2, color=color.blue)


//STRATEGY//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//LONG
if (inDateRange and openlong and (close > lttl))
    strategy.entry("OL", long=true, comment="##insert open long comment here##")
if (inDateRange and closelong)
    strategy.close("OL", comment="##insert close long comment here##")
if strategy.position_size > 0
    strategy.exit("L-SL", stop=long_stop_price, comment="##insert long stop-loss comment here##")
//SHORT  
if (inDateRange and openshort and (close < ltts))
    strategy.entry("OS", long=false, comment="##insert open short comment here##")
if (inDateRange and closeshort)
    strategy.close("OS", comment="##insert close short comment here##")
if strategy.position_size < 0
    strategy.exit("S-SL", stop=short_stop_price, comment="##inster short stop-loss comment here##")




もっと