TradingView Integration
TradingView is the most popular source for Signal Bot alerts. This guide shows you how to connect your TradingView strategies and indicators to TradeStaq for automated trade execution.
Overview
TradingView alerts can trigger webhooks when certain conditions are met. By pointing these alerts to your TradeStaq webhook URL, trades execute automatically.
TradingView Alert → Webhook → TradeStaq → Exchange → Trade
Prerequisites
- TradingView account (Pro, Pro+, or Premium for webhooks)
- TradeStaq Signal Bot created
- Your webhook URL ready
Note: TradingView's free plan does not support webhooks. You need at least a Pro subscription.
Setting Up Alerts
Step 1: Open Your Chart
- Go to tradingview.com
- Open a chart for your trading pair
- Apply your strategy or indicator
Step 2: Create an Alert
- Click the Alert button (clock icon) or press
Alt + A - The "Create Alert" dialog opens
Step 3: Configure Alert Condition
For Strategies:
- Condition: Select your strategy
- Choose: "Order fills only" or specific conditions
For Indicators:
- Condition: Select your indicator
- Choose: Crossing, greater than, less than, etc.
- Set the threshold value
Step 4: Configure Webhook
- In the Notifications section, check Webhook URL
- Paste your TradeStaq webhook URL:
https://www.tradestaq.com/api/webhooks/trade/YOUR_WEBHOOK_ID
Step 5: Set Alert Message
In the Message field, paste your JSON template (see templates below).
Step 6: Create the Alert
- Give your alert a name
- Set expiration (or "Open-ended")
- Click Create
Alert Message Templates
Minimum Required
The simplest template that works. Uses bot settings for position sizing.
{
"ticker": "{{ticker}}",
"position": "{{strategy.market_position}}"
}
Recommended
Includes price for faster sizing calculations and a comment for notifications.
{
"ticker": "{{ticker}}",
"position": "{{strategy.market_position}}",
"marketPrice": "{{close}}",
"comment": "{{strategy.order.comment}}"
}
Full Control
Override all settings per signal.
{
"ticker": "{{ticker}}",
"position": "{{strategy.market_position}}",
"size": "{{strategy.order.contracts}}",
"marketPrice": "{{close}}",
"tp": "",
"sl": "",
"leverage": "",
"comment": "{{strategy.order.comment}}",
"exchange": "{{exchange}}"
}
Manual Buy/Sell Alerts
For indicator-based alerts (not strategies), use fixed position values:
Buy Alert:
{
"ticker": "{{ticker}}",
"position": "long",
"marketPrice": "{{close}}"
}
Sell Alert:
{
"ticker": "{{ticker}}",
"position": "short",
"marketPrice": "{{close}}"
}
Close Alert:
{
"ticker": "{{ticker}}",
"position": "flat"
}
TradingView Placeholders
Use these placeholders in your alert messages. TradingView replaces them with actual values when the alert triggers.
General Placeholders
| Placeholder | Description | Example Output |
|---|---|---|
{{ticker}} | Symbol name | BTCUSDT |
{{exchange}} | Exchange name | BINANCE |
{{close}} | Current close price | 97500 |
{{open}} | Current open price | 97200 |
{{high}} | Current high price | 97800 |
{{low}} | Current low price | 97000 |
{{volume}} | Current volume | 1234567 |
{{time}} | Alert trigger time | 2024-01-15T10:30:00Z |
{{interval}} | Chart timeframe | 60 |
Strategy-Specific Placeholders
| Placeholder | Description | Example Output |
|---|---|---|
{{strategy.market_position}} | Current position state | long, short, flat |
{{strategy.order.action}} | Order action | buy, sell |
{{strategy.order.contracts}} | Order size | 0.1 |
{{strategy.order.price}} | Order price | 97500 |
{{strategy.order.id}} | Order ID | Long Entry |
{{strategy.order.comment}} | Order comment | RSI oversold |
{{strategy.position_size}} | Current position size | 0.1 |
Field Mapping Reference
| TradeStaq Field | TradingView Placeholder | Purpose |
|---|---|---|
ticker | {{ticker}} | Required. Trading symbol |
position | {{strategy.market_position}} | Required. Trade direction (long/short/flat) |
action | {{strategy.order.action}} | Alternative to position. Trade action (buy/sell) |
size | {{strategy.order.contracts}} | Override position size |
price | {{strategy.order.price}} | Limit order price (omit for market order) |
marketPrice | {{close}} | Price for sizing calculations |
comment | {{strategy.order.comment}} | Note in notifications |
exchange | {{exchange}} | Target specific exchange |
timeframe | {{interval}} | Chart timeframe |
strategy | (custom text) | Strategy name for notification subject |
Note: You can use either
positionoraction- both work.positionwith{{strategy.market_position}}is recommended because it handles position state (long/short/flat) rather than just order direction (buy/sell).
Example Pine Script Strategy
Here's a complete RSI strategy with proper TradeStaq alert messages:
//@version=5
strategy("RSI Strategy for TradeStaq", overlay=true)
// RSI Settings
rsiLength = input.int(14, "RSI Length")
rsiOverbought = input.int(70, "Overbought Level")
rsiOversold = input.int(30, "Oversold Level")
// Calculate RSI
rsiValue = ta.rsi(close, rsiLength)
// Entry Conditions
longCondition = ta.crossover(rsiValue, rsiOversold)
shortCondition = ta.crossunder(rsiValue, rsiOverbought)
// Strategy Entries with alert_message
if (longCondition)
strategy.entry("Long", strategy.long,
alert_message='{"ticker":"{{ticker}}","position":"long","marketPrice":"{{close}}","comment":"RSI oversold"}')
if (shortCondition)
strategy.entry("Short", strategy.short,
alert_message='{"ticker":"{{ticker}}","position":"short","marketPrice":"{{close}}","comment":"RSI overbought"}')
// Exit on opposite signal
if (shortCondition and strategy.position_size > 0)
strategy.close("Long",
alert_message='{"ticker":"{{ticker}}","position":"flat","comment":"Exit long"}')
if (longCondition and strategy.position_size < 0)
strategy.close("Short",
alert_message='{"ticker":"{{ticker}}","position":"flat","comment":"Exit short"}')
Using alert_message Parameter
The alert_message parameter in strategy.entry() and strategy.close() is the most reliable method. The message is sent exactly when the order would execute.
When using this approach, set your alert to trigger on "Order fills only" and leave the Message field empty (the alert_message from Pine Script is used).
Multiple Alerts Setup
For strategies with separate entry and exit logic, create multiple alerts:
Entry Alert (Long)
- Condition: When RSI crosses above 30
- Message:
{"ticker":"{{ticker}}","position":"long","marketPrice":"{{close}}"}
Entry Alert (Short)
- Condition: When RSI crosses below 70
- Message:
{"ticker":"{{ticker}}","position":"short","marketPrice":"{{close}}"}
Exit Alert (Close)
- Condition: When position should close
- Message:
{"ticker":"{{ticker}}","position":"flat"}
Understanding Position Values
TradingView's {{strategy.market_position}} outputs:
| Value | Meaning | TradeStaq Action |
|---|---|---|
long | Strategy is in a long position | Opens long (or flips from short) |
short | Strategy is in a short position | Opens short (or flips from long) |
flat | Strategy has no position | Closes any open position |
This makes {{strategy.market_position}} ideal for the position field because it automatically handles:
- Opening new positions
- Flipping positions (long → short or short → long)
- Closing positions
Troubleshooting
Alert Not Triggering
- Verify alert is active (not expired)
- Check alert conditions are correct
- Ensure market is open (crypto markets are 24/7)
- Review TradingView alert logs
Webhook Not Received
- Verify webhook URL is correct (no typos)
- Check that webhook URL checkbox is enabled
- Test webhook with the built-in test tool
- Review bot activity logs in TradeStaq
Invalid JSON Error
- Validate JSON syntax at jsonlint.com
- Ensure all quotes are straight quotes (
") not curly quotes - Check for special characters that need escaping
- Make sure placeholders are properly formatted
Wrong Symbol Format
Different exchanges use different formats:
- Binance Futures:
BTCUSDT - Bybit:
BTCUSDT - Most others:
BTC/USDT
Use {{ticker}} and let TradeStaq normalize the symbol automatically. If issues persist, set a fixed symbol in your bot settings instead of using dynamic pair.
Best Practices
1. Test with Paper Trading First
Always test your TradingView alerts with a paper trading exchange before using real funds.
2. Use strategy.market_position
The {{strategy.market_position}} placeholder is more reliable than {{strategy.order.action}} because it represents the actual position state, not just the order direction.
3. Include marketPrice
Adding "marketPrice": "{{close}}" speeds up position size calculations by reducing API calls to your exchange.
4. Set Alert Expiration Appropriately
- Use "Open-ended" for long-term strategies
- Set specific dates for short-term setups
- Review and refresh alerts periodically
5. Use alert_message in Pine Script
When writing your own strategies, use the alert_message parameter in strategy.entry() for the most reliable webhook delivery.
strategy.entry("Long", strategy.long,
alert_message='{"ticker":"{{ticker}}","position":"long"}')
6. Monitor Alert Frequency
TradingView has limits on alert frequency. Combine conditions where possible to reduce alert count.
See Also
- Webhook Setup - Complete webhook reference
- Pine Script Examples - More strategy examples
- Risk Management - Position sizing and risk settings