MACD指標に基づく二重移動平均取引戦略


作成日: 2023-12-18 12:25:13 最終変更日: 2023-12-18 12:25:13
コピー: 1 クリック数: 804
1
フォロー
1621
フォロワー

MACD指標に基づく二重移動平均取引戦略

概要

戦略はMACD双均線追跡策略MACD指数の二均線金叉死叉を取引シグナルとして使用し,昨日の最低価格をストップ・ロスのポイントとして組み合わせて,株価の短線移動を追跡する.

戦略原則

  1. 速線EMA ((close,5),遅線EMA ((close,8),信号線SMA ((MACD,3) を計算する
  2. 多頭信号を定義する:高速線で遅線を横切る時に多行
  3. 空頭シグナルを定義する: 速線の下のスローラインを突破するか,当日の閉店価格が昨日の最低価格より低ければ空頭する
  4. 保有額は,初期資金2000ドルを終了価格で割る
  5. 多頭ストップ使用 空頭信号平仓

優位分析

  1. MACD指標を用いて,市場の超買超売領域を判断し,双均線形成の取引信号と協働し,偽突破を避ける
  2. 短期的なトレンドを追跡し,時効的に止めてください.
  3. ポジションの動的調整,単一の損失を避ける

リスク分析

  1. MACDインディケーターが遅れているため,ショートラインのチャンスを逃している可能性がある.
  2. 双対線取引信号は偽信号を生成する可能性があります.
  3. ストップポイントが過度に激しく,過度に頻繁にストップする可能性があります.

最適化の方向

  1. MACDパラメータの組み合わせを最適化し,指標の感性を向上させる
  2. 市場を動揺させないためにトレンド判断を高めましょう.
  3. 変動指数と相まって市場の変動率を評価し,ストップポイントを調整します.

要約する

この戦略は,古典的なMACD双均線組合せ指標を使用して,超買い超売り区間を判断し,取引シグナルを生成し,同時に,ダイナミックなポジション保有量と前日の最低価格の止損点設計を導入し,株価のショートライン波動特性をキャプチャし,全体的な戦略の考え方は明確で分かりやすく,さらなるテストと最適化の価値があります.

ストラテジーソースコード
/*backtest
start: 2023-12-10 00:00:00
end: 2023-12-13 02:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
// macd/cam v1 strategizing Chris Moody Macd indicator https://www.tradingview.com/script/OQx7vju0-MacD-Custom-Indicator-Multiple-Time-Frame-All-Available-Options/
// macd/cam v2 changing to macd 5,8,3
// macd/cam v2.1 
//      Sell when lower than previous day low. 
//      Initial capital of $2k. Buy/sell quantity of initial capital / close price
//      Quitar short action
//      Note: custom 1-week resolution seems to put AMD at 80% profitable

strategy(title="MACD/CAM 2.1", shorttitle="MACD/CAM 2.1") //
source = close
//get inputs from options
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above", defval="60")
smd = input(true, title="Show MacD & Signal Line? Also Turn Off Dots Below")
sd = input(true, title="Show Dots When MacD Crosses Signal Line?")
sh = input(true, title="Show Histogram?")
macd_colorChange = input(true,title="Change MacD Line Color-Signal Line Cross?")
hist_colorChange = input(true,title="MacD Histogram 4 Colors?")
venderLowerPrev = input(true,title="Vender cuando closing price < previous day low?")

res = useCurrentRes ? timeframe.period : resCustom

fastLength = input(5, minval=1), slowLength=input(8,minval=1)
signalLength=input(3,minval=1)

// find exponential moving average of price as x and fastLength var as y
fastMA = ema(source, fastLength)
slowMA = ema(source, slowLength)

macd = fastMA - slowMA
// simple moving average
signal = sma(macd, signalLength)
hist = macd - signal

outMacD = request.security(syminfo.tickerid, res, macd)
outSignal = request.security(syminfo.tickerid, res, signal)
outHist = request.security(syminfo.tickerid, res, hist)

histA_IsUp = outHist > outHist[1] and outHist > 0
histA_IsDown = outHist < outHist[1] and outHist > 0
histB_IsDown = outHist < outHist[1] and outHist <= 0
histB_IsUp = outHist > outHist[1] and outHist <= 0

//MacD Color Definitions
macd_IsAbove = outMacD >= outSignal
macd_IsBelow = outMacD < outSignal

plot_color = hist_colorChange ? histA_IsUp ? aqua : histA_IsDown ? blue : histB_IsDown ? red : histB_IsUp ? maroon :yellow :gray
macd_color = macd_colorChange ? macd_IsAbove ? lime : red : red
signal_color = macd_colorChange ? macd_IsAbove ? yellow : yellow : lime

circleYPosition = outSignal
 
plot(smd and outMacD ? outMacD : na, title="MACD", color=macd_color, linewidth=4)
plot(smd and outSignal ? outSignal : na, title="Signal Line", color=signal_color, style=line ,linewidth=2)
plot(sh and outHist ? outHist : na, title="Histogram", color=plot_color, style=histogram, linewidth=4)

circleCondition = sd and cross(outMacD, outSignal)

// Determine long and short conditions
longCondition  = circleCondition and macd_color == lime

redCircle = circleCondition and macd_color == red
redCirclePrevLow = redCircle or low<low[1]
shortCondition = redCircle
if (venderLowerPrev)
    shortCondition = redCirclePrevLow

strategy.initial_capital = 20000
// Set quantity to initial capital / closing price
cantidad = strategy.initial_capital/close

// Submit orders
strategy.entry(id="long", long=true, qty=cantidad, when=longCondition)
strategy.close(id="long", when=shortCondition)
plot(circleCondition ? circleYPosition : na, title="Cross", style=cross, linewidth=10, color=macd_color)
// hline(0, '0 Line', linestyle=solid, linewidth=2, color=white)