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.

how-to-automate-tradingview-strategies-with-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.

😴
TL;DR - Just tell me what to do!
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...

If the strategy is closed-source, or you do not intend to write custom pine script, scroll down to Part 2

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:

  1. Order fills and alert() function calls
    Alerts are triggered by either event.
  2. Order fills only
    Alerts are triggered when a strategy order is filled (like an entry or exit).
  3. alert() function calls only
    Alerts are triggered only when the script uses manual alert() 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.

⚙️
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;

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 TypeWhat You Can DoAutomation Path
✅ Open-source with alert messagesFull control over webhook payloadDirect Pine code + CrossTrade
🔒 Closed-source with placeholdersUse {{strategy.order.action}} in alert messageManual CrossTrade alert
❌ Closed-source with no message logicCan’t automate directlyRebuild 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)

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

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.


Start your free trial

Try CrossTrade for 7 days.

Sign Up