Trading View
Turn TradingView alerts into real orders across one or many accounts using webhooks.
You can send orders from TradingView alerts to many Indian stock brokers through AutoTrader Web. Point a TradingView webhook at the AutoTrader Web alert URL, put your order in a small JSON message, and AutoTrader Web places it. With Group Accounts you can fire the same alert into many trading accounts using a single TradingView subscription.
This page shows how to place automated orders from TradingView to leading Indian stock brokers.
Contents
- Demos
- Setup
- Multi-Account Trading
- Place Order
- Square-off Position
- Instruments
- Strategies
- Dynamic Alerts
- API Library
- Errors
- Additional Information
Demos
- Indicator or price based alerts
- Moving Average Strategy
- Supertrend Strategy
- Long Straddle Options Strategy
Setup
- Create an account on TradingView.
- You can compare the different plans offered.
- Note: Automation is offered via the webhook feature, which is available in the pro plan at the time of writing. Please check the TradingView website for latest updates.
- Register on AutoTrader Web (if not already done).
- Add Trading Accounts.
- Create Group Accounts if you need to trade in groups.
- Get your API Key.
- This API key is the Stocks Developer authentication API key. (This is NOT your broker’s API key.)
- You can find your API Key under the AutoTrader Web menu (Settings -> Security).
- Create an alert.
- You can learn more about alerts on the TradingView alerts help.
- Open a chart and add your indicators.
- Create an Alert (Press Alt + a).
- Scroll down to Alert Actions.
- Add a webhook for the alert. Please see the next section, Webhook URL, for URL information. More details about webhooks are on the TradingView webhooks guide.
- Make sure your alert has a valid format as per the explanation given below.
- Optional: Use the “Send Email” option so that a copy of the alert is also sent to your email. This helps during investigation.
Webhook URL
There are two types of users on TradingView.
1. Users building strategies for their personal use. These users can use the basic URL:
https://tvx.stocksdeveloper.in/
2. Users building strategies for their clients or customers. Instead of hardcoding the apiKey and account in the JSON message, you can also pass them in the URL. Here is a sample:
https://tvx.stocksdeveloper.in/?apiKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&account=ACC-NAME&group=false
Rules when you pass values in the URL:
- If you put
apiKeyin the URL, you can skip theapiKeyproperty in the JSON message. WhenapiKeyis present in the URL, that one is used. Just remove this row from the JSON message:"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", - If you put
accountin the URL, you MUST remove theaccountproperty from the JSON message. If the system finds anaccountproperty in the JSON message, that one is used. - You can also pass
group=truein the URL if you are passing a group account name.

Trading View Alert
Multi-Account Trading
- To trade in multiple trading accounts, use a Group Account (details below).
- To trade in multiple accounts with different quantity, create multiple group accounts and pass multiple orders in a single alert with different quantity.
- Note: You only need one TradingView subscription to trade in multiple accounts.
Place Order
To place an order, your alert content must be in the JSON format shown below. Plenty of examples follow, so please go through them.
Syntax
Here is a full example. Each section is explained after it.
{
"command": "PLACE_ORDERS",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"orders": [
{
"account": "ACC_NUM",
"group": false,
"variety": "REGULAR",
"validity": "DAY",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_FUT",
"tradeType": "BUY",
"orderType": "MARKET",
"productType": "INTRADAY",
"quantity": 75,
"disclosedQuantity": 0,
"price": 0,
"triggerPrice": 0,
"target": 0,
"stoploss": 0,
"trailingStoploss": 0,
"amo": false
},
{
"account": "ACC_NUM",
"group": false,
"variety": "REGULAR",
"validity": "DAY",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_CE_14000",
"tradeType": "SELL",
"orderType": "LIMIT",
"productType": "INTRADAY",
"quantity": 75,
"disclosedQuantity": 0,
"price": 120.5,
"triggerPrice": 0,
"target": 25,
"stoploss": 25,
"trailingStoploss": 2,
"amo": false
}
]
}
Syntax Explanation
- All valid values for parameters can be seen on API Parameters.
- The alert message must be in a valid JSON format.
- You can learn more about JSON syntax.
- These tools can validate your JSON syntax:
The basic structure of the message is shown below.
{
// This line is fixed and
// indicates a place order command
"command": "PLACE_ORDERS",
// This is your secret api key
// (found in AT Web menu (Settings -> Security)
// It is optional, if you have provided it in the webhook URL
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// Next section is a collection of orders,
// you can have anywhere between
// 1 to 10 orders from a single alert
"orders": [
{
// Order 1
},
{
// Order 2
}
],
// You can also add any custom properties.
// This helps to add details of the analysis done in trading view.
// These can be useful for investigation purpose
// and can be viewed from AT Web menu (Tools -> Activity)
// NOTE: Addition of following properties is OPTIONAL,
// you can also skip it.
// You can use ANY built-in variables provided by Trading View.
// More details on following link
// https://in.tradingview.com/chart/?solution=43000531021
// Some example of built-in variables given below
"exchange": "{{exchange}}",
"ticker": "{{ticker}}",
"price": {{close}},
"volume": "{{volume}}",
"timenow": "{{timenow}}"
}
Order syntax
orders is a JSON array. AutoTrader allows anywhere between 1 to 10 orders.
Why are multiple orders allowed on a single alert?
- A user might want to execute an option strategy involving multiple legs (which means placing multiple orders on a single alert).
- Users might want to place an order into multiple accounts with the same or different quantity.
- Users might want to place an order into multiple group accounts with the same or different quantity.
"orders": [
{
// Pseudo or Group account number
// It is optional, if you have provided it in the webhook URL
"account": "ACC_NUM",
// true (if you are passing a Group account)
// (Optional, default false)
"group": false,
// Variety: REGULAR, BO, CO
"variety": "REGULAR",
// Validity: DAY, IOC (Optional, default DAY)
"validity": "DAY",
// Exchange: NSE, BSE, MCX
"exchange": "NSE",
// Symbol: AutoTrader Web's symbol
// Search symbol: https://webx.stocksdeveloper.in/instrument
"symbol": "NIFTY_29-APR-2021_FUT",
// Trade type: BUY, SELL
// You can also use strategy placeholder {{strategy.order.action}}
"tradeType": "BUY",
// Order type: MARKET, LIMIT, STOP_LOSS, SL_MARKET
"orderType": "MARKET",
// Product type: INTRADAY, DELIVERY, NORMAL
"productType": "INTRADAY",
// Quantity
"quantity": 75,
// Disclosed quantity (Optional, default 0)
"disclosedQuantity": 0,
// Price (optional for MARKET order, default 0)
"price": 0,
// Trigger price (Required only SL, SL_M or Cover orders)
"triggerPrice": 0,
// Target (Only required for Bracket order)
"target": 0,
// Stoploss (Only required for Bracket order)
"stoploss": 0,
// Trailing stoploss
// (Only applicable for Bracket order but is optional)
"trailingStoploss": 0,
// AMO: true to indicate an After Market Order
// (Optional, default false)
"amo": false
},
{
// Another order...
}
]
Examples
Place a Regular Order
Example 1: Place a regular market order to buy Nifty April future.
{
"command": "PLACE_ORDERS",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"orders": [
{
"account": "ACC_NUM",
"variety": "REGULAR",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_FUT",
"tradeType": "BUY",
"orderType": "MARKET",
"productType": "INTRADAY",
"validity": "DAY",
"quantity": 75
}
]
}
Example 2: Place a regular market order to buy 2 quantity of SBIN.
{
"command": "PLACE_ORDERS",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"orders": [
{
"account": "ACC_NUM",
"variety": "REGULAR",
"exchange": "NSE",
"symbol": "SBIN",
"tradeType": "BUY",
"orderType": "MARKET",
"validity": "DAY",
"productType": "INTRADAY",
"quantity": 2
}
]
}
Example 3: Place an order by using a TradingView strategy.
Webhook URL:
https://tvx.stocksdeveloper.in/?apiKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&account=ACC-NAME&group=false
Replace the API key, account name and group parameters with your values.
Now let us look at the alert JSON contents. Here we are using placeholders given by TradingView alerts; these are available in strategies.
{
"command": "PLACE_ORDERS",
"orders": [
{
"variety": "REGULAR",
"exchange": "NSE",
"symbol": "SBIN",
"tradeType": "{{strategy.order.action}}",
"orderType": "MARKET",
"productType": "INTRADAY",
"quantity": {{strategy.order.contracts}}
}
]
}
Place a Cover Order
Example 1: Place a Cover order to sell 1 lot of BANKNIFTY future with a stoploss of 32,000.
{
"command": "PLACE_ORDERS",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"orders": [
{
"account": "ACC_NUM",
"variety": "CO",
"validity": "DAY",
"exchange": "NSE",
"symbol": "BANKNIFTY_29-APR-2021_FUT",
"tradeType": "SELL",
"orderType": "MARKET",
"productType": "INTRADAY",
"quantity": 25,
"triggerPrice": 32000
}
]
}
Place a Bracket Order
Example 1: Place a bracket order to buy 2 quantity of SBIN with a target of 3/-, stoploss of 4/- and trailing stoploss of 1/-.
{
"command": "PLACE_ORDERS",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"orders": [
{
"account": "ACC_NUM",
"variety": "BO",
"validity": "DAY",
"exchange": "NSE",
"symbol": "SBIN",
"tradeType": "BUY",
"orderType": "MARKET",
"productType": "INTRADAY",
"quantity": 2,
"price": 330,
"target": 3,
"stoploss": 4,
"trailingStoploss": 1
}
]
}
Place an order into a Group Account
Example 1: Place an order into a group account having the name HIGH_PROFILE.
Note: Group accounts can be created from the AutoTrader Web menu (Accounts -> Group Accounts). More details in Group Accounts.
{
"command": "PLACE_ORDERS",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"orders": [
{
"account": "HIGH_PROFILE",
"group": true,
"variety": "REGULAR",
"exchange": "NSE",
"symbol": "SBIN",
"tradeType": "BUY",
"orderType": "MARKET",
"validity": "DAY",
"productType": "INTRADAY",
"quantity": 2
}
]
}
Example 2: Place an order into two group accounts having names HIGH_PROFILE and LOW_PROFILE (with different quantity).
{
"command": "PLACE_ORDERS",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"orders": [
{
"account": "HIGH_PROFILE",
"group": true,
"variety": "REGULAR",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_FUT",
"tradeType": "BUY",
"orderType": "MARKET",
"productType": "INTRADAY",
"validity": "DAY",
"quantity": 150
},
{
"account": "LOW_PROFILE",
"group": true,
"variety": "REGULAR",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_FUT",
"tradeType": "BUY",
"orderType": "MARKET",
"productType": "INTRADAY",
"validity": "DAY",
"quantity": 75
}
]
}
Place multiple orders
Example 1: Put an order for an option straddle strategy. We buy Call and Put options with 2 different orders fired from a single alert.
{
"command": "PLACE_ORDERS",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"orders": [
{
"account": "ACC_NAME",
"variety": "REGULAR",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_CE_15000",
"tradeType": "BUY",
"orderType": "MARKET",
"productType": "INTRADAY",
"validity": "DAY",
"quantity": 75
},
{
"account": "ACC_NAME",
"variety": "REGULAR",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_PE_15000",
"tradeType": "BUY",
"orderType": "MARKET",
"productType": "INTRADAY",
"validity": "DAY",
"quantity": 75
}
]
}
Add analysis details
Example 1: You can add any analysis detail in the given format.
"field_name": "field_value"
You can add any custom properties to record the analysis done in TradingView. These are useful for investigation and can be viewed from the AT Web menu (Tools -> Activity). Note: Adding these properties is OPTIONAL; you can also skip it.
You can use ANY built-in variables provided by TradingView. More details here: https://in.tradingview.com/chart/?solution=43000531021
{
"command": "PLACE_ORDERS",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"orders": [
{
"account": "ACC_NUM",
"variety": "REGULAR",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_FUT",
"tradeType": "BUY",
"orderType": "MARKET",
"productType": "INTRADAY",
"validity": "DAY",
"quantity": 75
}
],
"exchange": "{{exchange}}",
"ticker": "{{ticker}}",
"price": "{{close}}",
"volume": "{{volume}}",
"short moving avg": "{{plot_0}}",
"long moving avg": "{{plot_1}}",
"timenow": "{{timenow}}"
}
Square-off Position
To square-off a position, your alert content must be in the JSON format shown below. Plenty of examples follow, so please go through them.
Syntax
Here is a full example. Each section is explained after it.
{
"command": "SQUARE_OFF_POSITION",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"positions": [
{
"account": "ACC_NUM",
"group": false,
"category": "NET",
"type": "MIS",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_FUT"
},
{
"account": "ACC_NUM",
"group": false,
"category": "NET",
"type": "MIS",
"exchange": "NSE",
"symbol": "SBIN"
}
]
}
Syntax Explanation
- All valid values for parameters can be seen on API Parameters.
- The alert message must be in a valid JSON format.
- You can learn more about JSON syntax.
- These tools can validate your JSON syntax:
The basic structure of the message is shown below.
{
// This line is fixed and
// indicates a square-off position command
"command": "SQUARE_OFF_POSITION",
// This is your secret api key
// (found in AT Web menu (Settings -> Security)
// It is optional, if you have provided it in the webhook URL
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// Next section is a collection of positions,
// you can have anywhere between
// 1 to 10 positions from a single alert
"positions": [
{
// Position 1
},
{
// Position 2
}
],
// You can also add any custom properties.
// This helps to add details of the analysis done in trading view.
// These can be useful for investigation purpose
// and can be viewed from AT Web menu (Tools -> Activity)
// NOTE: Addition of following properties is OPTIONAL,
// you can also skip it.
// You can use ANY built-in variables provided by Trading View.
// More details on following link
// https://in.tradingview.com/chart/?solution=43000531021
// Some example of built-in variables given below
"exchange": "{{exchange}}",
"ticker": "{{ticker}}",
"price": "{{close}}",
"volume": "{{volume}}",
"timenow": "{{timenow}}"
}
Position syntax
positions is a JSON array. AutoTrader allows anywhere between 1 to 10 positions.
Why are multiple positions allowed on a single alert?
- A user might want to execute an option strategy involving multiple legs (which means squaring off multiple positions on a single alert).
- Users might want to square-off a position from multiple accounts or groups.
"positions": [
{
// Pseudo or Group account number
// It is optional, if you have provided it in the webhook URL
"account": "ACC_NUM",
// true (if you are passing a Group account)
// (Optional, default false)
"group": false,
// Category: NET, DAY
"category": "NET",
// Type: MIS, CNC, NRML, BO, CO
"type": "MIS",
// Exchange: NSE, BSE, MCX
"exchange": "NSE",
// Symbol: AutoTrader Web's symbol
// Search symbol: https://webx.stocksdeveloper.in/instrument
"symbol": "NIFTY_29-APR-2021_FUT"
},
{
// Another position...
}
]
Examples
Square-off a single position
Webhook URL:
https://tvx.stocksdeveloper.in/
Example 1: Square-off a single position.
{
"command": "SQUARE_OFF_POSITION",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"positions": [
{
"account": "ACC_NUM",
"group": false,
"category": "NET",
"type": "MIS",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_FUT"
}
]
}
Example 2: Square-off a single position (API key, account number and group flag are provided in the URL).
Webhook URL:
https://tvx.stocksdeveloper.in/?apiKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&account=ACC-NAME&group=false
{
"command": "SQUARE_OFF_POSITION",
"positions": [
{
"category": "NET",
"type": "MIS",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_FUT"
}
]
}
Square-off a single position in a GROUP account
{
"command": "SQUARE_OFF_POSITION",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"positions": [
{
"account": "GROUP_ACC_NUM",
"group": true,
"category": "NET",
"type": "MIS",
"exchange": "NSE",
"symbol": "NIFTY_29-APR-2021_FUT"
}
]
}
Square-off multiple positions
{
"command": "SQUARE_OFF_POSITION",
"apiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"positions": [
{
"account": "ACC_NUM",
"group": false,
"category": "NET",
"type": "MIS",
"exchange": "NSE",
"symbol": "NIFTY_12-AUG-2021_CE_16000"
},
{
"account": "ACC_NUM",
"group": false,
"category": "NET",
"type": "MIS",
"exchange": "NSE",
"symbol": "NIFTY_12-AUG-2021_PE_16000"
}
]
}
Instruments
To find the correct exchange and symbol values, use our broker independent symbols. You can use this instrument search tool.
Always use AutoTrader Web’s broker independent symbols.
Note: Do NOT use broker specific symbols, or you will get an instrument not found error.
You can read more about AutoTrader Web’s broker independent instrument symbols.
Strategies
Strategies are very useful in TradingView. The main reasons to use strategies are:
- Backtesting.
- Easily add and configure parameters.
- Easily double the quantity when the signal changes.
- Use placeholders available from the strategy.
Examples
Dynamic Alerts
When you want to add dynamic content to your alert message, you can use the following placeholder.
{{strategy.order.alert_message}}
You can create the alert JSON in your strategy and pass it to the alert_message parameter. Your alert JSON content can then use any of the parameters based on what you have used.
See the example below:
strategy.entry(id = "Long", long = strategy.long, when = longCondition,
alert_message = "Your alert message content")
Strategies using Dynamic Alerts
API Library
We have built a public API library for our AutoTrader Web users. This library has many functions that make it easy for a Pine Script programmer to integrate with AutoTrader Web.
How to use?
To use this library, import it in your Pine Script by adding the import line at the top.
Step 1: Visit the library page and copy the import statement
- Visit the library page.
- Scroll down until you see the library code. There is a copy button just above the code (see screenshot below).

Library Import Copy
Step 2: Add the copied import statement to your Pine Script (just below the strategy() function)

AutoTrader Web Library Import
Functions
preparePlaceOrderAlertMessage
Prepares a complete place order alert message in AutoTrader Web’s JSON structure.
Signature
// @function Prepare a place order alert json message
// @param account Pseudo or Group account number
// @param symbol AutoTrader Web's stock/derivative symbol
// @param tradeType Trade type [BUY, SELL]
// @param group Set it to true if you are using a group account (Default: false)
// @param exchange Symbol's exchange [NSE, BSE, MCX] (Default: NSE)
// @param quantity Quantity (Default: 1)
// @param price Price (Default: 0)
// @param orderType Order type [MARKET, LIMIT, STOP_LOSS, SL_MARKET] (Default: MARKET)
// @param productType Product type [INTRADAY, DELIVERY, NORMAL] (Default: INTRADAY)
// @param triggerPrice Trigger price (Default: 0)
// @param variety Variety [REGULAR, BO, CO] (Default: REGULAR)
// @param validity Validity [DAY, IOC] (Default: DAY)
// @param disclosedQuantity Disclosed quantity (Default: 0)
// @param target Target (for Bracket order only) (Default: 0)
// @param stoploss Stoploss (for Bracket order only) (Default: 0)
// @param trailingStoploss (for Bracket order only) Trailing Stoploss (Default: 0)
// @param amo Set it to true for AMO (After Market Order) (Default: false)
// @param comments Comments (Default: blank)
// @returns A complete alert message to place orders
export preparePlaceOrderAlertMessage(string account, string symbol, string tradeType,
bool group = false, string exchange = "NSE", int quantity = 1,
float price = 0, string orderType = "MARKET",
string productType = "INTRADAY", float triggerPrice = 0,
string variety = "REGULAR", string validity = "DAY",
int disclosedQuantity = 0, float target = 0, float stoploss = 0,
float trailingStoploss = 0, bool amo = false, string comments = "")
Example
message = preparePlaceOrderAlertMessage(account = "ACC_NUM",
symbol = "BANKNIFTY_24-FEB-2022_CE_34000",
tradeType = "BUY", group = false, exchange = "NSE",
quantity 25, price = 0, orderType = "MARKET",
productType = "NORMAL")
strategy.entry(id = "Long", direction = strategy.long, when = longCondition,
alert_message = message)
preparePlaceOrderAlertMessageForTwoOrders
Prepares a complete place order alert message in AutoTrader Web’s JSON structure for two orders to be placed in a single alert. It is useful for trading option strategies. If you want to place more than two orders in a single alert, you can make a similar function.
Signature
// @function Prepare a place order alert json message for 2 orders
// @param account Pseudo or Group account number
// @param symbol AutoTrader Web's stock/derivative symbol
// @param tradeType Trade type [BUY, SELL]
// @param group Set it to true if you are using a group account (Default: false)
// @param exchange Symbol's exchange [NSE, BSE, MCX] (Default: NSE)
// @param quantity Quantity (Default: 1)
// @param price Price (Default: 0)
// @param orderType Order type [MARKET, LIMIT, STOP_LOSS, SL_MARKET] (Default: MARKET)
// @param productType Product type [INTRADAY, DELIVERY, NORMAL] (Default: INTRADAY)
// @param triggerPrice Trigger price (Default: 0)
// @param account2 Pseudo or Group account number [for order 2]
// @param symbol2 AutoTrader Web's stock/derivative symbol [for order 2]
// @param tradeType2 Trade type [BUY, SELL] [for order 2]
// @param group2 Set it to true if you are using a group account (Default: false) [for order 2]
// @param exchange2 Symbol's exchange [NSE, BSE, MCX] (Default: NSE) [for order 2]
// @param quantity2 Quantity (Default: 1) [for order 2]
// @param price2 Price (Default: 0) [for order 2]
// @param orderType2 Order type [MARKET, LIMIT, STOP_LOSS, SL_MARKET] (Default: MARKET) [for order 2]
// @param productType2 Product type [INTRADAY, DELIVERY, NORMAL] (Default: INTRADAY) [for order 2]
// @param triggerPrice2 Trigger price (Default: 0) [for order 2]
// @param comments Comments
// @returns A complete alert message to place 2 orders
export preparePlaceOrderAlertMessageForTwoOrders(string account, string symbol,
string tradeType, bool group = false, string exchange = "NSE",
int quantity = 1, float price = 0, string orderType = "MARKET",
string productType = "INTRADAY", float triggerPrice = 0,
string account2, string symbol2, string tradeType2,
bool group2 = false, string exchange2 = "NSE", int quantity2 = 1,
float price2 = 0, string orderType2 = "MARKET",
string productType2 = "INTRADAY", float triggerPrice2 = 0,
string comments = "")
Example
message = preparePlaceOrderAlertMessageForTwoOrders(account = "ACC_NUM",
symbol = "BANKNIFTY_24-FEB-2022_CE_34000",
tradeType = "BUY", group = false, exchange = "NSE",
quantity = 25, productType = "NORMAL", orderType = "MARKET", price = 0,
account2 = "ACC_NUM",
symbol2 = "BANKNIFTY_24-FEB-2022_PE_34000",
tradeType2 = "BUY", group2 = false, exchange2 = "NSE",
quantity2 = 25, productType2 = "NORMAL", orderType2 = "MARKET", price2 = 0,
comments = "Long Straddle")
strategy.entry(id = "Long", direction = strategy.long, when = longCondition,
alert_message = message)
prepareSqOffPositionAlertMessage
Prepares a complete square-off alert message in AutoTrader Web’s JSON structure.
Signature
// @function Prepare a square-off position alert json message
// @param account Pseudo or Group account number
// @param symbol AutoTrader Web's stock/derivative symbol
// @param group Set it to true if you are using a group account (Default: false)
// @param exchange Symbol's exchange [NSE, BSE, MCX] (Default: NSE)
// @param category Position category [NET, DAY]
// @param type Position type [MIS, CNC, NRML, BO, CO]
// @param comments Comments (Default: Blank)
// @returns A complete alert message to square-off position
export prepareSqOffPositionAlertMessage(string account, string symbol,
bool group = false, string exchange = "NSE", string category = "NET",
string type = "MIS", string comments = "")
Example
message = prepareSqOffPositionAlertMessage(account = "ACC_NUM",
symbol = "BANKNIFTY_24-FEB-2022_CE_34000",
group = false, exchange = "NSE",
type = "NRML", comments = "Square Off Request")
strategy.entry(id = "Long", direction = strategy.long, when = longCondition,
alert_message = message)
prepareSqOffPositionAlertMessageForTwoPositions
Prepares a complete square-off alert message in AutoTrader Web’s JSON structure for two orders to be placed in a single alert. It is useful for trading option strategies. If you want to place more than two orders in a single alert, you can make a similar function.
Signature
// @function Prepare a square-off position alert json message for two positions
// @param account Pseudo or Group account number
// @param symbol AutoTrader Web's stock/derivative symbol
// @param group Set it to true if you are using a group account (Default: false)
// @param exchange Symbol's exchange [NSE, BSE, MCX] (Default: NSE)
// @param category Position category [NET, DAY]
// @param type Position type [MIS, CNC, NRML, BO, CO]
// @param account2 Pseudo or Group account number [for order 2]
// @param symbol2 AutoTrader Web's stock/derivative symbol [for order 2]
// @param group2 Set it to true if you are using a group account (Default: false) [for order 2]
// @param exchange2 Symbol's exchange [NSE, BSE, MCX] (Default: NSE) [for order 2]
// @param category2 Position category [NET, DAY] [for order 2]
// @param type2 Position type [MIS, CNC, NRML, BO, CO] [for order 2]
// @param comments Comments
// @returns A complete alert message to square-off of two positions
export prepareSqOffPositionAlertMessageForTwoPositions(string account,
string symbol, bool group = false, string exchange = "NSE",
string category = "NET", string type = "MIS", string account2,
string symbol2, bool group2 = false, string exchange2 = "NSE",
string category2 = "NET", string type2 = "MIS",
string comments = "")
Example
message = prepareSqOffPositionAlertMessageForTwoPositions(
account = "ACC_NUM",
symbol = "BANKNIFTY_24-FEB-2022_CE_34000",
group = false, exchange = "NSE",
type = "NRML", account2 = "ACC_NUM",
symbol2 = "BANKNIFTY_24-FEB-2022_CE_34000",
tradeType2 = "BUY", group2 = false, exchange2 = "NSE",
type2 = "NRML", comments = "Square Off Request")
strategy.entry(id = "Long", direction = strategy.long, when = longCondition,
alert_message = message)
prepareFutureSymbol
Prepares a future symbol as per AutoTrader Web’s broker independent format defined in broker independent instrument symbols.
Signature
// @function Prepares future symbol for AutoTrader Web
// @param underlier Underlier symbol (Ex. BANKNIFTY, USDINR, CRUDEOIL)
// @param expiry Expiry date in (DD-MMM-YYYY) format
// @returns future symbol as per AutoTrader Web's format
export prepareFutureSymbol(string underlier, string expiry)
Example
futSymbol = prepareFutureSymbol(underlier = "BANKNIFTY",
expiry = "24-FEB-2022")
prepareOptionSymbol
Prepares an option symbol as per AutoTrader Web’s broker independent format defined in broker independent instrument symbols.
Signature
// @function Prepares option symbol for AutoTrader Web
// @param underlier Underlier symbol (Ex. BANKNIFTY, USDINR, CRUDEOIL)
// @param expiry Expiry date in (DD-MMM-YYYY) format
// @param optionType Option type [CE, PE]
// @param strike Strike price
// @returns option symbol as per AutoTrader Web's format
export prepareOptionSymbol(string underlier, string expiry, string optionType,
int strike)
Example
callSymbol = prepareOptionSymbol(underlier = "BANKNIFTY",
expiry = "24-FEB-2022", optionType = "CE", strike = 34000)
calcClosestStrike
Calculates the closest option strike price as per the given underlier price.
Signature
// @function Calculates the closest option strike price as per the given
// underlier price
// @param underlierPrice The underlier's price
// @param gap The gap between option strikes
// (Example. The gap is 100 for options of BANKNIFTY)
// @returns the closest option strike price
export calcClosestStrike(float underlierPrice, int gap)
Example
strike = calcClosestStrike(underlierPrice = close, gap = 100)
Other functions
The library has other functions that might be useful in certain scenarios. Please look at the library code at the bottom of the library page.
Errors
What to do when orders are not placed but you see the alert on Trading View?
- Use the “Send Email” option while configuring the alert, so that a copy of the alert is also sent to your email. This is very helpful during investigation.
- First, check that you have passed the correct api_key. It can be passed in the webhook URL or the JSON message.
- Check if your alert message content is valid JSON. See the JSON Errors section below.
- Check your activity logs (Menu: Tools -> Activity) to see if your order has failed validation or at the broker.
- If you do not see any activity logs and you have entered the correct API key, then do the following:
- Send us details of your investigation:
- Alert setting screenshot showing the API key used properly.
- Alert message time and content in text format (available in the TradingView “Alert Log” window).
- Activity logs screenshot.
- Note: The support team will only investigate once the above details are properly provided.
- Send us details of your investigation:
JSON Errors
If your JSON format is wrong or order details are not valid, then you will get errors. As long as you have entered the correct api_key, you can see all your errors on the AutoTrader Web menu (Tools -> Activity).
JSON parsing errors can occur if your alert content is not in a valid JSON format. In such cases, use this validation tool to find errors. Copy the content of the generated alerts into the validation tool (you can view generated alerts in the “Alert Log” section on TradingView). See the example below.
Here we missed a comma, so an error is shown.

JSON Validation
Additional Information
If you are testing, do not forget to stop all alerts before closing the TradingView website. TradingView alerts and strategies keep running on their server unless you stop them. If a user forgets to stop them, orders might keep executing in their accounts.
Automation has its own risks. Users must understand how TradingView alerts and strategies work before using automation. We strongly recommend thorough testing with the minimum possible capital before increasing your capital and risk.
Please be careful and avoid changing the alerts or strategy settings during live market. TradingView can repaint a signal when you change the settings, which leads to unexpected results. If you are testing, then it is okay to change settings during live market. Here are some references on repainting:
Support for TradingView will keep improving as we understand our clients’ needs. Feel free to share your feedback through our contact page.
Frequently asked questions
The TradingView alert time and the AutoTrader Web time look different. Why?▾
This is a clock difference, not a delay. TradingView's alert clock can be out of sync with standard internet time by a few seconds, so its timestamp may not match ours. AutoTrader Web keeps its own clock in sync with standard internet time, so the time shown in your activity logs is accurate. Your order is placed as soon as the alert reaches AutoTrader Web — you can confirm the exact time in the activity logs (Tools -> Activity).
Next steps
Thanks for the feedback. Still stuck? Contact support.
Last updated 22 June 2026