Common Pine Script mistakes that break live execution
A strategy can pass every backtest and still misfire the moment it's live. These are the recurring Pine mistakes that cause it — each with the symptom and the fix.
Most live failures trace back to a short list of modelling and execution errors. Work through them before you automate.
The list
- Acting on the unclosed bar. Symptom: signals that vanish or shift. Fix: gate on
barstate.isconfirmed. See repainting. - Lookahead in request.security(). Symptom: unreal backtest, weak live. Fix:
lookahead_off+ one-bar offset. - No commission/slippage. Symptom: edge evaporates live. Fix: model both in
strategy(). See backtest vs live. - Alert spam. Symptom: dozens of fills, bridge chaos. Fix: alert once per confirmed signal, not every tick.
- Hardcoded contract size. Symptom: wrong size across accounts. Fix: send
{{strategy.order.contracts}}, size by account. - Ignoring sessions / EOD. Symptom: positions held into closes that breach futures rules. Fix: session filters and a flat-by-close guard on futures.
- Order-fill timing. Symptom: fills you couldn't get. Fix:
process_orders_on_closewhere appropriate; don't assume perfect limit fills. - max_bars_back errors. Symptom: script breaks on load. Fix: set an explicit
max_bars_backfor long historical references.
The pattern
Every one of these flatters the backtest and punishes you live. A robust system is built confirmed-bar, cost-aware and session-aware from the start — then stress-tested with walk-forward and Monte Carlo.
Puravida Edge strategies are hardcoded, fire on confirmed bars, account for costs, and flatten before the close on futures presets — the opposite of every item above.
FAQ
Why does my strategy work in backtest but not live?
Almost always one of these: it repaints, uses lookahead data, ignores costs, spams alerts, hardcodes size, or holds into sessions it shouldn't. Each looks fine in the tester and fails live.
How do I stop my Pine alerts from firing too often?
Trigger alerts only on a confirmed signal (barstate.isconfirmed) rather than on every tick, and make sure the condition can't re-fire while a position is already open.
How do I make my strategy flatten before the close?
Add a session/time filter that closes positions before the cash close — essential for futures prop accounts with end-of-day rules.
Not financial advice. Performance figures referenced are hypothetical, modeled outputs (1,500-path Monte Carlo on a 12-month sample). Past performance does not guarantee future results. Tool names are referenced for education; verify current features and prop-firm rules directly.