How to Automate TradingView Alerts to Binance (Spot, USDM & COINM Futures)

This is the complete guide to sending TradingView alerts to Binance with TradingView to Anywhere (TTA). It covers setup, the full command reference, strategies, indicators, take profit and stop loss, hedge mode, Multi-Assets Mode, and fixes for the most common errors.

Contents

  1. Before you start
  2. Set up your webhook
  3. Command syntax
  4. Command reference (open, close, cancel, balance)
  5. Automate a strategy
  6. Automate an indicator
  7. Take profit and stop loss
  8. Hedge mode
  9. Multi-Assets Mode (B=MARGIN)
  10. Troubleshooting
  11. Test before going live

1. Before you start

You need:

  • A TradingView account with webhook alerts enabled on your plan
  • A Binance account (Spot or Futures)
  • A TTA webhook for Binance

Binance accounts are selected with the A= parameter:

Account Parameter
Spot (default) A=SPOT
USDM futures A=USDM
COINM futures A=COINM

If you leave out A=, the command is sent to your Spot account.


2. Set up your webhook

  1. Go to TradingView To Binance and scroll to the step-by-step guide.
  2. Create new Binance API keys. Allow Spot, Futures & Margin trading.
  3. Binding your API keys to an IP address is optional, but we recommend it for security. If you do, use this IP address: 34.89.98.97.
  4. Submit your API keys on the TradingView To Binance website and follow the on-screen instructions to finish creating your webhook.
  5. In TradingView, create an alert and paste your webhook URL into the Webhook URL field. Keep the URL private.

3. Command syntax

Every command follows this pattern:

action symbol param=value

Example:

Buy BTC/USDT Quantity=0.01

Rules to remember:

  • **The symbol is case-sensitive ** and must be typed exactly as it appears on Binance. You can get the name from the Binance web URL. The format depends on the account:
Account Symbol format Example
Spot With a slash XRP/USDT
USDM futures No slash BTCUSDT
COINM futures _PERP contract name BTCUSD_PERP
  • No spaces around =. buy BTC/USDT quantity = 0.1 is wrong. buy BTC/USDT quantity=0.1 is correct.
  • One-word parameters can be the full word or the first letter. buy BTCUSDT q=0.1 and buy BTCUSDT quantity=0.1 do the same thing.
  • You can send up to 5 commands in one alert. Put each command on its own line:
SELL BTCUSDT Q=0.05 A=USDM
SELL BTCUSD_PERP Q=50 A=COINM
SELL XRP/USDT Q=100 A=SPOT
BALANCE B=FREE A=USDM
BALANCE USDT A=SPOT
  • Take Profit and Stop Loss are placed as limit/stop orders and work in one-way mode only.

4. Command reference

4.1 Open an order

Use Buy, Long or 1 to buy, and Sell, Short or -1 to sell.

Parameter Description
Q (Quantity) Order size. On Spot and USDM, it is the number of coins or tokens, and on COINM it is the number of contracts. It can also be a percentage of your balance, and a percentage above 100% multiplies your balance (see the note below the balance options). Can also be sent as OQ (Opening Quantity). Examples: Q=0.01, Q=100 (100 contracts on COINM), Q=50%, Q=150%, Q=300%. Default: Q=100%
A (Account) SPOT, COINM or USDM. Default: A=SPOT
L (Leverage) Sets the leverage. L=5 means 5x
T (Type) Order type for stop orders: STOP, STOP_MARKET, TAKE_PROFIT, TAKE_PROFIT_MARKET. Example: T=STOP
P (Price) Entry price, as an absolute price (P=16572.35) or a percentage from the market price (P=2%)
D (Delay) Delays the command by a number of seconds. Maximum 5 seconds
B (Balance) Balance used to size the position: FREE, MARGIN or TOTAL. Default: B=TOTAL
H (Hedge) H=true if the account is in hedge mode. You can also just add the word hedge
R (Reduce) R=true makes the order only close existing positions. Default: R=false
TP (Take Profit) Creates a take_profit_market order in the opposite direction. Price or percentage from entry. Example: TP=22500.85, TP=5%
SL (Stop Loss) Creates a stop_market order in the opposite direction. Price or percentage from entry. Example: SL=22500.85, SL=5%

Balance options for B

  • FREE: the part of your funds that isn’t committed to any active obligation.
  • MARGIN: the total value of your futures wallet, including unrealized profit and loss from open positions.
  • TOTAL: the total balance in your account (default).

Using a percentage above 100% (futures)

If you don’t set L, TTA uses the leverage already preset on your Binance futures account. A Q above 100% lets you size the trade as a multiple of your balance:

  • Q=100% uses 1x your balance.
  • Q=150% uses 1.5x your balance.
  • Q=300% uses 3x your balance.

Your account leverage must be at least as high as the multiple, or Binance will reject the order.

Examples

Long BTCUSDT Q=0.01 L=10 A=USDM

Opens a long position worth 0.01 BTC with 10x leverage.

{{strategy.order.action}} ETHUSDT q=0.01 A=USDM L=5

Opens a 0.01 ETH trade in the strategy’s direction with 5x leverage.

Buy BTC/USDT Q=0.005 P=98000 A=SPOT

Places a buy limit order if the market price is higher than 98000. If the market price is lower, it opens a market order immediately.

Sell ETH/USDT Q=1 A=SPOT

Sells 1 ETH in your Spot account.

BUY XRP/USDT Q=10 A=SPOT

Buys 10 XRP coins in your Spot account.

BUY BTCUSD_PERP Q=100 A=COINM

Opens a COINM position of 100 contracts.

{{strategy.market_position}} BTCUSD_PERP Q=100 CQ=100% A=COINM

Opens a trade of 100 contracts and, when the strategy generates a flat command, closes 100% of it. CQ is the closing quantity and works the same way as Q, so it can be any amount or percentage.

4.2 Close an open trade

Use Close, Flat, or 0.

Parameter Description
A (Account) USDM or COINM only
Q (Quantity) Amount to close, in coins or contracts, or as a percentage. Can also be sent as CQ (Closing Quantity), which works exactly like Q and can be any amount. Default: Q=100%
T (Type) Which side to close: BUY or SELL. Example: T=BUY
D (Delay) Delays the command by up to 5 seconds. Example: D=3
H (Hedge) H=true, or just add the word hedge

Examples

Close BTCUSDT A=USDM

Closes all BTCUSDT trades in your USDM account.

Flat BTCUSDT Q=0.05 A=USDM

Closes 0.05 of your BTCUSDT trades.

Close BTCUSD_PERP Q=50% A=COINM

Closes 50% of your BTCUSD_PERP positions in the COINM account.

Close BTCUSDT A=USDM T=BUY

Closes only your BUY positions on the symbol.

4.3 Cancel a pending order

Use Cancel or Exit to cancel pending limit or stop orders. Set A= to SPOT, COINM, or USDM (default SPOT).

Cancel BTCUSDT A=USDM

Cancels all pending BTC/USDT orders in your USDM account.

Exit ETH/USDT A=SPOT

Cancels all pending ETH/USDT spot orders.

4.4 Check your balance

Use Balance, Bal, or Funds. Options are B=FREE, B=MARGIN, B=TOTAL (default), and A=SPOT, A=USDM, A=COINM.

Balance B=TOTAL A=USDM
Balance b=Free A=COINM
Balance A=SPOT
Balance B=margin

5. Automate a strategy

For strategy alerts, use one of TradingView’s placeholders in place of BUY/SELL:

  • {{strategy.order.action}} returns “buy” or “sell” for the executed order. Use it for strategies with only long and short orders.
  • {{strategy.market_position}} returns the current position: “long”, “flat” or “short”. Use it for strategies that also generate exit (close) orders.

For more on placeholders, see TradingView’s alert placeholder reference.

Long and short orders only (USDM)

Put a close command first so any open position is closed before the new one opens:

Close BTCUSDT A=USDM
{{strategy.order.action}} BTCUSDT Q=0.02 L=20 A=USDM

or using a percentage of your balance:

Close BTCUSDT A=USDM
{{strategy.order.action}} BTCUSDT Q=50% A=USDM

Long, short and exit orders (USDM)

No close command is needed, because the strategy sends its own exit order:

{{strategy.market_position}} BTCUSDT Q=0.02 L=10 A=USDM

COINM

Close BTCUSD_PERP A=COINM
{{strategy.order.action}} BTCUSD_PERP Q=100 L=5 A=COINM
{{strategy.market_position}} BTCUSD_PERP Q=100 CQ=100% A=COINM

Spot

{{strategy.order.action}} BTC/USDT Q=50% A=SPOT

Tip: If your strategy alert only buys and never sells, you are most likely missing the close command. Use the two-line format above.


6. Automate an indicator

Indicators do not use placeholders for buy, sell, or close commands. Type the command directly.

  1. Create an alert and select your indicator as the condition.
  2. Choose the long or short condition.
  3. Set the frequency to Once Per Bar Close to avoid duplicate alerts.
  4. Paste your webhook URL.
  5. Enter the command in the message field.

Long condition (USDM)

Close BTCUSDT A=USDM
BUY BTCUSDT Q=0.03 L=5 A=USDM

Short condition (USDM)

Close BTCUSDT A=USDM
SELL BTCUSDT Q=0.03 L=5 A=USDM

Long condition (COINM)

Close BTCUSD_PERP A=COINM
BUY BTCUSD_PERP Q=100 A=COINM

Short condition (COINM)

Close BTCUSD_PERP A=COINM
SELL BTCUSD_PERP Q=100 A=COINM

The close command comes first so any previous position is closed before the new one opens.

Using multiple indicators

Create a separate alert for each indicator, all using the same webhook URL. Set up the first indicator, click OK, then add the second indicator and repeat. When any indicator fires, the command is sent to your Binance account.


7. Take profit and stop loss

Add TP= and SL= to your open command. Both accept a price or a percentage from the entry price. They work in one-way mode only.

BUY BTCUSDT Q=0.01 TP=125000 SL=100000 A=USDM

This executes a market BUY, creates a take_profit_market order at 125000, and creates a stop_market order at 100000.

It is the same as sending these three commands:

BUY BTCUSDT Q=0.01 A=USDM
SELL BTCUSDT Q=0.01 P=125000 R=TRUE A=USDM T=TAKE_PROFIT_MARKET
SELL BTCUSDT Q=0.01 P=100000 R=TRUE A=USDM T=STOP_MARKET

Percentages work too:

Close ETHUSDT A=USDM
SELL ETHUSDT Q=0.1 L=50 SL=0.2% A=USDM

Updating take profit and stop loss

To change your stops, cancel the existing orders and send new ones:

  1. Cancel the existing stop and take-profit orders:
    Cancel BTCUSDT A=USDM
    
  2. Send the new orders with P= (price), T= (order type) and R=TRUE (so they only close the position). Use the same quantity as the original order:
    SELL BTCUSDT Q=0.01 P=122000 R=TRUE A=USDM T=TAKE_PROFIT_MARKET
    SELL BTCUSDT Q=0.01 P=101000 R=TRUE A=USDM T=STOP_MARKET
    

This moves your take profit to 122000 and your stop loss to 101000.


8. Hedge mode

If your Binance account uses Hedge Mode, your orders can fail with this error:

ExchangeError -4061: Order's position side does not match user's setting.

You have two ways to fix it.

Option 1: Switch to One-Way Mode

  1. Open Binance Futures and go to the asset you trade.
  2. In the trading panel, click the settings icon at the top-right.
  3. Select Position Mode.
  4. Choose One-Way Mode and save.

Option 2: Keep Hedge Mode and add hedge (or H=true) to your commands

{{strategy.order.action}} BTCUSDT Q=0.02 A=USDM hedge
{{strategy.order.action}} BTCUSD_PERP Q=100 A=COINM hedge
Close BTCUSDT A=USDM hedge

For indicators:

BUY BTCUSDT Q=0.03 A=USDM hedge
SELL BTCUSDT Q=0.03 A=USDM hedge

Remember that TP and SL will not work in hedge mode, because they are placed as limit and stop orders.


9. Multi-Assets Mode (B=MARGIN)

If you switch your Binance Futures account from Single-Asset Mode to Multi-Assets Mode, your wallet may hold no USDT at all. A percentage quantity such as Q=50% would then calculate to zero, and the order fails.

Use B=MARGIN to size the position from your margin balance instead. Margin balance is your wallet balance plus the unrealized PNL of open positions. Under Multi-Assets Mode, your eligible assets act as shared collateral across futures positions.

BUY BTCUSDT Q=50% A=USDM B=MARGIN

This buys BTCUSDT using 50% of your current margin balance, even if you don’t hold any USDT in your wallet.

How to enable it

  1. In Binance Futures, switch your account from Single-Asset Mode to Multi-Assets Mode.
  2. Add B=MARGIN to your alert message.
  3. Trigger your alert and confirm the position opens.

Good to know

  • Margin balance moves with the profit and loss of your open trades, so position sizes can vary between alerts while positions are open.
  • Binance may restrict switching asset mode while you have open positions or orders. Make the switch when your account is flat.
  • Test with a small size first.
  • You can check your margin balance at any time with Balance B=margin.

See the full release note: Binance Margin with Multi-Assets Mode.


10. Troubleshooting

Error or problem Cause Fix
BadSymbol binancecoinm does not have market symbol COINM symbol typed in the wrong format, such as BTCUSD or BTC/USD Use the exact COINM contract name, for example BTCUSD_PERP
Symbol not found or wrong market Symbols are case-sensitive, and the format depends on the account Copy the symbol name from the Binance web URL. Spot uses a slash (XRP/USDT), USDM has no slash (BTCUSDT), and COINM uses _PERP (BTCUSD_PERP)
Command rejected A space around = Remove the spaces: Q=0.1, not Q = 0.1
ExchangeError -4061: Order’s position side does not match user’s settings. Your account is in Hedge Mode Switch to One-Way Mode, or add hedge to your commands (section 8)
InvalidOrder … amount must be greater than minimum amount precision with a percentage Q The calculated quantity is below Binance’s minimum trade size. This also happens when your wallet holds no USDT because you use Multi-Assets Mode, so the quantity is always zero Increase the percentage, or add B=MARGIN if you use Multi-Assets Mode (section 9)
TP/SL not placed TP and SL only work in one-way mode Switch to One-Way Mode (section 8)
The strategy buys but never sells Missing close command Send the two-line format: Close BTCUSDT A=USDM then {{strategy.order.action}} BTCUSDT Q=50% A=USDM
Only some commands run More than 5 commands in one alert Keep alerts to 5 commands or fewer
Alerts stop arriving during the day You have reached your plan’s daily alert limit Open your webhook and click Extend Expiry to move to a higher plan. If you can’t see it, click Manage Payment and choose Cancel Payment (this does not affect your current subscription period). Extend Expiry will then appear

11. Test before going live

  1. Start with a small quantity.
  2. Trigger a test alert and confirm the trade opens on Binance with the right size, stop loss, and take profit.
  3. Use Balance commands to confirm which balance your percentages are using.
  4. Use Once Per Bar Close on indicator alerts so they don’t fire repeatedly.
  5. Keep your webhook URL private. Anyone with the URL can send commands to your connected account.

Have a question? Reply below, and the team will help.


Visit TradingView To Anywhere to start automating.