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

  1. Go to tradingview.com
  2. Open a chart for your trading pair
  3. Apply your strategy or indicator

Step 2: Create an Alert

  1. Click the Alert button (clock icon) or press Alt + A
  2. 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

  1. In the Notifications section, check Webhook URL
  2. 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

  1. Give your alert a name
  2. Set expiration (or "Open-ended")
  3. 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

PlaceholderDescriptionExample Output
{{ticker}}Symbol nameBTCUSDT
{{exchange}}Exchange nameBINANCE
{{close}}Current close price97500
{{open}}Current open price97200
{{high}}Current high price97800
{{low}}Current low price97000
{{volume}}Current volume1234567
{{time}}Alert trigger time2024-01-15T10:30:00Z
{{interval}}Chart timeframe60

Strategy-Specific Placeholders

PlaceholderDescriptionExample Output
{{strategy.market_position}}Current position statelong, short, flat
{{strategy.order.action}}Order actionbuy, sell
{{strategy.order.contracts}}Order size0.1
{{strategy.order.price}}Order price97500
{{strategy.order.id}}Order IDLong Entry
{{strategy.order.comment}}Order commentRSI oversold
{{strategy.position_size}}Current position size0.1

Field Mapping Reference

TradeStaq FieldTradingView PlaceholderPurpose
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 position or action - both work. position with {{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:

ValueMeaningTradeStaq Action
longStrategy is in a long positionOpens long (or flips from short)
shortStrategy is in a short positionOpens short (or flips from long)
flatStrategy has no positionCloses 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

  1. Verify alert is active (not expired)
  2. Check alert conditions are correct
  3. Ensure market is open (crypto markets are 24/7)
  4. Review TradingView alert logs

Webhook Not Received

  1. Verify webhook URL is correct (no typos)
  2. Check that webhook URL checkbox is enabled
  3. Test webhook with the built-in test tool
  4. Review bot activity logs in TradeStaq

Invalid JSON Error

  1. Validate JSON syntax at jsonlint.com
  2. Ensure all quotes are straight quotes (") not curly quotes
  3. Check for special characters that need escaping
  4. 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