
この戦略は,指数移動平均 (EMA) と移動平均傾向/偏移 (MACD) の指標を組み合わせた定量化取引システムである.短期および長期のEMAの交差信号を統合し,MACDの動態を確認することで,トレーダーに包括的なトレンド追跡ソリューションを提供します.この戦略には,ダイナミックなストップとストップのメカニズムが含まれています.
戦略の核心的な論理は,2つの技術指標の協同作用に基づいています. 第一に,12周期と26周期のEMAを使用して市場トレンドを識別し,短期EMAの上部に長期EMAを突破すると多調信号が発生し,下部に長期EMAを突破すると空調信号が発生します. 第二に,MACD指標 ((12,26,9設定) を使用してトレンドの動力を確認し,MACDラインとラインのシグナルの位置関係がEMAから生成される取引信号をサポートします. システムは,ダイナミックストップ損失 ((デフォルト2%) とストップオフのデフォルト ((5%) をパーセント方式で設定し,EMAの交差またはMACDを反転して追加のポジションシグナルを誘発します.
これは,合理的で論理的に明確なトレンド追跡戦略を設計したものです. 戦略を簡潔に理解しながら,EMAとMACDの優位性を組み合わせることで,より信頼性の高い取引信号生成を実現しています. 戦略のカスタマイズ性が強く,リスク管理機構は完善し,中長期のトレンド取引の基本的枠組みに適合しています. 交易者は,現場で使用する前に,パラメータ設定を十分にテストし,特定の取引品種と市場環境に応じてターゲットに最適化することをお勧めします.
/*backtest
start: 2025-01-21 00:00:00
end: 2025-02-03 15:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("EMA + MACD Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === Inputs ===
shortEmaLength = input.int(12, title="Short EMA Period", minval=1)
longEmaLength = input.int(26, title="Long EMA Period", minval=1)
macdFastLength = input.int(12, title="MACD Fast EMA Period", minval=1)
macdSlowLength = input.int(26, title="MACD Slow EMA Period", minval=1)
macdSignalLength = input.int(9, title="MACD Signal Period", minval=1)
stopLossPerc = input.float(2.0, title="Stop-Loss (%)", minval=0.1, step=0.1)
takeProfitPerc = input.float(5.0, title="Take-Profit (%)", minval=0.1, step=0.1)
// === Indicator Calculations ===
// Exponential Moving Averages (EMA)
shortEMA = ta.ema(close, shortEmaLength)
longEMA = ta.ema(close, longEmaLength)
// MACD
[macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength)
// === Entry Conditions ===
// Buy signal: Short EMA crosses above Long EMA and MACD > Signal Line
longCondition = ta.crossover(shortEMA, longEMA) and (macdLine > signalLine)
// Sell signal: Short EMA crosses below Long EMA and MACD < Signal Line
shortCondition = ta.crossunder(shortEMA, longEMA) and (macdLine < signalLine)
// === Entry Signals with Stop-Loss and Take-Profit ===
if (longCondition)
strategy.entry("Long", strategy.long)
// Calculate Stop-Loss and Take-Profit
stopPrice = close * (1 - stopLossPerc / 100)
takePrice = close * (1 + takeProfitPerc / 100)
strategy.exit("Long Exit", from_entry="Long", stop=stopPrice, limit=takePrice)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Calculate Stop-Loss and Take-Profit
stopPrice = close * (1 + stopLossPerc / 100)
takePrice = close * (1 - takeProfitPerc / 100)
strategy.exit("Short Exit", from_entry="Short", stop=stopPrice, limit=takePrice)
// === Exit Conditions ===
// Alternative exit conditions based on crossovers
exitLongCondition = ta.crossunder(shortEMA, longEMA) or (macdLine < signalLine)
exitShortCondition = ta.crossover(shortEMA, longEMA) or (macdLine > signalLine)
if (exitLongCondition)
strategy.close("Long")
if (exitShortCondition)
strategy.close("Short")
// === Indicator Plotting ===
// EMA
plot(shortEMA, color=color.blue, title="Short EMA")
plot(longEMA, color=color.red, title="Long EMA")
// MACD Indicator in separate window
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_dotted)
plot(macdLine - signalLine, color=(macdLine - signalLine) >= 0 ? color.green : color.red, title="MACD Histogram", style=plot.style_histogram)
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.orange, title="Signal Line")
// === Signal Visualization ===
// Markers for Long and Short entries
plotshape(series=longCondition, title="Long Entry", location=location.belowbar, color=color.green, style=shape.labelup, text="Long")
plotshape(series=shortCondition, title="Short Entry", location=location.abovebar, color=color.red, style=shape.labeldown, text="Short")
// Markers for Long and Short exits
plotshape(series=exitLongCondition, title="Long Exit", location=location.abovebar, color=color.red, style=shape.labeldown, text="Exit Long")
plotshape(series=exitShortCondition, title="Short Exit", location=location.belowbar, color=color.green, style=shape.labelup, text="Exit Short")