Strategy vault / Mean reversion
MACD Long Reversal Strategy
The MACD long reversal strategy is a strategy that utilizes the MACD indicator to identify long-term price reversals and makes long-term trades. This strategy constructs the MACD indicator using the fast SMA line and…

Overview
The MACD long reversal strategy is a strategy that utilizes the MACD indicator to identify long-term price reversals and makes long-term trades. This strategy constructs the MACD indicator using the fast SMA line and slow SMA line difference of MACD, and uses the reversal pattern of the MACD histogram to identify potential long-term reversal opportunities in prices. When a price reversal opportunity is identified, the strategy will make a directional long-term entry.
Strategy Logic
The strategy uses 6-day EMA as the fast line of MACD and 26-day EMA as the slow line of MACD. The difference between the fast and slow lines is the MACD, and the 9-day SMA of MACD constitutes the signal line. When the difference between the fast and slow lines, i.e. the histogram, equals zero, it represents a balance; when positive, it represents a long-term bullish view; when negative, it represents a long-term bearish view.
The trading logic of this strategy is: When the MACD histogram rises above the previous one (the difference widens), it is considered that the price has reversed to long-term bullish (buying opportunity); When the MACD histogram falls below the previous one (the difference narrows), the price is considered to have reversed to long-term bearish (selling opportunity). To filter out false signals, this strategy will wait for the actual reversal of two histograms before entering.
Advantage Analysis
- Identify long-term price reversals using the long-term moving average difference of the MACD indicator
- The double-line crossover filters out false breakouts and avoids chasing highs and selling lows
- MACD parameters are adjustable to adapt to different market environments
- Stop loss strategies can be configured to control single loss
Risks and Solutions
- Missing trading opportunities due to MACD divergence
- Optimize to use in combination with RSI indicator
- There are many false reversal signals in oscillating markets
- Increase trailing stop loss to reduce losses; Adjust MACD parameters to pursue smoothness
- The reversal does not hold or the price breaks through the stop loss
- Use exponential moving averages to improve stop loss reliability
- No stop loss strategy, unable to control losses
- Add trailing stop loss or fixed stop loss logic to strictly control single loss amount
Optimization Directions
- Adjust MACD parameters to pursue smoother MACD lines. MACD is a long-term trend tracking indicator, being too sensitive will increase false signals.
- Add trailing stop loss logic. Long-term holdings inevitably face the risk of pullbacks, and trailing stops can mitigate that risk.
- Use in combination with other indicators like RSI. Single indicator effects are limited, combining other indicators can improve performance.
- Add position sizing module. Different market conditions can use different holding strategies.
Summary
The MACD long reversal strategy captures long-term reversal opportunities in prices by judging the reversal of the MACD histogram. This strategy successfully controls the conflict between short-term and long-term cycles, as well as avoiding chasing highs and selling lows. However, as a single indicator strategy, the MACD long reversal strategy also has certain limitations, and there is still room for further optimization, especially when used in combination with other indicators.
Source Pine Script
/*backtest
start: 2022-12-08 00:00:00
end: 2023-12-14 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TheGrindToday
//@version=4
strategy("MACD Long Strat", overlay=false)
//fast = 12, slow = 26
fast = 6, slow = 26
fastMA = ema(close, fast)
slowMA = ema(close, slow)
macd = fastMA - slowMA
signal = sma(macd, 9)
histogram = macd-signal
macdpos = histogram[0] > 0
macdneg = histogram[0] < 0
histogram_reversing_negative = histogram[1] > histogram[2]
LongEntryCondition = histogram > histogram[1]
ShortEntryCondition = histogram < histogram[1]
exitConditionLong = histogram[0] < histogram[2]
if (LongEntryCondition and histogram_reversing_negative)
strategy.entry("Long", strategy.long)
if (exitConditionLong)
strategy.close("Long")
plot(histogram)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-15. 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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/MACD-Long-Reversal-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- Advanced 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h
- BONK Multi Factor Trading StrategyPine Script · Mean reversion · 1d
- Customizable Non Repainting HTF MACD MFI Scalable Bot StrategyPine Script · Mean reversion · 1d
- Dynamic Adaptive Multi Timeframe Trend Following and Range Reversal Hybrid StrategyPine Script · Mean reversion · 2d
- MACD Cross Period Trading StrategyPine Script · Mean reversion · 1d
- Trend Reversal Momentum Indicators Crossover Tracking StrategyPine Script · Mean reversion · 1h