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.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.