Syntax for NinjaTrader 7/8
Syntax is the set of rules for constructing proper alert messages for sending Tradingview alerts to NinjaTrader 7/8.
A message is constructed by fields. A field is a parameter-value pair connected by "=". Fields are separated by ",". You can put no space or a few spaces after "," to make message clear to read.
A message for NinjaTrader 7/8 must have "token" and "n_signal" fields.
Except for "token", all fields start with "n_", i.e. "n_signal", "n_qty", "n_symbol", "n_sl_pips". This is different as the syntax for MT4/5
Every message must have a token field which is the master token, you can get your master token on your TradingRouter Dashboard
Here are some syntax examples:
- token=master19dd529542d4b79d2bc4,n_signal=buy,n_symbol=EURUSD,n_qty=1
- token=master19dd529542d4b79d2bc4, n_signal=sell,n_symbol=EURUSD, n_qty=2, n_sl_pips=100
- token=master19dd529542d4b79d2bc4,n_signal=closelong, n_symbol=EURUSD
Market Orders
Syntax for market orders such as buy and sell
buy
Place a buy order at the market price. Usually this order will be filled immediately.
- long
- bull
- bullish
- n_symbol= is a required parameter, it must be in message
- n_qty= is a required parameter, it must be in message
- token=master19dd529542d4b79d2bc4, n_signal=buy, n_symbol=EURUSD, n_qty=1
- token=master19dd529542d4b79d2bc4, n_signal=buy, n_symbol=AUDUSD, n_qty=3, n_sl_pips=100
- token=master19dd529542d4b79d2bc4, n_signal=buy, n_symbol=EURJPY, n_qty=20, n_sl_pct=3
sell
Place a sell order at the market price. Usually this order will be filled immediately.
- short
- bear
- bearish
- n_symbol= is a required parameter, it must be in message
- n_qty= is a required parameter, it must be in message
- token=master19dd529542d4b79d2bc4, n_signal=sell, n_symbol=EURUSD, n_qty=1
- token=master19dd529542d4b79d2bc4, n_signal=sell, n_symbol=AUDUSD, n_qty=3, n_sl_pips=100
- token=master19dd529542d4b79d2bc4, n_signal=sell, n_symbol=EURJPY, n_qty=200, n_sl_pct=3
eaoff
Halts the TradingRouter Strategy. If the Strategy is halted, incoming signals will not be processed.
- token=master19dd529542d4b79d2bc4,n_signal=eaoff
eaon
Reactivates the TradingRouter Strategy from halt.
- token=master19dd529542d4b79d2bc4,n_signal=eaon
close all
For NinjaTrader 8, close all positions and delete all pending orders of the account, regardless of symbol.
For NinjaTrader 7, close all positions created by TradingRouter Strategy and delete all pending orders created by TradingRouter Strategy , regardless of symbol. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- token=master19dd529542d4b79d2bc4,n_signal=closeall,n_symbol=EURUSD (note: if TradingRouter Strategy is running on EURUSD chart, then all positions and pending orders of the account will be closed and deleted in NinjaTrader 8; all positions and pending orders created by TradingRouter Strategy will be closed and deleted in NinjaTrader 7.)
closealleaoff
Close all positions and delete all pending orders, regardless of symbol, then halts the TradingRouter Stratgey. If the strategy is halted, incoming signals will not be processed.
For NinjaTrader 8, all positions and all pending orders of the account will be closed or deleted.
For NinjaTrader 7, all positions created by TradingRouter Strategy and all pending orders created by TradingRouter Strategy will be closed or deleted. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- token=master19dd529542d4b79d2bc4,n_signal=closealleaoff,n_symbol=EURUSD (note: if TradingRouter Strategy is running on EURUSD chart, then all positions and pending orders of the account will be closed and deleted in NinjaTrader 8; all positions and pending orders created by TradingRouter Strategy will be closed and deleted in NinjaTrader 7.)
close
Close all positions of the specified symbol.
For NinjaTrader 8, it closes all positions of the specific symbol of the account.
For NinjaTrader 7, it closes all positions of the specific symbol of TradingRouter Strategy. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- token=master19dd529542d4b79d2bc4,n_signal=closelong,n_symbol=EURUSD
closebuy
Close all positions of the specified symbol and open a new long position of the specified symbol.
For NinjaTrader 8, it closes all positions of the specific symbol of the account.
For NinjaTrader 7, it closes all positions of the specific symbol of TradingRouter Strategy. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- token=master19dd529542d4b79d2bc4,n_signal=closebuy, n_symbol=EURUSD, n_qty=5
closesell
Close all positions of the specified symbol and open a new short position of the specified symbol.
For NinjaTrader 8, it closes all positions of the specific symbol of the account.
For NinjaTrader 7, it closes all positions of the specific symbol of TradingRouter Strategy. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- token=master19dd529542d4b79d2bc4,n_signal=closesell, n_symbol=EURUSD, n_qty=5
Pending Orders
Syntax for pending orders such as buy limit, sell limit, buy stop and sell stop
buylimit
Place a buy limit order below the current market price.
- n_symbol= is a required parameter, it must be in message
- Price Parameter is required
- n_qty= is required
- token=master19dd529542d4b79d2bc4, n_signal=buylimit, n_symbol=EURUSD, n_price_exact=1.023, n_qty=1
- token=master19dd529542d4b79d2bc4, n_signal=buylimit, n_symbol=AUDUSD, n_price_pct=1, n_qty=200, n_sl_pips=100
selllimit
Place a sell limit order above the current market price.
- n_symbol= is a required parameter, it must be in message
- Price Parameter is required
- n_qty= is required
- token=master19dd529542d4b79d2bc4, n_signal=selllimit, n_symbol=EURUSD, n_price_exact=1.231, n_qty=1
- token=master19dd529542d4b79d2bc4, n_signal=selllimit, n_symbol=AUDUSD, n_price_pct=1, n_qty=200, n_sl_pips=100
buystop
Place a buy stop order above the current market price.
- n_symbol= is a required parameter, it must be in message
- Price Parameter is required
- n_qty= is required
- token=master19dd529542d4b79d2bc4, n_signal=buystop, n_symbol=EURUSD, n_price_exact=1.231, n_qty=1
- token=master19dd529542d4b79d2bc4, n_signal=buystop, n_symbol=AUDUSD, n_price_pct=1, n_qty=200, n_sl_pips=100
sellstop
Place a sell stop order below the current market price.
- n_symbol= is a required parameter, it must be in message
- Price Parameter is required
- n_qty= is required
- token=master19dd529542d4b79d2bc4, n_signal=sellstop, n_symbol=EURUSD, n_price_exact=1.0123, n_qty=1
- token=master19dd529542d4b79d2bc4, n_signal=sellstop, n_symbol=AUDUSD, n_price_pct=1, n_qty=200, n_sl_pips=100
Price Parameter (for Pending Order)
Price parameter is used to determine the entry price of pending order. It has the following 3 parameters
- n_price_pips=
- n_price_pct=
- n_price_exact=
These 3 parameters has priorities: n_price_pips= > n_price_pct= > n_price_exact=
You can only put one of the 3 price parameters in your message. If you put more than one price parameters in the message, the highest priority paramter in the message will be used. For example if you put n_price_pct= and n_price_exact= in the message, only n_price_pct= will be used because n_price_pct= has higher priority than n_price_exact= and n_price_pct= is the highest priority parameter in your message.
1. n_price_pips=
n_price_pips= set the entry price to some pips away from current market price
- token=master19dd529542d4b79d2bc4, n_signal=buylimit, n_symbol=EURUSD, n_price_pips=300, n_qty=1 (note: create a buylimit order for 1 quantity of EURUSD, the entry price is 300 below current market price )
- token=master19dd529542d4b79d2bc4, n_signal=buystop, n_symbol=EURUSD, n_price_pips=200, n_sl_pips=100, n_qty=2 (note: create a buystop order for 2 quantity of EURUSD, the entry price is 200 above current market price, the stop loss is 100 pips )
2. n_price_pct=
n_price_pct= set the entry price to some percentage away from current market price
- token=master19dd529542d4b79d2bc4, n_signal=buylimit, n_symbol=EURUSD, n_price_pct=2, n_qty=1 (note: create a buylimit order for 1 quantity of EURUSD, the entry price is 2% below current market price )
- token=master19dd529542d4b79d2bc4, n_signal=selllimit, n_symbol=EURUSD, n_n_price_pct=3, sl_pips=100, n_qty=2 (note: create a selllimit order for 2 quantity of EURUSD, the entry price is 3% above current market price, the stop loss is 100 pips )
3. n_price_exact=
n_price_exact= set the entry price to a specific price
Note: This parameter is not recommended because the entry price may be invalid due to the discrepancy in quotes between TradingView and NinjaTrader. For example, your quote in Tradingview is $10000, but the quote at NinjaTrader is $9998, if you make a buylimit order and set n_price_exact=9999, the entry price is above current market price and is invalid for buylimit order at NinjaTrader.
- token=master19dd529542d4b79d2bc4, n_signal=buylimit, n_symbol=EURUSD, n_price_exact=1.0012, n_qty=1 (note: create a buylimit order for 1 quantity of EURUSD, the entry price is 1.0012 )
- token=master19dd529542d4b79d2bc4, n_signal=selllimit, n_symbol=EURUSD, n_price_exact=1.2342, n_sl_pips=100, n_qty=2 (note: create a selllimit order for 2 quantity of EURUSD, the entry price is 1.2342, the stop loss is 100 pips )
cancellong
delete all buylimit and buystop pending orders of the specified symbol.
For NinjaTrader 8, it deletes all buylimit and buystop pending orders of the account of the specified symbol
For NinjaTrader 7, it deletes all buylimit and buystop pending orders of the specified symbol created by TradingRouter Strategy. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- token=master19dd529542d4b79d2bc4,n_signal=cancellong,n_symbol=EURUSD
cancelshort
delete all selllimit and sellstop pending orders of the specified symbol.
For NinjaTrader 8, it deletes all buylimit and buystop pending orders of the account of the specified symbol
For NinjaTrader 7, it deletes all buylimit and buystop pending orders of the specified symbol created by TradingRouter Strategy. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- token=master19dd529542d4b79d2bc4,n_signal=cancelshort,n_symbol=EURUSD
cancellongbuylimit
delete all buylimit and buystop pending orders of the specified symbol and place a buy limit order below the current market price.
For NinjaTrader 8, it deletes all buylimit and buystop pending orders of the account of the specified symbol
For NinjaTrader 7, it deletes all buylimit and buystop pending orders of the specified symbol created by TradingRouter Strategy. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- n_symbol= is a required parameter, it must be in message
- Price Parameter is required
- n_qty= is required
- token=master19dd529542d4b79d2bc4,n_signal=cancellongbuylimit,n_symbol=EURUSD,n_price_pct=1, n_qty=3, n_sl_pips=100
cancellongbuystop
delete all buylimit and buystop pending orders of the specified symbol and place a buy stop order above the current market price.
For NinjaTrader 8, it deletes all buylimit and buystop pending orders of the account of the specified symbol
For NinjaTrader 7, it deletes all buylimit and buystop pending orders of the specified symbol created by TradingRouter Strategy. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- n_symbol= is a required parameter, it must be in message
- Price Parameter is required
- n_qty= is required
- token=master19dd529542d4b79d2bc4,n_signal=cancellongbuystop,n_symbol=EURUSD,n_price_pct=1, n_qty=3, n_sl_pips=100
cancelshortselllimit
delete all sell limit and sell stop pending orders of the specified symbol and place a sell limit order above the current market price.
For NinjaTrader 8, it deletes all buylimit and buystop pending orders of the account of the specified symbol
For NinjaTrader 7, it deletes all buylimit and buystop pending orders of the specified symbol created by TradingRouter Strategy. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- n_symbol= is a required parameter, it must be in message
- Price Parameter is required
- n_qty= is required
- token=master19dd529542d4b79d2bc4,n_signal=cancelshortselllimit,n_symbol=EURUSD,n_price_pct=1, n_qty=0.3, n_sl_pips=100
cancelshortsellstop
delete all sell limit and sell stop pending orders of the specified symbol and place a sell stop order below the current market price.
For NinjaTrader 8, it deletes all buylimit and buystop pending orders of the account of the specified symbol
For NinjaTrader 7, it deletes all buylimit and buystop pending orders of the specified symbol created by TradingRouter Strategy. You are recommended to close all positions and pending orders before apply TradingRouter Strategy on NinjaTrader 7.
- n_symbol= is a required parameter, it must be in message
- Price Parameter is required
- n_qty= is required
- token=master19dd529542d4b79d2bc4,n_signal=cancelshortsellstop,n_symbol=EURUSD,n_price_pct=1, n_qty=3, n_sl_pips=100
Stop Loss Parameter
Stop loss has the following 3 parameters
- n_sl_pips=
- n_sl_pct=
- n_sl_price=
These 3 parameters has priorities: n_sl_pips= > n_sl_pct= > n_sl_price=
You can only put one of the 3 stop loss parameters in your message. If you put more than one stop loss parameters in the message, the highest priority paramter in the message will be used. For example if you put n_sl_pct= and n_sl_price= in the message, only n_sl_pct= will be used because n_sl_pct= has higher priority than n_sl_price= and n_sl_pct= is the highest priority parameter in your message.
1. n_sl_pips=
n_sl_pips= set the stop loss pips away from the open price of the order. If n_sl_pips=100, then the stop loss is 100 pips away from the open price of the order.
- token=master19dd529542d4b79d2bc4, n_signal=sell, n_symbol=EURUSD, n_qty=1, n_sl_pips=100
- token=master19dd529542d4b79d2bc4, n_signal=buy, n_symbol=AUDUSD, n_qty=2, n_sl_pips=150
2. n_sl_pct=
n_sl_pct= set the stop loss percentage away from the open price of the order. If n_sl_pips=1, then the stop loss is 1 percent away from the open price of the order. For example, if BTCUSD is at $20000, you buy with "n_sl_pct=0.1", then the stop loss is 0.1% away, at $19980.
- token=master19dd529542d4b79d2bc4, n_signal=sell, n_symbol=EURUSD, n_qty=1, n_sl_pct=1
- token=master19dd529542d4b79d2bc4, n_signal=buy, n_symbol=AUDUSD, n_qty=2, n_sl_pct=2
3. n_sl_price=
n_sl_price= set exact price for stop loss. If n_sl_price=1.1234, then the stop loss set at 1.1234.
- token=master19dd529542d4b79d2bc4, n_signal=sell, n_symbol=EURUSD, n_qty=0.1, n_sl_price=1.3012
- token=master19dd529542d4b79d2bc4, n_signal=buy, n_symbol=AUDUSD, n_qty=0.2, n_sl_price=0.6045
Note: This parameter is not recommended because the stop loss may be invalid due to the discrepancy in quotes between TradingView and NinjaTrader, and also due to slippage. For example, your quote in Tradingview is $10000, but the quote at NinjaTrader is $9999, if you make a market buy order and set sl_price=9999, the stop loss is invalid at NinjaTrader. Another example, your quote in Tradingview is $10000, and the quote at NinjaTrader is also $10000, you make a market buy order and set sl_price=9999, but when the order is filled, the open price is $9998 due to slippage, then the stop loss is invalid.
Take Profit Parameter
Take profit has the following 3 parameters
- n_tp_pips=
- n_tp_pct=
- n_tp_price=
These 3 parameters has priorities: n_tp_pips= > n_tp_pct= > n_tp_price=
You can only put one of the 3 take profit parameters in your message. If you put more than one take profit parameters in the message, the highest priority paramter in the message will be used. For example if you put n_tp_pct= and n_tp_price= in the message, only n_tp_pct= will be used because n_tp_pct= has higher priority than n_tp_price= and n_tp_pct= is the highest priority parameter in your message.
1. n_tp_pips=
n_tp_pips= set the take profit pips away from the open price of the order. If n_tp_pips=100, then the take profit is 100 pips away from the open price of the order.
- token=master19dd529542d4b79d2bc4, n_signal=sell, n_symbol=EURUSD, n_qty=1, n_tp_pips=100
- token=master19dd529542d4b79d2bc4, n_signal=buy, n_symbol=AUDUSD, n_qty=2, n_tp_pips=150
2. n_tp_pct=
n_tp_pct= set the take profit percentage away from the open price of the order. If n_tp_pips=1, then the take profit is 1 percent away from the open price of the order. For example, if BTCUSD is at $20000, you buy with "n_tp_pct=0.1", then the take profit is 0.1% away, at $20020.
- token=master19dd529542d4b79d2bc4, n_signal=sell, n_symbol=EURUSD, n_qty=1, n_tp_pct=0.1
- token=master19dd529542d4b79d2bc4, n_signal=buy, n_symbol=AUDUSD, n_qty=2, n_tp_pct=20
Note:
- tp_pct= should be less than 100 for sell order
3. n_tp_price=
n_tp_price= set exact price for take profit. If n_tp_price=1.1234, then the take profit is set at 1.1234.
- token=master19dd529542d4b79d2bc4, n_signal=sell, n_symbol=EURUSD, n_qty=0.1, n_tp_price=1.0012
- token=master19dd529542d4b79d2bc4, n_signal=buy, n_symbol=AUDUSD, n_qty=0.2, n_tp_price=0.9045
Note: This parameter is not recommended because the take profit may be invalid due to the discrepancy in quotes between TradingView and NinjaTrader, and also due to slippage. For example, your quote in Tradingview is $10000, but the quote at NinjaTrader is $10001, if you make a market buy order and set tp_price=10001, the take profit is invalid at NinjaTrader. Another example, your quote in Tradingview is $10000, and the quote at NinjaTrader is also $10000, you make a market buy order and set tp_price=10001, but when the order is filled, the open price is $10002 due to slippage, then the take profit is invalid.