🔓 Get All Tools for FREE!
- ✅ Click here to open a trading account using our referral link and start trading.
- 📅 After 7 days of active trading under our referral link, you can get access to all tools in your account.
- ⚠️ Keep trading to keep access free — if you're inactive for 7 days, your access will be removed.
- 👉 Already have an account? You can change the IB (introducing broker) to our referral link ( https://one.exnesstrack.org/a/w7syl3vnjb ) and still qualify!
Finding high-probability trade setups can be challenging when markets produce false breakouts and misleading momentum signals. This advanced TradingView Pine Script indicator combines multiple professional trading concepts including MACD Pullbacks, Histogram Momentum Analysis, Divergence Detection, Support & Resistance Filtering, and Bollinger Band Confirmation to generate high-quality BUY and SELL signals.
Unlike traditional MACD indicators that rely solely on simple crossovers, this system uses several layers of confirmation to help traders identify stronger market opportunities.
🔓 Get All Tools for FREE!
- ✅ Click here to open a trading account using our referral link and start trading.
- 📅 After 7 days of active trading under our referral link, you can get access to all tools in your account.
- ⚠️ Keep trading to keep access free — if you're inactive for 7 days, your access will be removed.
- 👉 Already have an account? You can change the IB (introducing broker) to our referral link ( https://one.exnesstrack.org/a/w7syl3vnjb ) and still qualify!
Strategy Overview
This indicator combines five powerful trading concepts into a single system:
- MACD Pullback Confirmation
- Histogram Momentum Analysis
- Bullish & Bearish Divergence Detection
- Dynamic Support & Resistance Filtering
- Bollinger Band Confirmation
By combining multiple confirmations, the strategy aims to reduce false signals and improve trade quality.
MACD Pullback Logic
The indicator searches for pullbacks within established momentum trends.
Bullish Setup
The strategy looks for:
- Previous bearish MACD crossover above zero
- MACD momentum recovering
- MACD crossing back above the zero line
- Increasing bullish histogram momentum
This can indicate that a temporary pullback has ended and bullish momentum is returning.
Bearish Setup
The strategy looks for:
- Previous bullish MACD crossover below zero
- Weakening momentum
- MACD crossing below the zero line
- Increasing bearish histogram strength
This can signal renewed downside momentum.
Divergence Detection
One of the most powerful features of this indicator is automatic divergence detection.
Bullish Divergence
Occurs when:
- Price forms a lower low
- MACD histogram forms a higher low
This may suggest weakening selling pressure and potential bullish reversal conditions.
Bearish Divergence
Occurs when:
- Price forms a higher high
- MACD histogram forms a lower high
This may indicate weakening bullish momentum and potential downside risk.
Support & Resistance Filter
The indicator automatically identifies pivot-based support and resistance zones.
Signals can be filtered to appear only when price interacts with these important levels.
Benefits include:
- Better entry precision
- Reduced random signals
- Stronger market structure confirmation
Bollinger Band Confirmation
An optional Bollinger Band filter adds another layer of confirmation.
BUY Conditions
Price closes below the lower Bollinger Band, indicating potential oversold conditions.
SELL Conditions
Price closes above the upper Bollinger Band, indicating potential overbought conditions.
This helps identify extreme price movements that may align with reversal opportunities.
Indicator Features
✅ MACD Histogram Momentum Analysis
✅ Pullback Detection System
✅ Bullish Divergence Detection
✅ Bearish Divergence Detection
✅ Automatic Support & Resistance Levels
✅ Bollinger Band Confirmation
✅ Zero Line Cross Filtering
✅ BUY & SELL Labels
✅ TradingView Alert Support
✅ Forex, Crypto & Stock Market Compatible
Best Timeframes
Recommended timeframes:
- 15 Minute
- 30 Minute
- 1 Hour
- 4 Hour
- Daily
Works particularly well on:
- Forex Pairs
- Gold (XAUUSD)
- Cryptocurrency Markets
- Stock Indices
- Individual Stocks
Risk Management Tips
For improved consistency:
- Use stop loss below recent swing lows for BUY trades
- Use stop loss above recent swing highs for SELL trades
- Avoid major news events
- Trade in the direction of the higher timeframe trend
- Use proper risk-to-reward ratios
Conclusion
This MACD Pullback + Divergence + Bollinger Band Strategy combines momentum analysis, divergence detection, support and resistance zones, and volatility filters into a powerful multi-confirmation trading system. By requiring several conditions to align before generating a signal, the indicator focuses on quality setups rather than quantity.
Whether you trade Forex, Crypto, Indices, or Stocks, this advanced Pine Script indicator provides a professional framework for identifying potential trend continuation and reversal opportunities.
Pinescript –
//@version=6
indicator("MACD Pullback + Histogram Momentum Signals", overlay=true)
// MACD Inputs
fastLength = input.int(12, "Fast Length")
slowLength = input.int(26, "Slow Length")
signalLength = input.int(9, "Signal Length")
lookback = input.int(10, "Pullback Lookback", minval=1)
// MACD Calculation
[macdLine, signalLine, hist] = ta.macd(close, fastLength, slowLength, signalLength)
// =====================================================
// HISTOGRAM MOMENTUM CONDITIONS
// =====================================================
// Green histogram increasing
histBull = hist > 0 and hist > hist[1]
// Red histogram decreasing
histBear = hist < 0 and hist < hist[1]
// =====================================================
// PULLBACK CONDITIONS
// =====================================================
// Bearish crossover above zero
bearishCrossAboveZero =
ta.crossunder(macdLine, signalLine) and
macdLine > 0 and
signalLine > 0
// Bullish crossover below zero
bullishCrossBelowZero =
ta.crossover(macdLine, signalLine) and
macdLine < 0 and
signalLine < 0
barsSinceBearishCross = ta.barssince(bearishCrossAboveZero)
barsSinceBullishCross = ta.barssince(bullishCrossBelowZero)
recentBearishCross =
not na(barsSinceBearishCross) and
barsSinceBearishCross <= lookback
recentBullishCross =
not na(barsSinceBullishCross) and
barsSinceBullishCross <= lookback
// =====================================================
// ZERO LINE CONDITIONS
// =====================================================
macdCrossAboveZero = ta.crossover(macdLine, 0)
macdCrossBelowZero = ta.crossunder(macdLine, 0)
// Divergence cross
// Divergence Settings
lbR = input.int(title="Pivot Lookback Right", defval=5)
lbL = input.int(title="Pivot Lookback Left", defval=5)
rangeUpper = input.int(title="Max of Lookback Range", defval=60)
rangeLower = input.int(title="Min of Lookback Range", defval=5)
plotBull = input.bool(title="Plot Bullish", defval=true)
plotHiddenBull = input.bool(title="Plot Hidden Bullish", defval=false)
plotBear = input.bool(title="Plot Bearish", defval=true)
plotHiddenBear = input.bool(title="Plot Hidden Bearish", defval=false)
// Colors
bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 80)
hiddenBearColor = color.new(color.red, 80)
textColor = color.white
noneColor = color.new(color.white, 100)
// MACD Histogram
osc = hist
// Pivot Detection
plFound = not na(ta.pivotlow(osc, lbL, lbR))
phFound = not na(ta.pivothigh(osc, lbL, lbR))
_inRange(cond) =>
bars = ta.barssince(cond)
rangeLower <= bars and bars <= rangeUpper
//------------------------------------------------------------------------------
// Regular Bullish Divergence
// Histogram: Higher Low
inRangePl = _inRange(plFound[1])
oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and inRangePl
// Price: Lower Low
priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCondAlert = priceLL and oscHL and plFound
bullCond = plotBull and bullCondAlert
//------------------------------------------------------------------------------
// Hidden Bullish Divergence
// Histogram: Lower Low
oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and inRangePl
// Price: Higher Low
priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
hiddenBullCondAlert = priceHL and oscLL and plFound
hiddenBullCond = plotHiddenBull and hiddenBullCondAlert
//------------------------------------------------------------------------------
// Regular Bearish Divergence
// Histogram: Lower High
inRangePh = _inRange(phFound[1])
oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and inRangePh
// Price: Higher High
priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
bearCondAlert = priceHH and oscLH and phFound
bearCond = plotBear and bearCondAlert
//------------------------------------------------------------------------------
// Hidden Bearish Divergence
// Histogram: Higher High
oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and inRangePh
// Price: Lower High
priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)
hiddenBearCondAlert = priceLH and oscHH and phFound
hiddenBearCond = plotHiddenBear and hiddenBearCondAlert
// Alerts
alertcondition(bullCondAlert, title="Regular Bullish Divergence", message="MACD Histogram Regular Bullish Divergence")
alertcondition(hiddenBullCondAlert, title="Hidden Bullish Divergence", message="MACD Histogram Hidden Bullish Divergence")
alertcondition(bearCondAlert, title="Regular Bearish Divergence", message="MACD Histogram Regular Bearish Divergence")
alertcondition(hiddenBearCondAlert, title="Hidden Bearish Divergence", message="MACD Histogram Hidden Bearish Divergence")
// =====================================================
// FINAL SIGNALS
// =====================================================
recentBullDiv = ta.barssince(bullCondAlert) <= 30
recentBearDiv = ta.barssince(bearCondAlert) <= 30
// SR
enableSRFilter = input.bool(true, "Enable Support/Resistance Filter")
// Inputs
leftBars = input.int(10, "Left Bars", minval=1)
rightBars = input.int(10, "Right Bars", minval=1)
// Candle body values
bodyHigh = math.max(open, close)
bodyLow = math.min(open, close)
// Body pivot detection
pivotHigh = ta.pivothigh(bodyHigh, leftBars, rightBars)
pivotLow = ta.pivotlow(bodyLow, leftBars, rightBars)
// Store latest pivot high candle range
var float latestPivotHighCandleHigh = na
var float latestPivotHighCandleLow = na
if not na(pivotHigh)
latestPivotHighCandleHigh := high[rightBars]
latestPivotHighCandleLow := low[rightBars]
label.new(
bar_index - rightBars,
high[rightBars],
"PH",
style=label.style_label_down,
color=color.red,
textcolor=color.white)
// Store latest pivot low candle range
var float latestPivotLowCandleHigh = na
var float latestPivotLowCandleLow = na
if not na(pivotLow)
latestPivotLowCandleHigh := high[rightBars]
latestPivotLowCandleLow := low[rightBars]
label.new(
bar_index - rightBars,
low[rightBars],
"PL",
style=label.style_label_up,
color=color.lime,
textcolor=color.black)
//=====================================================
// SUPPORT / RESISTANCE FILTER
//=====================================================
//zonePercent = input.float(0.20, "Zone Size (%)", step=0.05)
// Latest support & resistance from pivot bodies
supportLevel = latestPivotHighCandleHigh
resistanceLevel = latestPivotHighCandleLow
// Zone calculations
supportZoneTop = supportLevel //* (1 + zonePercent / 100)
supportZoneBottom = supportLevel //* (1 - zonePercent / 100)
resistanceZoneTop = resistanceLevel //* (1 + zonePercent / 100)
resistanceZoneBottom = resistanceLevel //* (1 - zonePercent / 100)
// Candle touching support zone
touchSupport =
not na(supportLevel) and
low <= supportZoneTop
// Candle touching resistance zone
touchResistance =
not na(resistanceLevel) and
high >= resistanceZoneBottom
//=====================================================
// BOLLINGER BAND FILTER
//=====================================================
enableBBFilter = input.bool(true, "Enable Bollinger Band Filter")
bbLength = input.int(20, "BB Length")
bbMult = input.float(2.0, "BB StdDev", step=0.1)
bbBasis = ta.sma(close, bbLength)
bbDev = bbMult * ta.stdev(close, bbLength)
bbUpper = bbBasis + bbDev
bbLower = bbBasis - bbDev
// Close outside bands
bbBuyCondition = close < bbLower
bbSellCondition = close > bbUpper
plot(enableBBFilter ? bbUpper : na, "BB Upper", color=color.new(color.red, 50))
plot(enableBBFilter ? bbBasis : na, "BB Basis", color=color.new(color.gray, 50))
plot(enableBBFilter ? bbLower : na, "BB Lower", color=color.new(color.green, 50))
baseBuySignal =
histBull and
macdCrossAboveZero and
recentBearishCross and
recentBullDiv
baseSellSignal =
histBear and
macdCrossBelowZero and
recentBullishCross and
recentBearDiv
buySignal =
baseBuySignal and
(
not enableSRFilter or
touchSupport
) and
(
not enableBBFilter or
bbBuyCondition
)
sellSignal =
baseSellSignal and
(
not enableSRFilter or
touchResistance
) and
(
not enableBBFilter or
bbSellCondition
)
// =====================================================
// PLOTS
// =====================================================
plotshape(
buySignal,
title="BUY",
location=location.belowbar,
style=shape.labelup,
color=color.lime,
text="BUY",
textcolor=color.white,
size=size.normal)
plotshape(
sellSignal,
title="SELL",
location=location.abovebar,
style=shape.labeldown,
color=color.red,
text="SELL",
textcolor=color.white,
size=size.normal)
// =====================================================
// ALERTS
// =====================================================
alertcondition(
buySignal,
title="BUY Signal",
message="MACD Buy Signal")
alertcondition(
sellSignal,
title="SELL Signal",
message="MACD Sell Signal")
0 Comments