Detect Pine Repainting and Lookahead Bias with Antei AI
Learn how to detect Pine repainting and lookahead bias in Antei AI, review warnings and fixes, and backtest safer Hyperliquid strategy logic.

On this page
Quick Answer
Pine Script repainting happens when a signal changes or disappears after new market data arrives. Lookahead bias happens when a historical backtest uses information that was not available at the moment a trade decision was supposedly made. Both can make a strategy look far more accurate than it would be in live trading.
Antei AI helps you investigate these risks before deployment. Import the Pine strategy, review its warnings and Security mode, use validated suggestions in the Fixes tab, and compare backtest behavior with live-safe assumptions. A warning is evidence to investigate—not proof that every strategy is invalid—and you should always review the source logic yourself.
Key Takeaways
Repainting changes past signals; lookahead bias gives a historical decision access to future information.
Higher-timeframe
request.security()calls are a common source of misleading historical results.barmerge.lookahead_offis appropriate in many cases, while the confirmed higher-timeframe patternexpression[1]withbarmerge.lookahead_oncan also avoid future leakage.barstate.isconfirmedhelps prevent signals based on an unfinished chart bar, but it does not repair a future-leaking security request.In Antei AI, review Warnings, Security mode, Fixes, and the backtest lookahead notice before paper trading or deploying.
What Repainting and Lookahead Bias Mean
Repainting
A script repaints when a value or signal shown on a previous bar changes after later data arrives. This can happen when the strategy acts on an unfinished realtime bar, uses higher-timeframe values before that higher-timeframe candle closes, or recalculates logic differently on historical and realtime bars. A buy marker that appears during a candle and disappears by the close is a practical example.
Lookahead Bias
Lookahead bias is a backtesting error. It occurs when a historical calculation uses information that would only become known later. For example, a strategy cannot use the final close of a one-hour candle to place a trade thirty minutes before that candle closes. The problem is not simply “using the current close”; it is using finalized information earlier than it was actually available.
These issues are related but not identical. A strategy can repaint without intentionally looking ahead, and a backtest can contain lookahead bias even when the chart looks stable after the fact.
How to Inspect a Pine Strategy in Antei AI
1. Import the Pine Script
Open Pine Script in Antei AI and choose Upload file or Paste or edit code. Add the strategy name, market, and chart timeframe, then import the strategy. Use the same market and timeframe you plan to test so that warnings and results are interpreted in the correct context.

Import the real Pine strategy and confirm its market and chart timeframe in Antei AI.
2. Review Warnings and Security Mode
Open the imported strategy and check its Overview. Antei displays the Pine version, market, chart timeframe, declared capital, Security mode, program identifier, and any warnings to review. Security mode matters because TradingView parity can reproduce historical behavior that includes future-data semantics, while As live is intended to reflect information availability more like realtime execution.
Expand each warning and trace it back to the relevant line of Pine code. Do not dismiss a warning because the equity curve looks good; unusually smooth returns, perfect turns, or near-perfect entries are reasons to inspect the logic more carefully.

The Strategy Overview shows Security mode and warnings that should be reviewed before deployment.
3. Check Validated Fixes
Open the Fixes tab and select Check for fixes. Antei can surface validated suggestions for the current program, including a lookahead fix when one applies. Applying a suggestion saves a new version, so compare the proposed change with your intended strategy logic before accepting it.

Use Check for fixes to review validated suggestions, including applicable lookahead fixes.
A Valid Pine Script Lookahead Example
This higher-timeframe request can leak the final value of the containing higher-timeframe bar across historical lower-timeframe bars when lookahead is enabled:
// Potential historical lookahead leak
htfClose = request.security(
syminfo.tickerid,
"60",
close,
lookahead = barmerge.lookahead_on
)One common non-repainting pattern is to request the previously confirmed higher-timeframe value:
// Previously confirmed higher-timeframe close
htfClose = request.security(
syminfo.tickerid,
"60",
close[1],
lookahead = barmerge.lookahead_on
)Depending on the strategy, barmerge.lookahead_off may also be appropriate. The correct choice depends on when the strategy is supposed to receive the higher-timeframe value. Avoid rules such as “always use lookahead off” without checking the intended execution timing.
If the issue is an unfinished chart bar, barstate.isconfirmed can help delay a signal until that bar closes. It does not, however, fix a request.security() expression that already exposes future higher-timeframe information.
Backtest the Corrected Version
Open the Backtest tab, choose a date range and initial capital, and run the corrected strategy against historical data. Compare the original and corrected versions using the same test settings. If performance collapses after the leak is removed, the earlier result was likely benefiting from unavailable information.

Run the corrected version with consistent dates and capital so the comparison is meaningful.
Inspect any lookahead notice or leak classification shown with the result. Also review trades for impossible timing: entries before a confirming candle closed, trades placed at a price that was not yet observable, or signals that only exist on the finished historical chart. A backtest is evidence, not a guarantee; paper trading is still necessary before live deployment.
Common Failure Modes
Assuming a high win rate proves the code is good: unrealistically clean performance can be a symptom of future-data leakage.
Using the completed higher-timeframe candle too early: the final value is not available until that candle closes.
Treating every current-bar reference as lookahead: current-bar data can be valid when the order is evaluated at the correct time. The timing relationship is what matters.
Relying only on
barstate.isconfirmed: it addresses partial chart bars, not every form of higher-timeframe leakage.Applying a fix without reviewing the new behavior: a technically safe change can still alter the strategy’s intended signal timing.
Frequently Asked Questions
How does Antei AI detect repainting and lookahead risk?
Antei analyzes the imported Pine program and can surface repainting warnings, lookahead leak information, Security mode, and validated fix suggestions. No automated check can prove every complex script is safe, so the developer must still review the code and test realtime behavior.
Does a repainting warning block deployment?
A warning is informational and should be investigated. Backtest results can also carry a lookahead notice when future information affected a run. Review the exact warning, Security mode, and result details instead of treating every warning as the same severity.
Can I fix lookahead bias automatically?
The Fixes tab may offer a validated suggestion when an applicable lookahead fix is available. Review the proposed version and rerun the backtest because changing data timing can change entries, exits, and overall performance.
How can I tell whether a signal repaints?
Compare the signal during the live candle with the signal after the candle closes, then repeat the test after a refresh or recalculation. If a historical marker moves or disappears, inspect partial-bar logic and higher-timeframe requests.
What should I do before live deployment?
Resolve unexplained warnings, compare TradingView-parity and live-safe behavior where relevant, rerun the corrected backtest, and paper trade the strategy. Only then consider a small, controlled live deployment.
Start with a Safer Pine Workflow
Create an Antei AI account to import your Pine strategy, inspect warnings and Security mode, review applicable fixes, and backtest the corrected version before deployment.
Risk Note
This article is for educational purposes only and is not investment advice. Trading perpetual futures with leverage involves substantial risk. You can lose all capital allocated to a position, and backtests or paper-trading results do not guarantee future performance. Review every strategy carefully and use risk controls before trading live.


