Home › Resources › How to Automate Pine Script Live Trading
How to Automate Pine Script for Live Prop Firm Trading
Running a Pine Script strategy manually — watching for signals, clicking buy and sell in real time — works fine in a paper trading environment. On a live prop firm evaluation, it introduces a different kind of failure mode: human latency, second-guessing, and the psychological weight of a losing session that breaks a trader's adherence to their own system. Automation removes all of that. The strategy either fires or it doesn't. The daily loss limit either stops it or it doesn't. The trader is a spectator.
This guide walks through the complete TradingView + TradersPost + broker stack for automating a Pine Script strategy on a prop firm evaluation or funded account. It covers every step from creating your TradersPost account to the exact alert message format to the Bar Magnifier setting that most traders overlook.
Why automation matters for prop firms
Prop firm evaluations test one thing: whether a trader can execute a rules-based approach consistently over a defined period. The rules are clear — profit target, drawdown limit, daily loss cap, session restrictions. The failure rate is high not because the rules are hard, but because human traders break their own systems under pressure.
Automation enforces the plan mechanically. There are three specific prop firm benefits:
- No emotional entries: The strategy fires at bar close when the conditions are met — not when the trader feels confident enough, or after watching the market for 20 minutes and deciding it "feels right." Emotion-driven overrides are the most common source of out-of-system trades that blow evaluations.
- Consistent rule execution: Session filters, news blackouts, daily kill switches — all of these execute exactly as coded. A human trader might think "just one more trade" at 3:45 PM when the session filter should have halted entries. The algo doesn't. See our guide on passing the Topstep evaluation for more on how daily loss limits interact with automated kill switches.
- Daily loss limits hit automatically: The hardest thing for a losing human trader to do is stop trading for the day. For an algo, it's a single conditional check. Once the daily loss threshold is reached, entries halt. No exceptions. This single feature prevents the majority of evaluation failures that happen in the second half of sessions.
The TradingView → TradersPost → broker stack
The standard automation architecture for prop firm futures trading has three layers:
Each layer has a single job. TradingView generates signals. TradersPost converts those signals into broker API calls. The broker executes the fills on your prop firm account. You watch the P&L and intervene only if something goes wrong.
| Layer | Tool | Cost | Notes |
|---|---|---|---|
| Signal generation | TradingView | Free plan works; Essential+ for more alerts | Pine Script runs here |
| Order routing | TradersPost | ~$25-49/mo | Webhook receiver; converts to broker API |
| Execution | Tradovate or Rithmic | Exchange fees + data | Connected to your prop firm account |
Step 1: Set up your TradersPost account
TradersPost is the webhook middleware that sits between TradingView and your broker. Without it, there's no way to connect a TradingView alert to a live broker order — TradingView itself doesn't place trades.
- Create an account at traderspost.io
- Connect your broker: in TradersPost, go to Brokers and add your Tradovate or Rithmic account. You'll need your broker API credentials (generated from within the Tradovate dashboard or Rithmic's platform).
- Create a Strategy inside TradersPost. Give it a name matching your Pine Script strategy. Select your connected broker and the instrument you'll be trading (e.g., MES1!, MNQ1!, NQ1!).
- Copy your Webhook URL from the TradersPost strategy page. It will look like:
https://webhooks.traderspost.io/trading/webhook/[your-unique-id]/[token]. Keep this URL private — anyone with it can send orders to your account.
Step 2: Connect your broker to your prop firm account
Most futures prop firms use one of two broker platforms: Tradovate or Rithmic. Apex Trader Funding, Take Profit Trader, and MyFundedFutures all support Tradovate. Topstep uses both Tradovate and Rithmic. Your prop firm will provide instructions for connecting their funded or eval account to the broker platform during onboarding.
Once your prop firm account is live in Tradovate:
- Log into Tradovate's API settings and generate an API key (username/password pair or OAuth credentials depending on the plan)
- In TradersPost, under your connected broker, enter these credentials to link the Tradovate account
- Select the specific account ID in TradersPost that corresponds to your prop firm evaluation — Tradovate often shows multiple accounts and you must choose the correct one
- Confirm connectivity with a test order (TradersPost has a built-in test tool that sends a paper order without affecting real positions)
Step 3: Configure your Pine Script strategy for automation
Not all Pine Script strategies are automation-ready. Before creating TradingView alerts, verify your script meets these requirements:
- Bar-close execution: The strategy should use
strategy.entry()insideif barstate.isconfirmedor place entries on bar close, not on intrabar ticks. Bar-close execution prevents repainting and ensures TradingView's backtest results match what happens live. - Built-in alert message format: The script must use Pine Script's native alert message system. If your script has custom alert messages hard-coded in the
alert()oralertcondition()calls, those will NOT work with TradersPost. The strategy needs to generate signals throughstrategy.entry()andstrategy.exit()so TradingView's built-in{{strategy.order.alert_message}}variable works correctly. - Defined stop and target: The strategy should have explicit stop-loss and take-profit values passed to
strategy.exit(). This ensures the backtest and live execution handle exits identically. - Session filter: Include a time-based filter that prevents the strategy from placing entries outside your defined trading window. A simple RTH filter:
inSession = not na(time(timeframe.period, "0930-1600", "America/New_York"))
Every strategy in our store is built to meet all four requirements above and ships with TradersPost-compatible alert configurations.
Step 4: Configure the TradingView alert — the exact message format
This is where most traders make the critical mistake that causes automation to fail silently. The TradingView alert message must be set to exactly:
{{strategy.order.alert_message}}
This is not a custom message. It is a TradingView template variable that expands to a JSON object containing the order action, ticker, and quantity that your Pine Script strategy generated. TradersPost reads this JSON to know what order to place.
To create the alert in TradingView:
- With your Pine Script strategy open and applied to a chart, click the Alert clock icon in the top toolbar
- Under Condition, select your strategy name from the dropdown, then choose Order fills — this fires the alert on every strategy order event (entry, exit, stop)
- In the Message field, delete any default content and enter exactly:
{{strategy.order.alert_message}} - Under Notifications, enable Webhook URL and paste your TradersPost webhook URL from Step 1
- Set Alert name to something descriptive (e.g., "MES Starter — Live Eval")
- Set Expiration to an appropriate end date — TradingView alerts expire and will stop firing if you forget to renew them
- Click Create
{{strategy.order.alert_message}}, TradersPost will receive a text string instead of structured JSON and will reject the alert. No order will be placed. The alert will appear to fire in TradingView's alert log, but nothing will happen in your broker account.Step 5: Enable Bar Magnifier in TradingView for backtest/live parity
Bar Magnifier is a TradingView strategy property that changes how the backtest engine simulates order fills within individual candles. By default, TradingView backtests assume that stop hits and target fills happen at the exact stop/target price on the bar's closing tick. With Bar Magnifier enabled, TradingView uses a higher-resolution intrabar simulation to model stop hits more accurately — catching wicks that would realistically trigger a stop even if the candle closes above it.
To enable Bar Magnifier in your Pine Script strategy:
strategy("My Strategy", overlay=true,
use_bar_magnifier=true)
Or via the TradingView UI: open your strategy's Settings > Properties > enable Use bar magnifier.
For live trading, Bar Magnifier doesn't directly change alert behavior — alerts still fire on bar close. But enabling it ensures your backtest simulates stop hits with the same accuracy as what will happen live, which means your backtest win rate, average trade size, and drawdown metrics better predict live performance. Without it, your backtest may show fewer stop-outs than you'll experience live on intraday wicks.
This is especially important for strategies trading NQ and MNQ, where the intraday wick range can be 50-150 points and mid-candle stop touches are common. See our guide on the Apex consistency rule for how unexpected stop-outs affect consistency metrics.
Common mistakes that break Pine Script automation
After the setup is complete, most problems fall into a small set of recurring errors. Here are the most common, and exactly how to diagnose each one:
1. Wrong alert message format
Symptom: alerts fire in TradingView's alert history, but no orders appear in TradersPost or your broker. Check TradersPost's webhook log — if it shows a text string instead of JSON, the message field is wrong. Fix: delete the alert and recreate it with {{strategy.order.alert_message}} as the only content in the message field.
2. Missing webhook URL
Symptom: alerts fire but nothing reaches TradersPost. In TradingView's alert settings, confirm the Webhook URL field is populated with your TradersPost webhook address. If it's blank, alerts are only firing email/push notifications with no API call. Also verify the webhook URL hasn't expired or been regenerated in TradersPost.
3. Not enabling Bar Magnifier before comparing live vs backtest
Symptom: the strategy shows clean performance in backtest but stops hitting much more frequently in live trading. The backtest is modeling a best-case fill scenario. Enable Bar Magnifier, re-run the backtest, and compare the updated results to live performance. The gap should close significantly.
4. Wrong account selected in TradersPost
Symptom: orders route to a different account than your prop firm evaluation — sometimes a personal account, sometimes the wrong eval. In TradersPost, under your broker connection, verify the selected account ID matches your prop firm evaluation account number. Tradovate shows account IDs clearly in the account switcher.
5. Alert condition set to indicator instead of strategy
Symptom: the alert fires but the message doesn't contain strategy.order.alert_message data — because you set the alert on an indicator signal (a plotted value crossing a level) rather than on strategy order fills. In the TradingView alert condition, make sure the condition is set to your strategy name with the Order fills option, not to a custom indicator cross.
6. Session filter missing or incorrectly configured
Symptom: orders fire at 2 AM when the market is thin and liquidity is poor, resulting in large slippage and unexpected stops. The Pine Script strategy needs a hard session filter that blocks strategy.entry() calls outside your defined trading hours. This is especially critical on evaluations with trailing drawdown, where an overnight gap-induced stop can touch the drawdown floor in a single candle.
How our pre-built strategies handle daily loss limits automatically
Configuring a daily loss kill switch manually in Pine Script is straightforward in theory but error-prone in practice. You need to track running P&L from session open, compare it against a configurable threshold, and halt new entries for the remainder of the session — then reset at the next session open.
Every strategy in our store includes this logic pre-built and tested. The kill switch works as follows:
- Daily P&L tracking: The script calculates realized P&L from the session open tick by tick, separate from any open position's unrealized value
- Configurable threshold: You set the daily loss limit as an input — typically 80% of your firm's hard limit, leaving buffer for slippage on an open position's stop
- Halt on trigger: Once the threshold is reached,
strategy.entry()is blocked for the remainder of the session. Existing positions continue to their stops or targets normally — the kill switch prevents new entries, not existing exits - Session reset: At the start of each new RTH session, the daily P&L counter resets and entries resume if all other conditions are met
This behavior is what separates a prop firm-ready Pine Script from a generic TradingView community script. Most public scripts have no daily kill switch. Running them on a Topstep evaluation with a $1,000 daily loss limit is a question of when — not whether — they'll chain enough losers in a session to hit the limit.
For more on how daily loss limits work across different prop firms, see our guide on passing the Apex evaluation and the Topstep evaluation tips — each firm's daily limit has different implications for kill switch configuration.
Monitoring your automated strategy in live trading
Once automation is running, your job shifts from executing to monitoring. What to watch:
- TradersPost webhook log: Check this after every session for any failed deliveries or malformed payloads. One missed alert = one missed trade or, worse, an unclosed position
- Broker position panel: Verify that your broker shows the expected flat/position status after each trade. If TradingView says the strategy is flat but the broker shows an open position, the exit alert didn't fire or wasn't received
- End-of-day reconciliation: Compare TradingView's strategy P&L to your broker's actual fills for the session. Slippage should be minimal (1-3 ticks on MES/MNQ) — consistent large slippage indicates liquidity issues with your entry timing or stop placement
- Alert expiration: TradingView alerts have expiration dates. Set a calendar reminder to renew your alert before it expires — an expired alert fires nothing, and you may not notice until after a missed session
Ready-built strategies with daily kill switches and TradersPost-compatible alerts.
MES, MNQ, NQ, and ES. Prop firm rules built in. Instant email delivery.
View PlansFAQ — Pine Script automation
What is the best way to automate a Pine Script strategy for prop firm trading?
The TradingView + TradersPost + broker stack is the most reliable approach. TradingView generates order alerts from your Pine Script strategy, TradersPost converts them to broker orders via webhook, and your broker (Topstep via Tradovate, or Apex via Tradovate) executes them. This setup works for MES, MNQ, ES, NQ, and other CME futures.
What should the TradingView alert message be set to for automation?
Set the alert message field to exactly: {{strategy.order.alert_message}} — this tells TradingView to pass the built-in order data (action, instrument, quantity) in each alert. If you set a custom message instead, TradersPost will not receive the correct trade data.
Do I need Bar Magnifier enabled for live trading?
Bar Magnifier improves how TradingView simulates intrabar stop hits during backtesting. For live trading, it doesn't change how orders are sent — alerts still fire at bar close. However, enabling it keeps your live results more consistent with what you saw in the backtest.