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

A merged script occupies one script instance, but still has limits on plot counts, execution time, data requests, and memory. Merge calculations only when you have editable source and permission to reuse it. Shared values can then feed an explicit combined condition. The example below requires price above an EMA, a close at or below the lower Bollinger Band, and RSI below a chosen threshold; it does not require an EMA crossover or establish that those conditions improve returns.

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 paneUse overlay = false for the oscillator pane and force_overlay = true on supported price plots to place those on the main chart
Version mismatchesOne script is v4 or v5, while the other is v6Migrate each script through the applicable version guides and compare behavior; namespace replacement alone is not a complete migration
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 display toggles, input groups, and a confirmed-bar combined condition. RSI is calculated for the condition but is not plotted in a separate pane. Toggles hide visuals without disabling signal calculations. Every qualifying closed bar can produce a marker and alert; this is a state condition, not a first-entry event.

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", minval = 1, group = grpEma)

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

grpRsi = "Momentum (RSI)"
rsiLen = input.int(14, "RSI Length", minval = 1, group = grpRsi)
rsiOversold = input.int(35, "RSI Oversold Level", minval = 0, maxval = 100, 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, "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 =====================
// Confirmed-bar condition; each qualifying bar can signal.
confluenceBuy = barstate.isconfirmed and (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
    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: Keep one version annotation, preferably at the top. Follow the migration guides for each older version, including type and evaluation changes, then compare the migrated outputs.
  • 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

The overlay setting chooses the default pane. Pine also supports force_overlay on plot functions and supported drawings, so one script can retain an oscillator pane and place selected price visuals on the main chart. This does not create several independent oscillator panes.

  • Keep an oscillator in its own pane with overlay = false; use force_overlay = true for supported moving-average plots on the price chart.
  • If only the oscillator value is needed, an overlay script can display it in a table instead of adding an oscillator plot.
  • Avoid treating scale.none as a separate oscillator pane. Normalizing oscillator values onto price changes their display interpretation. Add a fresh script instance after changing declaration-level pane settings.
Where Pineify fits

Pine Script AI Coding Agent

Provide the source scripts and desired combined behavior. Ask the coding agent for a proposed merge, an explanation of semantic changes, and an explicit syntax check of the final source.

Also useful: Visual Pine Script Editor. Configure supported indicator modules, conditions, and alerts visually. Check available modules and plan limits before choosing this workflow.

Combine Indicators with AI Agent

Frequently asked questions

Combining conditions changes which bars qualify; fewer signals do not establish better accuracy or returns. This educational indicator does not simulate trades. Syntax validation does not replace chart and alert testing.

Sources and verification