Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124

Creating indicators or strategies in TradingView often requires combining multiple conditions. But when not done properly, these scripts can repaint, causing misleading signals. This article provides a complete walkthrough of how to use pine script add multiple conditions without repainting example correctly, ensuring your signals are stable, confirmed, and reliable. The methods below follow best practices used by experienced Pine Script developers.
Repainting is one of the most misunderstood concepts for new Pine Script coders, yet preventing it is crucial. Since we’re working with the keyword pine script add multiple conditions without repainting example, we’ll explore concepts that ensure multiple conditions behave predictably.
Repainting occurs when signals change after a bar closes. It happens mainly because:
A repainting script produces signals that look perfect historically but fail in real trading behavior.
Stable conditions help you:
If your script repaints, then all performance metrics become unreliable.
To combine multiple conditions without repainting, you must use Pine Script tools that lock in values.
barstate.isconfirmed and Its Role in Preventing Repaintingbarstate.isconfirmed ensures that logic only triggers after the bar closes, making signals stable.
Example:
if barstate.isconfirmed
confirmedSignal := condition
close[1], etc.) CorrectlyHistorical values never change, so referencing them is always safe.
Safe structure:
longCondition = condA and condB and condC
Unstable structure:
longCondition = ta.crossover(close, ema) and condB // can repaint
Below is the main section dedicated to demonstrating how to use multiple conditions while keeping the indicator 100% non-repainting.
To keep conditions stable:
ta.crossover()//@version=5
indicator("Non-Repainting Multi-Condition Example", overlay=true)
emaFast = ta.ema(close, 9)
emaSlow = ta.ema(close, 21)
// Use last bar values to lock signals
crossUp = ta.crossover(emaFast[1], emaSlow[1])
rsi = ta.rsi(close, 14)
rsiConfirm = rsi[1] > 50
longCondition = crossUp and rsiConfirm
plotshape(longCondition, style=shape.labelup, color=color.green, size=size.small)
✔ No repainting because all values reference [1] (previous bar).
//@version=5
strategy("Non-Repainting Multi-Condition Strategy", overlay=true)
ema = ta.ema(close, 20)
macd = ta.macd(close, 12, 26, 9)
// Confirmed values only
trendUp = close[1] > ema[1]
macdBull = macd[0][1] > 0
entryLong = trendUp and macdBull and barstate.isconfirmed
if entryLong
strategy.entry("Long", strategy.long)
✔ All values use confirmed bar logic
✔ No future referencing
✔ Safe for backtesting
Never use these inside strategy entries:
❌ ta.crossover(close, ema) on real-time bars
❌ Conditions evaluated before bar closure
❌ Higher timeframe series without lookahead = barmerge.lookahead_off
Always use:
security(symbol, timeframe, expression, lookahead=barmerge.lookahead_off)
var and Confirmed BarsA stable buffer:
var bool signal = false
if barstate.isconfirmed
signal := condition
Most repainting issues stem from HTF misuse. Lock your HTF values using the correct lookahead mode.
This causes flickering signals.
Fix: Use only historical or confirmed data.
security()Never use:
lookahead_on
Always use:
lookahead_off
Check for repainting by enabling bar-replay and toggling real-time mode.
Use bar replay and compare real-time vs historical signals.
close[1] always prevent repainting?Yes—historical values never change.
ta.crossover() repaint?Yes, unless you reference previous values.
security() always repaint?No—only when using the wrong lookahead mode.
Yes—when combined improperly.
Yes; always test your logic first.
Mastering pine script add multiple conditions without repainting example requires understanding confirmed bars, historical data, and safe condition combinations. By structuring logic properly and avoiding future data, you ensure your indicators generate consistent and reliable signals that traders can trust.