Core Trading Parameters
Core trading parameters define the fundamental aspects of your trade: which exchange, which symbol, what action, and what type of position.
exchange
- Type:
string - Required: No
- Description: Name of the exchange where the trade should be executed
Supported Exchanges
Use the exchange your bot is connected to, for example BINANCE, BYBIT, OKX or ALPACA. Only exchanges you can connect in the OptAlgo app are supported.
Details
The exchange name must match your bot's exchange (case does not matter). If the bot is an auto or multi-symbol bot that has not received a signal yet, the first entry sets the exchange.
Validation
- Exchange name is case-insensitive
- Must match an exchange supported by OptAlgo
- Must match your bot's exchange, for every signal including exits
- Live bots need an active exchange connection in the app (paper bots do not)
Example
{
"strategy_key": "your_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"position_side": "LONG",
"action": "BUY"
}
Common Errors
| Error | Cause | Solution |
|---|---|---|
| "Exchange is not supported or not found for name: ..." | Unknown exchange name on an auto bot's first signal | Check spelling |
| "Exchange not found or does not match with strategy" | Different from the bot's exchange, or missing | Send the bot's exchange in every signal |
| "Connection not found" | Live bot without an exchange connection | Add the exchange connection in the app |
ticker
- Type:
string - Required: No
- Description: Trading pair symbol
Symbol Format
Spot Trading:
- Use symbol as-is:
"BTCUSDT","ETHUSDT","SOLUSDT"
Futures Trading:
- Append
.Pto symbol:"BTCUSDT.P","ETHUSDT.P","SOLUSDT.P"
Auto-Configuration
If your strategy is not yet configured (is_set = False), the first signal automatically sets:
- Symbol from
tickerparameter - Account type (Spot or Futures) based on
.Psuffix - Strategy name as
{exchange}-{ticker} AUTO CREATED
Validation
- For a single-symbol bot, every signal, exits included, must carry the bot's symbol
- A multi-symbol bot accepts any ticker on its exchange, market type and quote currency (see Multi-symbol bots)
- The symbol must exist on the exchange in the bot's market type
Examples
// Spot trading
{
"strategy_key": "your_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT",
"position_side": "LONG",
"action": "BUY"
}
// Futures trading
{
"strategy_key": "your_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"position_side": "LONG",
"action": "BUY"
}
Common Errors
| Error | Cause | Solution |
|---|---|---|
| "Signal symbol does not match strategy symbol" | Different from the bot's symbol, or missing | Use the bot's symbol, use one bot per symbol, or use a multi-symbol bot |
| "Ticker not supported or not found" | Symbol doesn't exist on the exchange | Check exchange listings |
| "Your signal symbol is belong to ... account type" | Wrong .P suffix for the bot's market type | Add .P for futures, remove it for spot |
action
- Type:
string - Required: No (required for opening positions)
- Description: Direction of the trade action
Allowed Values
BUY- Long directionSELL- Short direction
Values are case-sensitive: buy is rejected (invalid_action). TradingView's {{strategy.order.action}} placeholder produces lower case, so do not use it for this field.
When Required
The action parameter is required for:
- Opening positions (
LONG,SHORTposition_side) - Replacing positions (
UPDATE_ORDER,CHANGE_DIRECTION): it gives the new direction
Not required for:
- Closing positions (
CLOSE,CLOSE_ALL) - Moving stop loss (
MOVE_STOP_LOSS) - Validation (
VALIDATE_ALERT)
Validation Rules
For opening positions:
LONG+BUY= Open long positionSHORT+SELL= Open short positionLONGandSHORTare rejected unlessactionisBUYorSELL. Always pairLONGwithBUYandSHORTwithSELL.
Examples
// Open long position
{
"strategy_key": "your_key",
"position_side": "LONG",
"action": "BUY",
"entry_price": 50000
}
// Open short position
{
"strategy_key": "your_key",
"position_side": "SHORT",
"action": "SELL",
"entry_price": 50000
}
// Close position (no action needed)
{
"strategy_key": "your_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"position_side": "CLOSE"
}
position_side
- Type:
string - Required: Yes
- Description: Type of position action to take
Overview
The position_side parameter determines what operation to perform. It is case-sensitive: use upper case.
Main Categories
Opening Positions:
LONG- Open a long positionSHORT- Open a short position
Closing Positions:
CLOSE- Close a specific positionCLOSE_PARTIAL- Close part of a positionCLOSE_ALL- Close all positions for the strategy
Managing Positions:
MOVE_STOP_LOSS- Replace the stop-loss and take-profit ordersSET_ORDERS-MOVE_STOP_LOSSafter a delayCANCEL_ORDERS- Cancel the stop-loss and/or take-profitUPDATE_ORDER- Replace the position (close, then open again)
Advanced:
CHASE_LIMIT- Chase limit ordersCHANGE_DIRECTION- Close opposite and open newVALIDATE_ALERT- Verify position consistency- And more...
See Also
For complete documentation on all position types, see:
Example
{
"strategy_key": "your_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"position_side": "LONG",
"action": "BUY",
"entry_price": 50000
}
trade_id
- Type:
string - Required: No
- Max length: 36 characters
- Description: Identifier of one trade within a bot
Purpose
When a signal carries a trade_id, it acts on the open trade with that id. Without one, it acts on the bot's open trade.
When to Use
Most TradingView bots hold one position at a time and do not need a trade_id. Leave it out unless you deliberately manage several trades on one bot.
If you use one:
- send the same value on the entry and on all of its exits and stop moves;
- never build it from a value that changes between alerts, such as
{{timenow}}. Otherwise the exit cannot find the trade (CLOSE failed, there is no open trade); - keep it at 36 characters or fewer.
An entry is refused while the bot has an open trade with the same trade_id, or any open trade when no trade_id is used (There is an already open trade).
Examples
// Open position with a trade_id
{
"strategy_key": "your_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"trade_id": "BTC_LONG_001",
"position_side": "LONG",
"action": "BUY",
"leverage": 5
}
// Later, close that trade
{
"strategy_key": "your_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"trade_id": "BTC_LONG_001",
"position_side": "CLOSE"
}
Complete Example
{
"strategy_key": "your_encrypted_strategy_key",
"exchange": "BINANCE",
"ticker": "BTCUSDT.P",
"action": "BUY",
"position_side": "LONG",
"leverage": 5,
"entry_price": 50000,
"stop_loss_price": 48000,
"take_profit_price": 55000
}
Next Steps
- Pricing Parameters - Entry price, stop loss, take profit
- Position Types - All position_side values
- Examples - Complete working examples