Pine Script Modularization & Confluence

How to Combine Multiple Indicators in TradingView Pine Script

To combine multiple TradingView indicators into a single Pine Script, merge the source code beneath a unified indicator() declaration, rename overlapping variables and inputs to avoid scope collisions, group user inputs using the group parameter, and construct composite boolean conditions (confluence triggers) that require agreement across all merged indicators before plotting signals.

Combine Indicators with AI Agent

Why combine indicators and how to structure the merge

TradingView subscription tiers restrict the maximum number of simultaneous indicators you can add to a single chart (e.g. 2 indicators on Basic/Free, 5 on Essential). By merging the source code of multiple indicators into one script, you consume only a single indicator slot while enjoying all of your customary tools. Beyond saving slots, merging allows indicators to communicate directly, allowing you to create confluence rules such as buying only when an EMA crossover occurs and RSI is oversold and price touches the lower Bollinger Band.

Challenge during mergeCauseTechnical solution in Pine Script v6
Variable name collisionBoth scripts use identical names like len, ma, rsiPrefix variables with indicator acronyms (e.g. ema_len, rsi_len)
Overlay conflictOne script is overlay = true, the other is an oscillator in a separate paneKeep script overlay = true and normalize pane oscillator values or plot on main chart with scale = scale.none
Version mismatchesOne script is v4 or v5, while the other is v6Upgrade all logic to //@version=6 using modern ta.* namespaces
Unorganized settingsDozens of inputs appear mixed randomly in settingsAdd group = "Indicator Name" to every input() call

Complete combined indicator code example: EMA + RSI + Bollinger Bands in v6

The following complete Pine Script v6 script merges three separate indicators (EMA Trend Filter, Bollinger Bands, and RSI Oscillator) into a single unified script with toggles, clean input groups, and an all-in-one confluence signal.

Pine Script v6: Triple confluence indicator (EMA + BB + RSI)pinescript
//@version=6
indicator("Combined Multi-Indicator Suite [v6]", overlay = true)

// ===================== INPUT GROUPS =====================
grpEma = "Trend Filter (EMA)"
showEma = input.bool(true, "Show EMA", group = grpEma)
emaLen = input.int(200, "EMA Length", group = grpEma)

grpBb = "Volatility (Bollinger Bands)"
showBb = input.bool(true, "Show Bollinger Bands", group = grpBb)
bbLen = input.int(20, "BB Length", group = grpBb)
bbMult = input.float(2.0, "BB StdDev Multiplier", group = grpBb)

grpRsi = "Momentum (RSI)"
rsiLen = input.int(14, "RSI Length", group = grpRsi)
rsiOversold = input.int(35, "RSI Oversold Level", group = grpRsi)

// ===================== CALCULATIONS =====================
// 1. EMA
emaVal = ta.ema(close, emaLen)

// 2. Bollinger Bands
[bbMiddle, bbUpper, bbLower] = ta.bb(close, bbLen, bbMult)

// 3. RSI
rsiVal = ta.rsi(close, rsiLen)

// ===================== PLOTS =====================
plot(showEma ? emaVal : na, "200 EMA", color = color.yellow, linewidth = 2)

pUpper = plot(showBb ? bbUpper : na, "BB Upper", color = color.new(color.blue, 40))
pLower = plot(showBb ? bbLower : na, "BB Lower", color = color.new(color.blue, 40))
fill(pUpper, pLower, color = showBb ? color.new(color.blue, 95) : na, title = "BB Background")

// ===================== CONFLUENCE SIGNAL =====================
// Long condition: Price above 200 EMA + Price at or below Lower BB + RSI oversold
confluenceBuy = (close > emaVal) and (close <= bbLower) and (rsiVal <= rsiOversold)

plotshape(confluenceBuy, title = "Confluence Buy Signal", 
          style = shape.labelup, location = location.belowbar, 
          color = color.green, text = "BUY", textcolor = color.white, size = size.normal)

// Unified alert
if confluenceBuy and barstate.isconfirmed
    alert("Triple confluence buy signal on " + syminfo.ticker, alert.freq_once_per_bar_close)

Step-by-step checklist for merging third-party Pine Scripts

When combining open-source scripts from TradingView Community Scripts, follow this orderly process to prevent errors:

  • Unify version headers: Ensure only one //@version=6 directive exists at line 1. Convert older v4 or v5 functions (like security() or rsi()) to modern namespaces (request.security(), ta.rsi()).
  • Consolidate indicator() declarations: Keep only the top-level indicator() call. Remove any additional indicator() or study() declarations.
  • Search and replace variable names: Check for standard variable names like len, src, ma, upper, lower, up, down. Prefix each variable with its indicator family name (e.g. macd_src vs rsi_src).
  • Organize input parameters with groups and inline formatting: Use group and inline parameters in input.* functions to keep settings clean and intuitive in the indicator dialog.

Handling overlay vs. separate pane indicators

A single Pine Script can only be either overlay = true (drawn directly over price candlesticks) or overlay = false (drawn in a separate lower sub-window). If you want to merge an overlay indicator (e.g. Supertrend) with a sub-window indicator (e.g. MACD):

  • Option A (Recommended): Set overlay = true. Plot the moving averages on the chart, and plot shapes, background colors (bgcolor()), or a dashboard table (table.new()) summarizing the sub-window indicators status.
  • Option B: Display the secondary oscillator in an info table in the top-right corner of the chart, showing current RSI or MACD values and status labels (Bullish / Bearish).
  • Option C: Normalize oscillator values to price scale, though this can distort price perspective during major market volatility.
Where Pineify fits

Pine Script AI Coding Agent

Paste multiple Pine Scripts into Pineify and let the AI Coding Agent automatically resolve naming conflicts, unify versions, and output a single clean script.

Also useful: Visual Pine Script Editor. Stack and combine 235+ built-in indicators with drag-and-drop ease, custom confluence rules, and visual alerts with zero coding.

Combine Indicators with AI Agent

Frequently asked questions

Combining technical indicators into confluence systems can reduce false breakouts but may increase signal lag. Technical analysis tools carry inherent market risk and do not guarantee future profitability.

Sources and verification