EMAとMACDに基づくBTC取引戦略

作者: リン・ハーンチャオチャン, 日付: 2024-01-25 12:54:16
タグ:

img

概要

この戦略は,短期BTC取引のためのEMA差とMACD指標に基づいた複合戦略である.EMAとMACDからの信号を組み合わせ,特定の条件下で購入および販売信号を生成する.

戦略の論理

差がマイナスで値を下回り,MACDが下落クロスオーバーを示したときに購入信号を生成する.差がマイナスで値上回り,MACDが上昇クロスオーバーを示したときに売却信号を生成する.

利点分析

  1. 複合指標を使用し,より信頼性の高い信号
  2. 短期取引に適した短期的なパラメータを採用します
  3. リスク制御のためにストップ・ロストと収益設定を行っています.

リスク分析

  1. ストップ・ロスは,巨大な市場の変動中に破られる可能性があります.
  2. パラメータは異なる市場環境に最適化する必要があります
  3. 効果は異なるコインや取引所でテストする必要があります

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

  1. BTCの変動に合わせて EMA と MACD パラメータを最適化
  2. 資本効率を向上させるために,ポジションサイズとピラミッド戦略を追加する
  3. リスクを減らすため,ストップ・ロスのストップ・ロスのようにストップ・ロスの方法を追加します.
  4. 異なる取引所とコインに対するテスト効果

結論

この戦略は,EMAとMACDの両方の指標の強みを統合し,複合信号を使用して誤った信号を効果的にフィルタリングする.最適化されたパラメータとポジション戦略により,安定したリターンを達成することができます.しかし,ストップロスのヒットなどのリスクは注意を払い,さらなるテストと改善が必要です.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-24 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("EMA50Diff & MACD Strategy", overlay=false)
EMA = input(18, step=1)
MACDfast = input(12)
MACDslow = input(26)
EMADiffThreshold = input(8)
MACDThreshold = input(80)
TargetValidityThreshold = input(65, step=5)
Target = input(120, step=5)
StopLoss = input(650, step=5) 
ema = ema(close, EMA)
hl = plot(0, color=white, linewidth=1)
diff = close - ema
clr = color(blue, transp=100)
if diff>0
    clr := lime
else 
    if diff<0
        clr := red

fastMA = ema(close, MACDfast)
slowMA = ema(close, MACDslow)
macd = (fastMA - slowMA)*3
signal = sma(macd, 9)
plot(macd, color=aqua, linewidth=2)
plot(signal, color=purple, linewidth=2)

macdlong = macd<-MACDThreshold and signal<-MACDThreshold and crossover(macd, signal)
macdshort = macd>MACDThreshold and signal>MACDThreshold and crossunder(macd, signal)
position = 0.0
position := nz(strategy.position_size, 0.0)
long = (position < 0 and close < strategy.position_avg_price - TargetValidityThreshold and macdlong) or 
     (position == 0.0 and diff < -EMADiffThreshold and diff > diff[1] and diff[1] < diff[2] and macdlong)

short = (position > 0 and close > strategy.position_avg_price + TargetValidityThreshold and macdshort) or 
      (position == 0.0 and diff > EMADiffThreshold and diff < diff[1] and diff[1] > diff[2] and macdshort)
amount = (strategy.equity / close) //- ((strategy.equity / close / 10)%10)
bgclr = color(blue, transp=100) //#0c0c0c
if long
    strategy.entry("long", strategy.long, amount)
    bgclr := green
if short
    strategy.entry("short", strategy.short, amount)
    bgclr := maroon
bgcolor(bgclr, transp=20)
strategy.close("long", when=close>strategy.position_avg_price + Target)
strategy.close("short", when=close<strategy.position_avg_price - Target)
strategy.exit("STOPLOSS", "long", stop=strategy.position_avg_price - StopLoss)
strategy.exit("STOPLOSS", "short", stop=strategy.position_avg_price + StopLoss)
//plotshape(long, style=shape.labelup, location=location.bottom, color=green)
//plotshape(short, style=shape.labeldown, location=location.top, color=red)
pl = plot(diff, style=histogram, color=clr)
fill(hl, pl, color=clr)


もっと