How to Automate Pine Script for Live Prop Firm Trading
Watching a chart and clicking buy/sell in real time works fine on paper. On a live evaluation it introduces latency, hesitation, and the psychological weight of a red session. Automation removes all of it — here's the full setup.
Manually executing a Pine Script strategy — waiting for the signal, clicking the order in — is a different failure mode than the strategy itself failing. Human reaction time, second-guessing a valid signal, and the temptation to override a system after a loss are the actual causes behind a lot of blown evaluations, not the underlying rules. Automation takes the trader out of the execution loop entirely: the strategy either fires or it doesn't, and a kill switch either halts trading or it doesn't.
This guide walks through the full TradingView and CrossTrade stack for NinjaTrader 8 and Tradovate accounts, from creating a CrossTrade account to the exact alert message format to the Bar Magnifier setting that trips up a lot of first-time automators.
Why automation matters for prop firms
A prop firm evaluation tests one thing: whether a trader can execute a rules-based approach consistently over a defined stretch. The rules themselves are usually clear — profit target, drawdown limit, maybe a daily loss cap, maybe a session restriction. The failure rate stays high anyway, because human traders break their own systems under pressure far more often than the rules themselves are actually difficult.
Automation enforces the plan mechanically, in three specific ways relevant to a prop firm account:
- No emotional entries. The strategy fires at bar close when its conditions are met — not when a trader feels confident enough after watching the chart for twenty minutes. Discretionary overrides are one of the most common sources of out-of-system trades that blow an evaluation.
- Consistent rule execution. Session filters, news blackouts, and kill switches run exactly as coded, every time. A tired human trader might take "just one more" at 3:45pm when the session filter should have already stopped entries — the script doesn't.
- Daily loss limits actually hit. Stopping trading after a loss is the hardest discipline for most traders to hold. For a script it's one conditional check. See our guide on passing the Topstep Combine for how a daily loss limit interacts with an automated kill switch in practice.
The TradingView → CrossTrade → broker stack
The automation architecture for prop firm futures trading has three layers, each doing exactly one job:
| Layer | Tool | Role |
|---|---|---|
| Signal generation | TradingView | Pine Script runs here and produces entries/exits |
| Order routing | CrossTrade | Receives each webhook alert and turns it into an order |
| Execution | NinjaTrader 8 or Tradovate | Places the live fill on your prop firm account |
TradingView generates the signal, CrossTrade turns it into an order, and NinjaTrader 8 or Tradovate fills it on your account. The trader's job shifts from executing to monitoring: watching the P&L and stepping in only if something looks wrong.
Step 1: Set up a CrossTrade account
CrossTrade is the automation platform between TradingView and your trading account. TradingView alone can't place trades, so without a bridge like this there's no way to connect a chart signal to a live order. Target Filled is built by the team behind CrossTrade, the automation platform we recommend.
- Create a CrossTrade account. CrossTrade offers a 7-day free trial, no credit card required.
- Connect your platform. On NinjaTrader 8, CrossTrade connects through a desktop add-on on the computer that runs NinjaTrader. On Tradovate, you link the account in the cloud, with nothing to install.
- Copy your webhook URL and secret key from your CrossTrade account. Treat both like a password.
Step 2: Connect the broker to a prop firm account
Most futures prop firms run on Tradovate or Rithmic. Apex, Take Profit Trader, and MyFundedFutures all support Tradovate; Topstep supports both. The firm provides connection instructions during onboarding. CrossTrade works with prop firms that offer NinjaTrader or Tradovate, and your firm's current automation rules decide what's allowed, so check them before connecting anything.
- Tradovate account: link it to CrossTrade in your browser.
- NinjaTrader 8 account: connect the firm account inside NinjaTrader as your firm instructs, and keep the CrossTrade add-on running.
- Note the exact name of the evaluation account. It goes on the alert's
account=line, and most platforms list several accounts (simulation, evaluation, personal), so confirm the right one. - Send a test alert against a simulation account to confirm connectivity without risking a real fill.
Step 3: Configure the Pine Script strategy for automation
Not every Pine Script strategy is automation-ready. Before creating any alert, confirm the script meets these requirements:
- Bar-close execution. Entries should fire on a confirmed bar close (Pine Script's
barstate.isconfirmedguard), not on intrabar ticks — this keeps the backtest and the live result consistent. - Native order placeholders. The strategy needs to generate signals through
strategy.entry()andstrategy.exit()so TradingView's order placeholders ({{strategy.order.action}}and{{strategy.order.contracts}}) carry the right values. Signals sent only through a hard-codedalert()call won't fill them in. - Defined stop and target. Explicit values passed to
strategy.exit()keep backtest and live exits identical. - A session filter. A time-based guard that blocks entries outside the intended trading window — a simple RTH filter checks the current time against a defined session string.
Step 4: Configure the TradingView alert — the exact message format
This is where most first-time automators make the mistake that causes automation to fail silently. The alert's Message field carries the order instructions CrossTrade reads. In CrossTrade's format, it looks like this:
key=your-secret-key;
command=place;
account=sim101;
instrument=ES1!;
action={{strategy.order.action}};
qty={{strategy.order.contracts}};
order_type=market;
tif=day; {{strategy.order.action}} and {{strategy.order.contracts}} are TradingView
placeholders: on every order fill, TradingView swaps in the side (buy or sell) and the number of contracts your
strategy just traded. Replace your-secret-key with your own CrossTrade secret key and
sim101 with the exact name of the account you want to trade, and set instrument to the
market you trade. If you use a Target Filled Pro strategy, the CrossTrade-ready message
is already built in, and its setup guide shows exactly what goes in this field.
- With the strategy applied to a chart, click the Alert icon.
- Under Condition, choose the strategy name, then select Order fills — this fires on every order event (entry, exit, stop).
- In the Message field, clear any default text and paste your CrossTrade message.
- Under Notifications, enable Webhook URL and paste your CrossTrade webhook URL from Step 1.
- Name the alert descriptively (e.g. "MES VWAP, eval account") and set an appropriate expiration date.
- Click Create.
your-secret-key, or an account name that doesn't match exactly, won't reach the
account you meant to trade. After the first test alert, check the account itself, not just the alert log.
Step 5: Enable Bar Magnifier for backtest/live parity
Bar Magnifier changes how TradingView's backtest engine simulates fills within a single candle. By default, TradingView assumes a stop or target fills at its exact price when the bar closes past it. With Bar Magnifier on, the engine uses higher-resolution intrabar data to model stop hits more realistically — catching a wick that would genuinely have triggered a stop even if the bar closed on the other side of it.
strategy("My Strategy", overlay = true, use_bar_magnifier = true) Or via the UI: Settings → Properties → Fill orders → Using bar magnifier. It doesn't change how live alerts fire — those still trigger on bar close either way — but it does make the backtest's win rate, average trade, and drawdown numbers a more honest preview of live performance. Without it, a backtest can look cleaner than live trading will actually be, especially on wick-heavy instruments like NQ and MNQ. See our guide on the Apex consistency rule for how an unexpected stop-out can ripple into consistency metrics on a funded account.
Common mistakes that break Pine Script automation
1. Wrong alert message format
Symptom: alerts fire in TradingView's history but no order reaches the account. Compare the Message field line by line against the format in Step 4: the key, the account name, and the instrument all have to be your real values, not the placeholders. Delete the alert and recreate it with the corrected message.
2. Missing webhook URL
Symptom: alerts fire but no order is placed. Confirm the alert's Webhook URL field holds your CrossTrade webhook URL. A blank field means the alert is only firing a notification, with no webhook call behind it.
3. Never enabling Bar Magnifier
Symptom: clean backtest, noticeably worse live fills. Enable it, rerun the backtest, and compare the updated numbers to live performance — the gap should close substantially.
4. Wrong account in the alert message
Symptom: orders route to the wrong account, sometimes a personal one, sometimes the wrong evaluation. Verify that the account= line in the alert message matches the intended evaluation account exactly.
5. Alert set on an indicator instead of the strategy
Symptom: the alert fires but carries no order data, because the condition was set against a plotted indicator value rather than the strategy's order fills. Confirm the alert condition targets the strategy name with Order fills selected.
6. Missing or misconfigured session filter
Symptom: orders firing overnight when the market is thin, producing outsized slippage. A hard session filter blocking entries outside the intended hours is especially important on a trailing-drawdown account, where an overnight-gap-induced stop can eat into the floor in a single candle.
Building a daily kill switch that actually holds
A daily loss kill switch is simple in concept — track realized P&L from session open, compare it to a threshold, halt new entries once it's crossed, reset at the next session — but easy to get subtly wrong in practice (forgetting to exclude an already-open position's unrealized P&L from the reset, for example). The working shape:
- Daily P&L tracking from the session's opening equity, tracked separately from any open position's unrealized value.
- A configurable threshold — typically 75–85% of the firm's published limit (or of a self-imposed cap, on firms with none), leaving room for slippage on the exit that actually closes the position.
- A hard halt on new entries once the threshold is crossed. Existing positions still manage to their own stop/target — the kill switch blocks new entries, not open exits.
- A session reset at the start of the next trading day, resuming entries if every other condition is satisfied.
This is one of the clearest differences between a script written for a rule-bound account and a generic public TradingView script, since most public scripts have no kill switch at all. Running one on an account with a real daily loss limit is a question of when, not whether, it eventually chains enough losers in a session to breach it. For more on how limits differ by firm, see our guides on passing the Apex evaluation and passing the Topstep Combine. Each firm's rule set has different implications for how a kill switch should be configured.
A script-level kill switch only knows what the strategy knows. CrossTrade's Account Manager adds a second layer at the account: a max daily loss, a max daily profit, and a trailing drawdown per account. When one is hit, it flattens positions and locks the account, and it can also flatten on a schedule at end of day. It works on NinjaTrader and Tradovate; on NinjaTrader, the limits only run while NinjaTrader and the CrossTrade add-on are running. Set it a step inside your firm's limits, as a backstop rather than a guarantee.
Monitoring an automated strategy in live trading
Once automation is running, the job shifts from executing trades to watching the system. What to check regularly:
- TradingView's alert log: check after every session that an alert fired each time the strategy traded. One missed alert can mean one missed trade, or worse, a position left open.
- The broker's position panel — confirm it matches what TradingView's strategy believes is the current position. A mismatch usually means an exit alert didn't fire or wasn't received.
- End-of-day reconciliation — compare the strategy's backtest-style P&L to the broker's actual fills. A few ticks of slippage is normal on MES/MNQ; consistently large slippage points to a liquidity or timing issue.
- Alert expiration — TradingView alerts expire on a set date. An expired alert fires nothing, and a missed session might not be noticed until after the fact.