OPEN-SOURCE SCRIPT
MACD SAR Trend Filter: 200 EMA Strategy [forexobroker]

MACD SAR Trend Filter: 200 EMA + MACD + Parabolic SAR [forexobroker]
🔶 OVERVIEW
MACD SAR Trend Filter is a three-indicator trend strategy with its own trade log. It takes the most common MACD entry, the line crossing its signal line, and only lets it through when two other things agree: price is on the right side of the 200 EMA, and the Parabolic SAR dot is on the right side of the candle. Every entry is drawn with its stop and its target, every trade is followed to its result, and the last 100 results are counted in a table on the chart.
It is built for traders who want to see, on their own symbol and timeframe, what a classic indicator combination really did over the last 100 trades, wins and losses alike, before they trust it.
🔶 HOW IT WORKS
1. Trend. The close is above the 200 EMA: longs only. The close is below it: shorts only. The background is tinted faintly green or red so the allowed side is always visible.
2. Momentum. The MACD line (12, 26, 9) must be above its signal line for a long, below it for a short.
3. Confirmation. The Parabolic SAR dot (0.02, 0.02, 0.2) must be below the candle for a long, above it for a short.
A LONG signal prints on the closed candle on which conditions 2 and 3 are both true for the first time while condition 1 holds. There are two ways to get there: the MACD line crosses up while the dot is already below the candle, or the MACD line has already crossed up and the dot then flips below the candle. A SHORT signal is the mirror. A candle that only closes across the 200 EMA while the other two were already aligned is not a signal.
🔶 TRADE MANAGEMENT
Entry at the close of the signal candle. Stop at the SAR dot of that candle. Target at a fixed reward multiple of the stop distance, 1R by default (a one-to-one target). The trade is drawn as a red box from the entry to the stop and a green box from the entry to the target, from the signal candle to the candle that resolves it, with a "+1R" or "-1R" label at the end.
Optional stop limit: when the dot is far from price the risk is large. "Max stop, % of price" caps the stop distance at a percentage of the entry price (0 = off, the default). A capped entry is labelled "stop capped".
🔶 THE LOG
One trade at a time. A valid setup that appears while a trade is still open is drawn faded and is not counted (switch "Allow overlapping trades" on to count every setup). Every open trade is followed on closed candles to its stop or its target. When one candle touches both, the stop is counted first: that is the conservative reading of an ambiguous candle.
The last N results (100 by default) feed the table: signals, wins, losses, win rate, total R, best win streak, worst loss streak and days covered, followed by the live state of the three conditions and the open trade. A win adds the reward ratio in R, a loss subtracts 1R.
NON-REPAINTING: every condition, every signal and every result is evaluated on barstate.isconfirmed; there is no request.security and no lookahead.
🔶 SETTINGS
Indicators
- Trend EMA length (default 200).
- MACD fast, slow and signal lengths (12, 26, 9).
- SAR start, increment and maximum (0.02, 0.02, 0.2).
Setup
- Allow overlapping trades (default off): one trade at a time.
- Entry type (default Both): Both, MACD cross only, or SAR flip only. The log counts only the entries the setting lets through, so the three variants can be compared.
- Take longs, Take shorts.
Trade
- Reward ratio (default 1.0): distance × this.
- Max stop, % of price (default 0 = off).
- Extend open trade boxes (bars).
Log
- Log size (default 100), Show log table, Table position, Table text size.
Visual
- Long and short colours, EMA colour, show the EMA, show the SAR dots, tint the background by trend, BUY / SELL labels, +R / -R result labels, trades kept on chart, box fill transparency.
Alerts
- Send JSON alert() messages.
🔶 ALERTS
Three alertcondition hooks: MSTF Long setup, MSTF Short setup, MSTF Any setup. With "Send JSON alert() messages" on, every taken signal also fires an alert() once per bar close with a JSON body (action, ticker, timeframe, entry, stop, target, capped).
🔶 LIMITATIONS
- The three indicators are trend tools. In a sideways market the MACD and the SAR flip often and the strategy takes losses in a row; the log's worst loss streak shows how long that has lasted on your symbol.
- With a one-to-one target the strategy needs to win more than half of its trades. Check the win rate in the table before anything else.
- Results in the log are the script's own rules applied to closed candles: no spread, no commission, no slippage, and the stop is counted before the target on a candle that touches both.
- This is an analysis tool, not financial advice, and past performance does not guarantee future results. Test on your own market and timeframe before relying on any signal.
🔶 OVERVIEW
MACD SAR Trend Filter is a three-indicator trend strategy with its own trade log. It takes the most common MACD entry, the line crossing its signal line, and only lets it through when two other things agree: price is on the right side of the 200 EMA, and the Parabolic SAR dot is on the right side of the candle. Every entry is drawn with its stop and its target, every trade is followed to its result, and the last 100 results are counted in a table on the chart.
It is built for traders who want to see, on their own symbol and timeframe, what a classic indicator combination really did over the last 100 trades, wins and losses alike, before they trust it.
🔶 HOW IT WORKS
1. Trend. The close is above the 200 EMA: longs only. The close is below it: shorts only. The background is tinted faintly green or red so the allowed side is always visible.
2. Momentum. The MACD line (12, 26, 9) must be above its signal line for a long, below it for a short.
3. Confirmation. The Parabolic SAR dot (0.02, 0.02, 0.2) must be below the candle for a long, above it for a short.
A LONG signal prints on the closed candle on which conditions 2 and 3 are both true for the first time while condition 1 holds. There are two ways to get there: the MACD line crosses up while the dot is already below the candle, or the MACD line has already crossed up and the dot then flips below the candle. A SHORT signal is the mirror. A candle that only closes across the 200 EMA while the other two were already aligned is not a signal.
🔶 TRADE MANAGEMENT
Entry at the close of the signal candle. Stop at the SAR dot of that candle. Target at a fixed reward multiple of the stop distance, 1R by default (a one-to-one target). The trade is drawn as a red box from the entry to the stop and a green box from the entry to the target, from the signal candle to the candle that resolves it, with a "+1R" or "-1R" label at the end.
Optional stop limit: when the dot is far from price the risk is large. "Max stop, % of price" caps the stop distance at a percentage of the entry price (0 = off, the default). A capped entry is labelled "stop capped".
🔶 THE LOG
One trade at a time. A valid setup that appears while a trade is still open is drawn faded and is not counted (switch "Allow overlapping trades" on to count every setup). Every open trade is followed on closed candles to its stop or its target. When one candle touches both, the stop is counted first: that is the conservative reading of an ambiguous candle.
The last N results (100 by default) feed the table: signals, wins, losses, win rate, total R, best win streak, worst loss streak and days covered, followed by the live state of the three conditions and the open trade. A win adds the reward ratio in R, a loss subtracts 1R.
NON-REPAINTING: every condition, every signal and every result is evaluated on barstate.isconfirmed; there is no request.security and no lookahead.
🔶 SETTINGS
Indicators
- Trend EMA length (default 200).
- MACD fast, slow and signal lengths (12, 26, 9).
- SAR start, increment and maximum (0.02, 0.02, 0.2).
Setup
- Allow overlapping trades (default off): one trade at a time.
- Entry type (default Both): Both, MACD cross only, or SAR flip only. The log counts only the entries the setting lets through, so the three variants can be compared.
- Take longs, Take shorts.
Trade
- Reward ratio (default 1.0): distance × this.
- Max stop, % of price (default 0 = off).
- Extend open trade boxes (bars).
Log
- Log size (default 100), Show log table, Table position, Table text size.
Visual
- Long and short colours, EMA colour, show the EMA, show the SAR dots, tint the background by trend, BUY / SELL labels, +R / -R result labels, trades kept on chart, box fill transparency.
Alerts
- Send JSON alert() messages.
🔶 ALERTS
Three alertcondition hooks: MSTF Long setup, MSTF Short setup, MSTF Any setup. With "Send JSON alert() messages" on, every taken signal also fires an alert() once per bar close with a JSON body (action, ticker, timeframe, entry, stop, target, capped).
🔶 LIMITATIONS
- The three indicators are trend tools. In a sideways market the MACD and the SAR flip often and the strategy takes losses in a row; the log's worst loss streak shows how long that has lasted on your symbol.
- With a one-to-one target the strategy needs to win more than half of its trades. Check the win rate in the table before anything else.
- Results in the log are the script's own rules applied to closed candles: no spread, no commission, no slippage, and the stop is counted before the target on a candle that touches both.
- This is an analysis tool, not financial advice, and past performance does not guarantee future results. Test on your own market and timeframe before relying on any signal.
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.
🔵Gain access to our powerful tools : kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
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.
🔵Gain access to our powerful tools : kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
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.