Skip to main content
On this page

Combine Two Indicators in TradingView Pine Script

· 4 min read
Pineify Team
Pine Script and AI trading workflow research team

Combining indicators means calculating their values inside one Pine script and defining how the conditions interact. Combining two conditions can reduce the number of signals, but it does not automatically improve their profitability or make the evidence independent.

Build an RSI and EMA Example​

The Best Pine Script Generator

Open Pine Editor using the current toolbar control. The editor guide describes the interface. The next five code blocks are consecutive parts of one indicator, not five standalone scripts. Paste them together in order.

1. Declare the Indicator​

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify

//======================================================================//
// ____ _ _ __ //
// | _ \(_)_ __ ___(_)/ _|_ _ //
// | |_) | | '_ \ / _ \ | |_| | | | //
// | __/| | | | | __/ | _| |_| | //
// |_| |_|_| |_|\___|_|_| \__, | //
// |___/ //
//======================================================================//

//@version=6
indicator("[Pineify - Best Pine Script Generator] Combined Indicator", overlay=true)

2. Calculate the Inputs to the Rule​

// RSI Calculation
rsiValue = ta.rsi(close, 14)

// EMA Calculation
emaValue = ta.ema(close, 50)

The lengths 14 and 50 are example parameters. RSI and EMA use related price history; assigning them to different indicator categories does not make them statistically independent.

3. Define the Conditions​

buySignal = (rsiValue < 30) and (close > emaValue)
sellSignal = (rsiValue > 70) and (close < emaValue)

The example asks for low RSI while price remains above the EMA, or high RSI while it is below. These combinations can be uncommon. They are states, not crossover events, so a condition can remain true on consecutive bars. Do not assume that each marker represents a new independent trade.

4. Plot the States​

plotshape(buySignal, style=shape.labelup, location=location.belowbar, color=color.green, title="Buy Signal")
plotshape(sellSignal, style=shape.labeldown, location=location.abovebar, color=color.red, title="Sell Signal")

5. Expose Alert Conditions​

alertcondition(buySignal, title="Buy Alert", message="RSI & EMA Buy Signal Triggered")
alertcondition(sellSignal, title="Sell Alert", message="RSI & EMA Sell Signal Triggered")

After adding the indicator, create an alert in TradingView and select the relevant condition. Alert configuration and the script's realtime behavior determine when a notification is produced.

A Separate MACD and RSI Example​

The following is a complete alternative script. Keep it in a separate file from the first indicator declaration.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify

//======================================================================//
// ____ _ _ __ //
// | _ \(_)_ __ ___(_)/ _|_ _ //
// | |_) | | '_ \ / _ \ | |_| | | | //
// | __/| | | | | __/ | _| |_| | //
// |_| |_|_| |_|\___|_|_| \__, | //
// |___/ //
//======================================================================//

//@version=6
indicator("[Pineify - Best Pine Script Generator] MACD & RSI Combined", overlay=false)

// MACD Calculation
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)

// RSI Calculation
rsiValue = ta.rsi(close, 14)

// Buy/Sell Conditions
buyCondition = (macdLine > signalLine) and (rsiValue < 30)
sellCondition = (macdLine < signalLine) and (rsiValue > 70)

// Plotting Signals
plotshape(buyCondition, style=shape.triangleup, location=location.belowbar, color=color.green)
plotshape(sellCondition, style=shape.triangledown, location=location.abovebar, color=color.red)

[Pineify - Best Pine Script Generator] MACD & RSI Combined

This example displays condition markers in a separate pane. It does not place orders or measure trade returns. Current-bar values can change before the close; inspect that behavior before configuring alerts.

Check the Combination Rather Than Assuming Confluence​

Compare the individual and combined conditions over the same period. Count which observations are removed and examine both favorable and unfavorable outcomes. If you want trade statistics, define explicit entries, exits, sizing and costs in a separate strategy.

More conditions can create contradictory or rarely satisfied rules. Test on a later period that was not used to select parameters, and do not treat a successful example chart as a benchmark.

Combine Conditions With Pineify​

Pineify | Best Pine Script Editor

Pineify offers a visual workflow for combining indicator conditions. A combined script may occupy one indicator slot, but it still faces Pine's resource and execution limits. It does not provide unlimited calculations, plots or data requests.

Pine Script Multiple Indicator

Review generated source, input defaults and plot placement. Check current plans before assuming a particular feature is free or included for life.

Does combining indicators guarantee fewer losing trades?

No. It changes which observations satisfy a rule. Evaluate the complete strategy and include the opportunities it filters out.

Can I combine more than two calculations?

Yes, within Pine's documented limits. Complexity, redundant information and sparse conditions can make evaluation harder.

Are these strategies?

No. Both examples are indicators with visual conditions. Trading results require explicit order and risk rules.