You've built a Pine Script strategy that backtests beautifully. The equity curve looks great, the win rate is solid, and the drawdown is manageable. Now what?

The brutal truth is that most Pine Script strategies never leave the backtest. TradingView doesn't execute trades — it only generates signals. To run your strategy live, you need a bridge between Pine Script's strategy.entry() / strategy.close() calls and a real broker.

This guide shows you how to take any Pine Script strategy from backtest to live MT5 execution.

How Pine Script Mode Works

A standard TradingView signal bridge uses a two-step confirmation model (alertX → alertY) to prevent accidental trades. But Pine Script strategies generate entries and exits directly — they don't need human confirmation.

Pine Script mode changes the signal flow:

  1. Your Pine Script strategy calls strategy.entry("Long", strategy.long) or strategy.close("Long")
  2. TradingView fires the strategy alert with {{strategy.order.action}} as "buy" or "sell"
  3. The signal server receives it and — because Pine Script mode is enabled — executes immediately without waiting for a confirmation signal
  4. The MT5 EA picks up the signal and opens or closes the position

No two-step confirmation. No loop control. Direct execution that mirrors your backtest.

Setting Up Pine Script Mode

Step 1: Enable Pine Script Mode

Send an alertS signal with pine_script: true to register the strategy:

{
  "action": "alertS",
  "symbol": "EURUSD",
  "magic": 5001,
  "pine_script": true,
  "size": 0.1,
  "sl": 30,
  "tp": 60,
  "trail_activate": 40,
  "trail_distance": 20
}

This tells the signal server: "Magic 5001 is running in Pine Script mode. Execute entries and exits directly."

The sl, tp, and trailing parameters become defaults for every trade this strategy opens — you don't need to repeat them in every alert.

Step 2: Create Your TradingView Strategy Alert

In TradingView:

  1. Add your Pine Script strategy to the chart
  2. Click Alert → set condition to your strategy
  3. Select Order fills only (this fires only when strategy.entry() or strategy.close() triggers)
  4. Set the webhook URL to your signal bridge
  5. Use this message format:
{
  "action": "pine",
  "symbol": "{{ticker}}",
  "magic": 5001,
  "direction": "{{strategy.order.action}}"
}

That's it. When Pine Script enters long, {{strategy.order.action}} becomes "buy". When it closes, it becomes "sell" (or vice versa for shorts).

Step 3: Verify on Demo

Before going live:

  1. Attach the EA to your MT5 demo account
  2. Let the strategy run through a few signals
  3. Compare MT5 trades against TradingView's strategy list
  4. Verify lot sizes, SL, and TP match your defaults

Pine Script Alert Formatting Tips

Handling Both Entries and Exits

If your strategy uses strategy.close(), TradingView sends the close as a sell (for long positions) or buy (for short positions). The signal server in Pine Script mode handles this automatically — it detects whether the signal is a new entry or a close of an existing position.

Passing Dynamic Parameters

You can override default parameters per-signal using Pine's alert_message parameter:

if longCondition
    strategy.entry("Long", strategy.long,
        alert_message='{"action":"pine","symbol":"EURUSD","magic":5001,"direction":"buy","size":0.2,"sl":25}')

This overrides the default lot size and stop loss for this specific entry.

Multi-Symbol Strategies

Run the same Pine Script strategy on multiple symbols by using different Magic Numbers:

Each gets its own isolated state, position tracking, and signal queue.

Pine Script Mode vs. Standard Alerts

Feature Pine Script Mode Standard (alertX/Y)
Execution Immediate Requires confirmation
Use case Algorithmic strategies Manual/multi-timeframe
False alert protection None (trusts strategy) Two-step guards
Setup complexity Simpler More flexible
Best for Backtested strategies Discretionary + automation

Use Pine Script mode when you trust your strategy's signals. Use standard alertX/Y when you want an extra confirmation step or are combining signals from multiple sources.

Common Issues and Fixes

"Strategy works in backtest but not live"

Backtests execute on bar close by default. Live alerts can fire intra-bar. Use Once Per Bar Close as the alert trigger to match backtest behavior.

"Duplicate entries"

If your strategy logic can trigger strategy.entry() multiple times on the same bar, you'll get duplicate signals. Add a check in Pine Script:

if longCondition and strategy.position_size == 0
    strategy.entry("Long", strategy.long)

"Exits not working"

Make sure your strategy.close() ID matches your strategy.entry() ID exactly. Also verify that the signal server's Pine Script mode is enabled for your Magic Number.

"SL/TP not matching backtest"

TradingView backtests calculate SL/TP from the entry price. Live execution may have slippage, meaning the actual entry price differs slightly. Your bridge should calculate SL/TP relative to the actual fill price, not the signal price.

Best Practices for Live Pine Script Trading

  1. Use calc_on_every_tick = false — Matches backtest behavior and prevents excess signals
  2. Set realistic commission and slippage in backtests — So your backtest performance is closer to live
  3. Start with small lot sizes — Scale up only after confirming live execution matches expectations
  4. Monitor the first 20 trades manually — Compare each live trade against what the backtest would have done
  5. Keep a trading journal — Track any discrepancies between backtest and live performance

FAQ

Can I run multiple Pine Script strategies simultaneously? Yes. Each strategy gets its own Magic Number with isolated state. You can run different strategies on different pairs, or even multiple strategies on the same pair.

What happens during market gaps? If the market gaps past your SL, MT5 executes at the next available price (gap fill). This can result in larger losses than your SL setting. This is a broker/market behavior, not a bridge issue.

Do I need to keep TradingView open? No. Once an alert is set, TradingView's servers monitor the condition and fire webhooks even if you close the browser. You do need an active TradingView subscription though.


Turn your Pine Script backtests into live trades. Start with iNakaTrader — Pine Script mode included in Pro and Elite plans.

Risk Disclaimer: Trading forex and other financial instruments involves substantial risk of loss and is not suitable for all investors. Past performance does not guarantee future results. Only trade with capital you can afford to lose. iNakaTrader provides signal execution tools, not financial advice.