0bps

Strategy vault / Momentum

MACD Momentum Strategy

The MACD Momentum Strategy is a short-term trend tracking strategy based on the MACD indicator. It utilizes MACD line and signal line crossovers to determine trend changes and capture short-term price momentum. The…

Author
ChaoZhang
Complexity
Starter · 37 lines
Parameters
0
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

The MACD Momentum Strategy is a short-term trend tracking strategy based on the MACD indicator. It utilizes MACD line and signal line crossovers to determine trend changes and capture short-term price momentum. The advantages of this strategy are its simple operation and effectiveness in tracking short-term trends. The disadvantages are frequent trading and overoptimization. Overall, the MACD Momentum Strategy suits active traders looking for short-term profits.

Strategy Logic

The strategy employs the MACD line, signal line of the MACD indicator, as well as highest and lowest prices to formulate entry, stop loss and take profit criteria.

Specifically, when the MACD line crosses above the signal line, a golden cross is formed, indicating a buy signal to go long. When the MACD line crosses below the signal line, a dead cross is formed, indicating a sell signal to close position.

The stop loss is set at the lowest price of the most recent bar, and take profit is set at the highest price of the recent 3 bars.

Advantage Analysis

  • Utilize MACD indicator to judge short-term price momentum, effectively catching short-term trends
  • Using golden cross and dead cross to generate trade signals, simple and intuitive
  • Stop loss and take profit settings help control risks
  • No need for other indicators or filters, simple and clear strategy

Risk Analysis

  • MACD indicator prone to generating false signals, may cause overtrading
  • Short-term operations susceptible to unexpected events, some irrational risks
  • Wide stop loss range may amplify losses
  • Only catching short-term trends, limited long-term profitability

Optimization methods include adjusting MACD parameters, adding filters, reducing stop loss range.

Optimization Directions

  • Adjust MACD parameters to find optimal settings
  • Add filters to avoid false signals, e.g. Bollinger Bands, candlestick patterns
  • Optimize stop loss mechanisms, e.g. trailing stop loss, staggered stop loss
  • Add trend judgment to avoid counter trend trades
  • Combine other indicators like RSI, KD to form combo strategies
  • Adjust position sizing to optimize capital utilization

Summary

The MACD Momentum Strategy is a simple short-term trend tracking strategy. It uses MACD indicator to determine price momentum changes and quickly captures short-term trends, suitable for active traders seeking short-term profits. The advantages are its simplicity and intuitive operations, but it also carries risks of overtrading and amplified losses from wide stop loss. The strategy can be enhanced through parameter tuning, adding filters, improving position sizing to further control risks and expand profitability. Overall, the MACD Momentum Strategy provides a basic short-term trend following framework and is a great starting point for algorithmic trading.

Source Pine Script

/*backtest
start: 2022-10-15 00:00:00
end: 2023-10-15 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("MACD Momentum Strategy", overlay=true)

// MACD settings
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)

// Entry criteria
enterLong = ta.crossover(macdLine, signalLine)

// Exit criteria
exitLong = ta.crossunder(macdLine, signalLine)

// Calculate stop-loss and take-profit levels
stopLossLevel = ta.lowest(low, 1)
takeProfitLevel = ta.highest(high, 3)

// Execute the strategy
if (enterLong)
    strategy.entry("Buy", strategy.long)

if (exitLong)
    strategy.close("Buy")

strategy.exit("Take Profit/Stop Loss", "Buy", loss=stopLossLevel, profit=takeProfitLevel)

// Plot the MACD and signal line
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.red, title="Signal Line")

Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-16. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/MACD-Momentum-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open