
MACDトレンドトラッキング戦略は,MACD指数に基づく量化取引戦略である.この戦略は,MACD指数金叉と死叉の信号を識別して,市場トレンドを判断し,株価トレンドを追跡する.
MACDのトレンドトラッキング戦略の核心的な論理は
このトレンドトラッキングにより,市場トレンドの転換を把握し,収益を上げることができます.
MACDのトレンド追跡戦略には以下の利点があります.
MACDのトレンド追跡策には以下のリスクがあります.
このリスクに対して,以下の最適化策を講じることができます.
MACDのトレンドフォロー戦略は,以下の方法で最適化できます.
MACD指標パラメータを最適化し,偽信号率を下げます.異なる周期パラメータのMACDをテストできます.
取引量を増やすなど他の指標のフィルター信号.最小取引量条件を設定できます.
ダイナミック・トラッキング・ストップ・メカニズムを設定する. ストップ・ポイントは波動率に応じてリアルタイムで調整できる.
オードを打つシグナル判定の論理を最適化する.より厳格なシグナルトリガー条件を設定することができる.
機械学習モデルと組み合わせたフィルター信号. 信号の信頼性を判断するモデルを訓練することができる.
MACDトレンドトラッキング戦略は,全体的に見ると,より成熟した量化戦略である.この戦略は,MACD指標を使用して市場トレンドの方向を判断し,ストップダストメカニズムによるリスク制御と連携し,株価トレンドを効果的に追跡することができる.しかし,MACD指標自体は,偽信号を生成しやすい一定の欠陥を有している.したがって,この戦略は,さらなる最適化の余地があり,主に指標パラメータ,ストップダストメカニズム,信号フィルタリングなどの側面に焦点を当てている.
/*backtest
start: 2023-11-10 00:00:00
end: 2023-12-10 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("MACD Cross Strategy", overlay=true)
// Get MACD values
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
var float entryLongPrice = na
var float entryShortPrice = na
var float highestLongProfit = 0
var float highestShortProfit = 0
var float highestMACD = 0
var float lowestMACD = 0
var bool haveOpenedLong = false
var bool haveOpenedShort = false
var float stoploss = 0.04 // To be adjust for different investment
var float minProfit = 0.05 // To be adjust for different investment
if macdLine > 0
lowestMACD := 0
highestMACD := math.max(highestMACD, macdLine)
haveOpenedShort := false
else
highestMACD := 0
lowestMACD := math.min(lowestMACD, macdLine)
haveOpenedLong := false
// Enter long position when MACD line crosses above the signal line
if ta.crossover(macdLine, signalLine) and macdLine < highestMACD and macdLine > 0 and haveOpenedLong == false
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", from_entry = "Long", stop=close*(1 - stoploss))
entryLongPrice := close
haveOpenedLong := true
if ta.crossunder(macdLine, signalLine) and macdLine > lowestMACD and macdLine < 0 and haveOpenedShort == false
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", from_entry = "Short", stop=close*(1 + stoploss))
entryShortPrice := close
haveOpenedShort := true
// log.info("entryLongPrice:{0}", entryLongPrice)
if strategy.position_size > 0
profit = close - entryLongPrice
log.info("profit:{0}", profit)
if profit > 0
highestLongProfit := math.max(highestLongProfit, profit)
if profit / entryLongPrice > minProfit and highestLongProfit * 0.8 > profit
strategy.close("Long")
highestLongProfit := 0
if strategy.position_size < 0
profit = entryShortPrice - close
if profit > 0
highestShortProfit := math.max(highestShortProfit, profit)
log.info("highestShortProfit={0}, profit={1}", highestShortProfit, profit)
if profit / entryShortPrice > minProfit and highestShortProfit * 0.8 > profit
strategy.close("Short")
highestShortProfit := 0