OPEN-SOURCE SCRIPT
MACD & Stoch RSI Confluence S/R

MACD & Stoch RSI Confluence S/R
MACD & Stoch RSI Confluence S/R draws horizontal support and resistance
levels from MACD and Stochastic RSI crossover points, then automatically
merges levels that cluster close together into a single confluence zone.
Instead of treating every crossover as an isolated signal, it highlights
the price areas where two independent momentum oscillators historically
agreed on a turning point.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
BACKGROUND — WHY CROSSOVER-BASED LEVELS?
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MACD and Stochastic RSI are both momentum oscillators, but they measure
momentum differently — MACD from the relationship between two EMAs,
Stochastic RSI from the position of RSI within its own recent range.
Because of this difference, the two oscillators don't always cross at the
same time or the same price, but when they do cross near the same price
level, it suggests that two independent calculations both detected a
shift in momentum at that point.
Traditional crossover indicators only mark the moment of the crossover
itself and then move on — the price level where it happened is rarely
preserved or revisited. This indicator instead treats every crossover
price as a potential support or resistance level going forward, on the
logic that price has already shown a reaction (a momentum shift) at that
level once, and may do so again if it returns there.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
HOW IT WORKS — TECHNICAL DETAIL
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
CROSSOVER DETECTION
The indicator calculates a standard MACD (fast EMA, slow EMA, signal line)
and a standard Stochastic RSI (RSI smoothed through a Stochastic
calculation, then K/D smoothing) independently. Bullish crossovers occur
when MACD crosses above its signal line, or when Stochastic RSI's K line
crosses above its D line. Bearish crossovers are the inverse.
Each time a valid crossover occurs, the indicator looks back a
user-defined number of bars (How many bars before crossover?) and records
the low of that bar for bullish crossovers, or the high for bearish
crossovers. This offset exists because the actual turning point in price
often occurs slightly before the oscillator confirms it — anchoring the
line to the prior bar's extreme captures the reaction point more
accurately than the bar where the crossover is technically confirmed.
PROXIMITY FILTERING (PER OSCILLATOR)
Before a new level is recorded, it's checked against existing levels from
the same oscillator and same direction using an ATR-based distance
threshold. If a new crossover price falls too close to an already-recorded
level, it's discarded. This prevents a single trending move that triggers
several crossovers in quick succession from flooding the chart with
near-identical lines.
CONFLUENCE MERGING (ACROSS OSCILLATORS)
After proximity filtering, all surviving levels from both oscillators —
MACD support, MACD resistance, Stoch RSI support, Stoch RSI resistance —
are pooled together. Any levels within a percentage threshold of each
other are merged into a single line, positioned at their average price.
The merged line is labeled with the count of crossovers that contributed
to it, so a label showing "⬡3" indicates three separate crossover events —
potentially from different oscillators — all landed within the merge
threshold of one another.
This merge threshold is calculated automatically based on the chart's
timeframe: wider on higher timeframes (where price ranges are naturally
larger) and tighter on lower timeframes. A manual override is available if
you prefer a fixed percentage regardless of timeframe.
DYNAMIC COLORING
Every line — merged or single — is colored based on its position relative
to the current close. A line below price is colored as support; a line
above price is colored as resistance. Because lines extend forward in
time, a single line can change from resistance to support (or vice versa)
as price crosses through it, and the color updates automatically.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
INFO TABLE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
A table in the corner of your choice displays, for the most recent bar:
— The number of support and resistance lines currently shown for each
oscillator separately
— The nearest support and nearest resistance level to current price,
calculated from the same merged lines drawn on the chart — not a
separate calculation, so the table always matches what you see
— Whether the MACD zero-line filter and Stoch RSI overbought/oversold
filter are currently active
— Whether each oscillator is enabled
— The current merge threshold percentage and whether it was set
automatically or manually
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
HOW TO USE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. CHOOSE WHICH OSCILLATORS TO USE
Both MACD and Stochastic RSI are enabled by default. You can disable
either one independently if you only want levels from a single
oscillator, or run both for confluence.
2. SET THE BAR OFFSET
How many bars before crossover? controls how far back from the
confirmed crossover the indicator anchors the level. Start with the
default and increase it if you find levels are consistently anchored
slightly too late relative to the actual price reaction.
3. TUNE THE PROXIMITY FILTER
The ATR Multiplier controls how close a new crossover has to be to an
existing level of the same type before it's discarded. Increase this on
choppy assets to reduce clutter; decrease it if you feel valid levels
are being filtered out.
4. APPLY OPTIONAL FILTERS IF NEEDED
The MACD Zero Line Filter restricts bullish crossovers to above the
zero line and bearish crossovers to below it, filtering out weaker
signals that occur against the broader momentum direction. The Stoch
RSI Overbought/Oversold Filter restricts crossovers to occur only in
oversold or overbought territory, focusing on reversal-type signals
rather than mid-range noise. Both are off by default — enable them if
you want fewer, more selective levels.
5. ADJUST THE MERGE THRESHOLD IF NEEDED
The automatic threshold works well across most timeframes, but if you
trade a single timeframe consistently and want more control, switch to
Manual Threshold and set a fixed percentage that matches your
instrument's typical price behavior.
6. READ THE LABELS
Single-oscillator lines are labeled "M" (MACD) or "S" (Stoch RSI).
Merged lines are labeled with a count (e.g. "⬡2", "⬡3") showing how many
crossovers — and potentially how many different oscillators — agreed on
that level. Higher counts represent stronger confluence.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
WHERE TO USE IT
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The indicator works on any asset class and any timeframe, since both
oscillators and the merge threshold are calculated directly from the
chart you have open. It's particularly useful for:
— Identifying support/resistance levels that are backed by momentum
shifts rather than purely price-action-based pivots
— Spotting confluence zones where MACD and Stoch RSI crossovers
historically aligned, which may carry more weight than a level
identified by either oscillator alone
— Confirming reactions at prior turning points — if price returns to a
level where a crossover previously occurred, the level provides context
for whether momentum may shift again
— Combining with other structure or volume-based tools as part of a
broader confluence-based approach, rather than as a standalone signal
generator
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
SETTINGS REFERENCE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MACD: Fast/Slow/Signal EMA lengths, source, bar offset, max support/
resistance lines kept, line width, colors, extend mode, ATR-based
proximity filter, zero-line filter
Stochastic RSI: RSI period, Stochastic period, K/D smoothing, source, and
the same set of line/extend/proximity/zone options as MACD
Merging: enable/disable, automatic or manual threshold, merged line color
and width
Table: show/hide, position
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ORIGINALITY
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MACD and Stochastic RSI crossovers are both well-established concepts
individually, but this script's specific contribution is treating
crossover prices as persistent support/resistance levels rather than
one-off signals, combined with a cross-oscillator confluence merge that
identifies where two independently-calculated momentum tools agreed on
the same price area. The ATR-based proximity filter and timeframe-adaptive
merge threshold are the author's own approach to keeping this practical
and readable on a live chart rather than producing chart clutter.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
DISCLAIMER
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
This indicator is intended for educational and analytical purposes only.
No indicator can predict future market movements with certainty. Always
use proper risk management and combine multiple forms of analysis before
making trading decisions.
MACD & Stoch RSI Confluence S/R draws horizontal support and resistance
levels from MACD and Stochastic RSI crossover points, then automatically
merges levels that cluster close together into a single confluence zone.
Instead of treating every crossover as an isolated signal, it highlights
the price areas where two independent momentum oscillators historically
agreed on a turning point.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
BACKGROUND — WHY CROSSOVER-BASED LEVELS?
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MACD and Stochastic RSI are both momentum oscillators, but they measure
momentum differently — MACD from the relationship between two EMAs,
Stochastic RSI from the position of RSI within its own recent range.
Because of this difference, the two oscillators don't always cross at the
same time or the same price, but when they do cross near the same price
level, it suggests that two independent calculations both detected a
shift in momentum at that point.
Traditional crossover indicators only mark the moment of the crossover
itself and then move on — the price level where it happened is rarely
preserved or revisited. This indicator instead treats every crossover
price as a potential support or resistance level going forward, on the
logic that price has already shown a reaction (a momentum shift) at that
level once, and may do so again if it returns there.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
HOW IT WORKS — TECHNICAL DETAIL
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
CROSSOVER DETECTION
The indicator calculates a standard MACD (fast EMA, slow EMA, signal line)
and a standard Stochastic RSI (RSI smoothed through a Stochastic
calculation, then K/D smoothing) independently. Bullish crossovers occur
when MACD crosses above its signal line, or when Stochastic RSI's K line
crosses above its D line. Bearish crossovers are the inverse.
Each time a valid crossover occurs, the indicator looks back a
user-defined number of bars (How many bars before crossover?) and records
the low of that bar for bullish crossovers, or the high for bearish
crossovers. This offset exists because the actual turning point in price
often occurs slightly before the oscillator confirms it — anchoring the
line to the prior bar's extreme captures the reaction point more
accurately than the bar where the crossover is technically confirmed.
PROXIMITY FILTERING (PER OSCILLATOR)
Before a new level is recorded, it's checked against existing levels from
the same oscillator and same direction using an ATR-based distance
threshold. If a new crossover price falls too close to an already-recorded
level, it's discarded. This prevents a single trending move that triggers
several crossovers in quick succession from flooding the chart with
near-identical lines.
CONFLUENCE MERGING (ACROSS OSCILLATORS)
After proximity filtering, all surviving levels from both oscillators —
MACD support, MACD resistance, Stoch RSI support, Stoch RSI resistance —
are pooled together. Any levels within a percentage threshold of each
other are merged into a single line, positioned at their average price.
The merged line is labeled with the count of crossovers that contributed
to it, so a label showing "⬡3" indicates three separate crossover events —
potentially from different oscillators — all landed within the merge
threshold of one another.
This merge threshold is calculated automatically based on the chart's
timeframe: wider on higher timeframes (where price ranges are naturally
larger) and tighter on lower timeframes. A manual override is available if
you prefer a fixed percentage regardless of timeframe.
DYNAMIC COLORING
Every line — merged or single — is colored based on its position relative
to the current close. A line below price is colored as support; a line
above price is colored as resistance. Because lines extend forward in
time, a single line can change from resistance to support (or vice versa)
as price crosses through it, and the color updates automatically.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
INFO TABLE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
A table in the corner of your choice displays, for the most recent bar:
— The number of support and resistance lines currently shown for each
oscillator separately
— The nearest support and nearest resistance level to current price,
calculated from the same merged lines drawn on the chart — not a
separate calculation, so the table always matches what you see
— Whether the MACD zero-line filter and Stoch RSI overbought/oversold
filter are currently active
— Whether each oscillator is enabled
— The current merge threshold percentage and whether it was set
automatically or manually
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
HOW TO USE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. CHOOSE WHICH OSCILLATORS TO USE
Both MACD and Stochastic RSI are enabled by default. You can disable
either one independently if you only want levels from a single
oscillator, or run both for confluence.
2. SET THE BAR OFFSET
How many bars before crossover? controls how far back from the
confirmed crossover the indicator anchors the level. Start with the
default and increase it if you find levels are consistently anchored
slightly too late relative to the actual price reaction.
3. TUNE THE PROXIMITY FILTER
The ATR Multiplier controls how close a new crossover has to be to an
existing level of the same type before it's discarded. Increase this on
choppy assets to reduce clutter; decrease it if you feel valid levels
are being filtered out.
4. APPLY OPTIONAL FILTERS IF NEEDED
The MACD Zero Line Filter restricts bullish crossovers to above the
zero line and bearish crossovers to below it, filtering out weaker
signals that occur against the broader momentum direction. The Stoch
RSI Overbought/Oversold Filter restricts crossovers to occur only in
oversold or overbought territory, focusing on reversal-type signals
rather than mid-range noise. Both are off by default — enable them if
you want fewer, more selective levels.
5. ADJUST THE MERGE THRESHOLD IF NEEDED
The automatic threshold works well across most timeframes, but if you
trade a single timeframe consistently and want more control, switch to
Manual Threshold and set a fixed percentage that matches your
instrument's typical price behavior.
6. READ THE LABELS
Single-oscillator lines are labeled "M" (MACD) or "S" (Stoch RSI).
Merged lines are labeled with a count (e.g. "⬡2", "⬡3") showing how many
crossovers — and potentially how many different oscillators — agreed on
that level. Higher counts represent stronger confluence.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
WHERE TO USE IT
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The indicator works on any asset class and any timeframe, since both
oscillators and the merge threshold are calculated directly from the
chart you have open. It's particularly useful for:
— Identifying support/resistance levels that are backed by momentum
shifts rather than purely price-action-based pivots
— Spotting confluence zones where MACD and Stoch RSI crossovers
historically aligned, which may carry more weight than a level
identified by either oscillator alone
— Confirming reactions at prior turning points — if price returns to a
level where a crossover previously occurred, the level provides context
for whether momentum may shift again
— Combining with other structure or volume-based tools as part of a
broader confluence-based approach, rather than as a standalone signal
generator
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
SETTINGS REFERENCE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MACD: Fast/Slow/Signal EMA lengths, source, bar offset, max support/
resistance lines kept, line width, colors, extend mode, ATR-based
proximity filter, zero-line filter
Stochastic RSI: RSI period, Stochastic period, K/D smoothing, source, and
the same set of line/extend/proximity/zone options as MACD
Merging: enable/disable, automatic or manual threshold, merged line color
and width
Table: show/hide, position
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ORIGINALITY
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MACD and Stochastic RSI crossovers are both well-established concepts
individually, but this script's specific contribution is treating
crossover prices as persistent support/resistance levels rather than
one-off signals, combined with a cross-oscillator confluence merge that
identifies where two independently-calculated momentum tools agreed on
the same price area. The ATR-based proximity filter and timeframe-adaptive
merge threshold are the author's own approach to keeping this practical
and readable on a live chart rather than producing chart clutter.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
DISCLAIMER
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
This indicator is intended for educational and analytical purposes only.
No indicator can predict future market movements with certainty. Always
use proper risk management and combine multiple forms of analysis before
making trading decisions.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.