OPEN-SOURCE SCRIPT
MACD Pullback Sniper | Trend + ADX Filtered Strategy

MACD Pullback Sniper is a simple trend-following strategy. It uses the classic MACD signal-line cross, but only takes the crosses that line up with the larger trend. The goal is fewer trades, taken at better moments.
How it works
The strategy waits for the MACD line to cross the signal line, then checks three filters before entering:
Exits and risk management
Features
Tips
Disclaimer: This script is for educational purposes only and is not financial advice. Backtest results do not guarantee future performance. Always test on a demo account first and trade at your own risk.
How it works
The strategy waits for the MACD line to cross the signal line, then checks three filters before entering:
- Trend filter: Longs are allowed only when price is above the 200 EMA, and shorts only when it is below.
- Zero-line filter: Longs must cross below the zero line and shorts above it. In an uptrend, a bullish cross below zero usually marks a pullback ending, so entries come after the dip rather than after the move.
- ADX filter: Trades are taken only when ADX is above the threshold (default 20). This cuts out many of the whipsaws that MACD produces in sideways markets.
Exits and risk management
- Stop loss: ATR-based (default 2x ATR), so it adapts to volatility.
- Take profit: A fixed reward:risk multiple (default 2R).
- Optional signal exit: Closes the trade on an opposite MACD cross.
- Position sizing: Each trade risks a fixed percentage of current equity (default 1%). A maximum position size cap stops very tight stops from creating oversized trades.
- Stop and target placement: After entry, both are re-anchored to the actual fill price. The stop and target are drawn on the price chart while a trade is open.
Features
- Long and short trading, with shorts switchable off
- Each filter can be turned on or off independently
- Custom start and end dates for backtesting
- MACD histogram, MACD line and signal line in a separate pane
- Trend EMA, stop, target and entry markers drawn on the main chart
- Commission (0.05%) and slippage (2 ticks) included in the default settings
Tips
- Use it on trending markets and higher timeframes (1H, 4H, Daily). MACD crosses on very low timeframes are mostly noise.
- If you want more trades, turn off the zero-line filter first. If you want higher quality, raise the ADX minimum to 25.
- Check the trade count. Judge results on at least 100 trades, and be wary of any setting that looks great over only 20 or 30.
- Avoid over-optimizing. The defaults (12/26/9, 200 EMA, 14 ADX and ATR) are standard values, and results that hold up across nearby settings are more trustworthy.
- Test on several symbols and timeframes rather than one.
- Adjust the commission and slippage inputs to match your broker or exchange.
- Position sizing assumes one contract moves one currency unit per point of price, which fits crypto and stocks. For forex or futures, check the contract value and adjust sizing.
- For live trading, use a lower risk per trade than you think you need, and set the maximum drawdown you can accept before you start.
Disclaimer: This script is for educational purposes only and is not financial advice. Backtest results do not guarantee future performance. Always test on a demo account first and trade at your own risk.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.