How to Automate TradingView Strategies with CrossTrade
Learn how to automate your TradingView strategy and send real-time trading signals directly into NinjaTrader 8 using CrossTrade.

When using CrossTrade to send order instructions from TradingView to NinjaTrader, you'll need to understand how TradingView strategies operate and how NT8 requires certain information to perform open and closing actions. This guide is designed to take you from zero-to-hero on how to automate your TradingView strategy with CrossTrade to ensure NinjaTrader 8 executes orders as expected.
We get it, but not all strategies are created equal so we need to cover different options and determine the best method for your strategy,
Is the Strategy Open or Closed Source?
The first thing to determine is whether or not you have access to the strategyâs Pine Script, and want to modify the source code.
If the script is open source, youâll see the full Pine Script in the Pine Editor. This is the best-case scenario, because it means you can:
- Customize or add your own
strategy.order.alert_message
fields - Calculate TP/SL levels and encode them directly into the alert message
If itâs closed-source, you will only see a pane like this:
â ď¸ âThis script is protected. The source code is not available.â
Closed-source strategies can't be modified. This limits what can be done with native alert messages, but there are still options at your disposal. Let's keep going...
Creating CrossTrade specific Strategy Messages
The best way to automate a strategy is by creating specific strategy messages that hold all of the CrossTrade payload needed to communicate correct information to NinjaTrader. Here is an example of a buy alert that will supply all the needed fields, along with dynamic stop and target values
// Calculate stop loss and target prices based on 50 ticks
if not na(tickSize)
stopLossTicks = 50 * tickSize
targetTicks = 50 * tickSize
if longCondition
stopLossPrice = close - stopLossTicks
targetPrice = close + targetTicks
alertMessage = 'key=your-secret-key;'
alertMessage += 'command=PLACE;'
alertMessage += 'account=sim101;'
alertMessage += 'instrument=ES 06-25;'
alertMessage += 'action=BUY;'
alertMessage += 'qty=1;'
alertMessage += 'order_type=MARKET;'
alertMessage += 'tif=DAY;'
alertMessage += 'flatten_first=true;'
alertMessage += 'take_profit=' + str.tostring(targetPrice) + ';'
alertMessage += 'stop_loss=' + str.tostring(stopLossPrice) + ';'
strategy.entry("Long", strategy.long, alert_message=alertMessage)
This is only one example, you can use this approach to supply everything needed to fully automate your strategy. For more information and to review the source script above â> read more
My Strategy is Closed Source, What Now?
The next step is to determine what the strategy offers for alert conditions. Most strategies will offer a few options for conditional triggers. When you click "Create Alert", under Condition, hereâs what you might see:

Lets discuss what each of these options mean and which one you will want to use for automating your strategy.
Three typical alert trigger options:
- Order fills and alert() function calls
Alerts are triggered by either event. - Order fills only
Alerts are triggered when a strategy order is filled (like an entry or exit). - alert() function calls only
Alerts are triggered only when the script uses manualalert()
calls.
These options are always the same for all strategies, regardless of the Pine version used. Whatâs not always available, though, is the ability to customize what the alert actually sends.
By default, TradingView strategy alerts rely on the {{strategy.order.action}}
variable to execute. However, this order action is ridged and does not allow defining specific actions, in the same way you can create very specific alerts when developing indicators.
If you do have source access, you can customize the script and utilize the strategy.order.alert_message
variable to build a full CrossTrade-compatible message directly in Pine Script.
This is the most accurate way to automate your strategy.
If the strategy is closed-source, youâll need to use the default alert payload shown below. Depending on the strategy type, we can modify this command by adding in other Advanced Enhancement Options.
command=PLACE;
account=sim101;
instrument=ES 06-25;
action={{strategy.order.action}};
qty={{strategy.order.contracts}};
order_type=MARKET;
tif=DAY;
What If Thereâs No Condition Triggers?
This is where many users get stuck. If the script author didnât define a strategy.order.alert_message
in their Pine code, TradingView wonât inject helpful variables into the alert.
You will still see a Message box, but it will be pre-filled with a generic log message like:
âOrder {{strategy.order.action}} filled on {{ticker}}â
This looks helpful at first, but it canât be used to dynamically control trading behavior unless you reformat it to match CrossTradeâs expected webhook format â and even then, itâs limited to the few placeholders TradingView supports.
Can You Automate a Strategy Without Modifying It?
Yes â but with limitations.
If you canât modify the Pine code, youâll need to:
- Use the default webhook format that includes placeholders like
{{strategy.order.action}}
- Manually insert a valid CrossTrade payload into the alert message
- Be okay with using static values for things like instrument or account
This is how CrossTrade supports closed-source strategies out of the box.
Itâs not as flexible as building a custom script, but itâs enough to route basic buy and sell orders from TradingView into NinjaTrader.
Summary: What Kind of Strategy Are You Working With?
Strategy Type | What You Can Do | Automation Path |
---|---|---|
â Open-source with alert messages | Full control over webhook payload | Direct Pine code + CrossTrade |
đ Closed-source with placeholders | Use {{strategy.order.action}} in alert message | Manual CrossTrade alert |
â Closed-source with no message logic | Canât automate directly | Rebuild as indicator + XT Alert Builder |
Commands for Various Strategies
1. Stop and Reverse Strategy
- Use
flatten_first=true;
to clear opposing position before placing the new one. - Example: Momentum crossover strategies that alternate between long and short.
key=your-crosstrade-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action={{strategy.order.action}};
qty={{strategy.order.contracts}};
order_type=MARKET;
tif=DAY
flatten_first=true;
2. Entry + TP/SL (Bracket Orders)
- Use
PLACE
with aMARKET
entry, followed byBRACKET
commands (limit/stop).
You will need separate commands for your Entry and Exit. The exit will utilize the enhancement require_market_position to validate that a position is open in the NT8 account and is either, long or short.
key=your-crosstrade-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action={{strategy.order.action}};
qty={{strategy.order.contracts}};
order_type=MARKET;
tif=DAY
take_profit=100ticks;
stop_loss=100ticks;
If you're relying on the take profit and stop loss levels to take you out of the trade, you do not need the following close position command:
key=your-crosstrade-secret-key;
command=CLOSEPOSITION;
account=sim101;
instrument=ES 06-25;
require_market_position=long,short;
Lastly, if you want to instead use a NT8 ATM Strategy Template for the trade management instead of the take_profit and stop_loss values, you can do that by adding the 'strategy' field to your message. Its important to also include the flatten first enhancement to ensure any existing ATM pending orders are canceled when a new entry is submitted.
key=your-crosstrade-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action={{strategy.order.action}};
qty={{strategy.order.contracts}};
order_type=MARKET;
tif=DAY
strategy=your-atm-strategy;
flatten_first=true;
3. Partial Exits
- Use
quantity=X;
in exit alerts to scale out. - You can either scale out via a percentage or number of contracts.
Example: the total position is 3 contracts and you scale out using a partial amount of 33% across three separate exits.
key=your-crosstrade-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action={{strategy.order.action}};
qty={{strategy.order.contracts}};
order_type=MARKET;
tif=DAY
key=your-crosstrade-secret-key;
command=CLOSEPOSITION;
account=sim101;
instrument=ES 06-25;
require_market_position=long,short;
quantity=0.33;
4. One-Side Only (Long Only / Short Only)
- Alert logic only fires for one direction. Disable the other by adding require_market_position
key=your-crosstrade-secret-key;
command=PLACE;
account=sim101;
instrument=ES 06-25;
action={{strategy.order.action}};
qty={{strategy.order.contracts}};
order_type=MARKET;
tif=DAY
key=your-crosstrade-secret-key;
command=CLOSEPOSITION;
account=sim101;
instrument=ES 06-25;
require_market_position=long;
Wrapping It Up: Automating Your Strategy the Right Way
Whether you're working with a fully customizable open-source strategy or a locked-down closed-source script, CrossTrade makes it possible to bring real-time automation to your TradingView signals with NinjaTrader 8. The key is knowing what kind of access you have â and choosing the right automation path based on that.
â
Open-source strategy? Inject Pine-powered logic and send rich, dynamic webhook messages with full control through the {{strategy.order.alert_message}} variable
đ Closed-source strategy? Use CrossTradeâs default payload templates with supported placeholders. Bear in mind that because the strategy is closed-source, automation capabilities are limited.
Use the sample commands above to guide your setup, test each condition carefully, and you'll be routing trades from chart to execution with confidence.
If you run into trouble or need help crafting your alert messages, the CrossTrade community and team are always here to help.
