{
  "id": 1220181,
  "title": "How to Catch a Pine Script Repaint Bug Before It Costs You Real Money",
  "url": "https://urgent.news/2026/08/16/how-to-catch-a-pine-script-repaint-bug-before-it-costs-you-real-money",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-16T06:13:54.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/rezali/how-to-catch-a-pine-script-repaint-bug-before-it-costs-you-real-money-38m4"
  },
  "original_language": "en",
  "account": "Repainting bugs in Pine Script can lead to inaccurate backtest results that don't accurately reflect live trading performance. To identify and address repainting bugs before they cost real money, there are four main sources to look out for:\n\n1. Using request.security() with the wrong lookahead parameter. Pulling higher-timeframe values without proper handling can cause the current bar to leak into the calculation. The fix is to use barmerge.lookahead_off and offset the source by one bar, e.g. close[1]. Lookahead_on only works when the source has already been offset.\n\n2. Computing entry signals before the bar closes. Entry logic running on close or ta.crossover() without a barstate.isconfirmed guard can result in signals appearing, disappearing, and reappearing as the forming close price changes. Guard all critical entry/exit logic with barstate.isconfirmed when evaluating intrabar.\n\n3. Ambiguity between same-bar stop and target levels. When stop and target both could have been hit within the same bar's range, the Strategy Tester guesses which occurred first without always making the assumption clear. This hidden assumption can inflate win rates without being noticed.\n\n4. Repainting can be manually tested using TradingView's Bar Replay tool. Step through history bar by bar to see if any signals that appeared in the past match your original observations. If a signal moves, vanishes, or appears retroactively as you replay forward, that's a clear sign of repainting.\n\nA practical example demonstrated how cross-checking the Strategy Tester's results with an independent Python backtest agreed on the strategy's performance metrics. While manual cross-checking is time-consuming, automated tools like codemyedge generate Pine Script from plain English strategy descriptions and run them on real data to preview charts and catch repaints. Using such tools alongside manual verification is recommended before trusting any Strategy Tester numbers in live trading.",
  "summary": "I've watched too many TradingView strategies look great in the Strategy Tester and then fall apart the moment real money went live. Almost every time, the code compiled fine. The bug wasn't syntax. It was repainting, the script quietly using information it shouldn't have had yet. Repainting doesn't throw an error. It just quietly makes your backtest better than your live trading will ever be.…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}