Skip to content
TradequixDocsOpen the terminal
OverviewStart here, search, progress
  • Introduction
  • Quickstart
  • How a script runs
  • Types and qualifiers
  • Operators, conditionals and loops
  • Functions and methods
  • Objects and enums
  • Arrays, matrices and maps
  • Strings and colours
  • Time and sessions
  • Bar states
  • Plotting
  • Inputs
  • Technical analysis
  • Drawings and tables
  • Multiple timeframes
  • Strategies
  • Alerts in scripts
  • Repainting
  • The Pine editor
  • Indicator settings
  • Coming from TradingView
  • The data
  • Publish and sell
  • Catalogue and community
  • Your dashboard and earnings
  • Errors and debugging
  • Limits
  • Coverage
  • Built-in catalogue
  • Cookbook
  • Write Pine with AI
  • FAQ
  • Glossary
  • Cheat sheet
  • Function reference
  • Will it run here?
  • Error index

Write

Repainting

Why a signal can look perfect on history and never happen live, the four usual causes, and the patterns that prevent each.

View as MarkdownOpen in ClaudeOpen in ChatGPT

A script repaints when what it shows on past bars differs from what it showed while those bars were live. A repainting strategy backtests beautifully and then loses money, because the signals it was tested on never existed in real time.

The four usual causes#

CauseWhat happensFix
Acting on the live barA condition is true mid-bar, then false at the close, and the marker disappearsRequire barstate.isconfirmed
Higher timeframe with lookaheadrequest.security(..., lookahead_on) on the current value reads the future close of the higher-timeframe bar on historyUse the [1] pattern below
Pivots and "future" barsta.pivothigh(5, 5) confirms five bars late; plotting it back with offset = -5 hides that delayAct on it when it is confirmed, not where it is drawn
varip and per-tick logicValues that change within a live bar cannot be reproduced on historyUse var unless you truly need per-tick state

The non-repainting higher-timeframe pattern#

Request the previous completed bar of the higher timeframe, with lookahead on, so that history and live behave the same:

pine
1//@version=62indicator("HTF close without repainting", overlay = true)3htfClose = request.security(syminfo.tickerid, "60", close[1], lookahead = barmerge.lookahead_on)4plot(htfClose, "1h close (confirmed)", color = color.orange, style = plot.style_stepline)

Confirmed signals#

RunnableSignals that stay
1//@version=62indicator("Signals that stay", overlay = true)3f = ta.ema(close, 9)4s = ta.ema(close, 21)5longSignal = ta.crossover(f, s) and barstate.isconfirmed6plotshape(longSignal, "Long", style = shape.triangleup, location = location.belowbar, color = color.teal)

Checking a script#

Watch it live for a while next to its history: if markers appear and vanish on the forming bar, it acts on unconfirmed data. The checker also warns about lookahead_on and varip.

PreviousAlerts in scriptsNext The Pine editor

On this page

  • The four usual causes
  • The non-repainting higher-timeframe pattern
  • Confirmed signals
  • Checking a script

Use with AI

View as MarkdownOpen in ClaudeOpen in ChatGPT