Automating your trading strategy can significantly enhance efficiency, reduce emotional decision-making, and allow for 24/7 market monitoring. One of the most powerful ways to achieve this is by integrating TradingView signals with the OKX signal trading bot. This guide walks you through the complete setup process—from creating a custom signal in TradingView to configuring and managing your automated trading bot on OKX.
Whether you're using Pine Script strategies, technical indicators, or third-party programs, this step-by-step tutorial ensures seamless integration while maximizing performance and control.
Step 1: Access the Signal Bot on OKX
Log in to your OKX account, navigate to Trade → Trading Bot → Marketplace, and select the Signal Bot tab. Click "Create" to begin setting up your automated trading system.
This action opens the foundation for connecting external trading signals—such as those from TradingView—to execute real trades automatically on OKX.
👉 Discover how easy it is to automate your crypto trades today.
Step 2: Create a Custom Trading Signal
Click "Add Custom Signal" to start building your signal.
You’ll be prompted to:
- Enter a signal name
- Add a brief description (up to 500 characters)
Once completed, click "Create Signal" to proceed.
The next screen displays an auto-generated webhook URL and AlertMsg specifications. These are critical components that enable communication between TradingView and OKX. You’ll use them shortly when setting up alerts in TradingView.
There are two primary methods for sending signals:
- TradingView: For users leveraging Pine Script strategies that use
strategy.*()functions. - Custom: Designed for broader use cases including indicators, chart-based alerts, or third-party tools.
Understanding Pine Script: Strategy vs Indicator
| Pine Script Type | Description |
|---|---|
| TradingView Strategy | Used for backtesting and forward-testing on live markets. Includes strategy.*() functions to simulate trade execution via a broker emulator. Results appear in the "Strategy Tester" tab below the chart. Ideal for automated trading setups. |
| TradingView Indicator (Study Script) | Focuses on calculations without order simulation. More resource-efficient and faster than strategies. Suitable for generating alerts based on technical conditions. |
✅ Use Step 3.1 if you're usingstrategy.*()functions in a Pine Script strategy.
✅ Use Steps 3.2–3.4 if you’re using indicators, chart analysis, or external programs.
Step 3: Configure TradingView Alerts
Before proceeding, review the full Alert Message Specifications to ensure compatibility.
Open TradingView, choose your desired trading pair (ensure it matches an OKX-supported perpetual swap), and follow the appropriate setup path below.
Step 3.1: Using a TradingView Strategy Script
- Open the Pine Editor, configure your strategy script, then click "Save" and "Add to Chart".
- Click the gear icon next to the strategy on the chart to adjust parameters like order size. Confirm changes with "OK".
Aligning Order Settings with OKX
TradingView allows three ways to define order size:
1. Order Size: USDT
Set a fixed USDT amount per trade. To sync with OKX:
- Set "Investment Type" to
base - Use
{{strategy.order.contracts}}in the "Amount" field
{
"id": "{{strategy.order.id}}",
"action": "{{strategy.order.action}}",
"marketPosition": "{{strategy.market_position}}",
"prevMarketPosition": "{{strategy.prev_market_position}}",
"instrument": "{{ticker}}",
"signalToken": "******",
"timestamp": "{{timenow}}",
"maxLag": "60",
"investmentType": "base",
"amount": "{{strategy.order.contracts}}"
}2. Order Size: Contracts
Note: Contract definitions differ between platforms.
- In TradingView: 1 contract = 1 unit of base currency (e.g., 1 BTC)
- In OKX: Contract size varies (e.g., BTCUSDT = 0.01 BTC per contract)
Use the same JSON template above with "investmentType": "base" for direct mapping.
3. Order Size: Percentage of Equity
While possible, this method relies heavily on backtest estimates and may not reflect real-market performance accurately. For consistency, prefer defining orders in USDT or contracts.
- Click "Alerts" in the top toolbar → Change condition to your strategy → Select "Once Per Bar" and set alert expiration to "Open-ended".
- Paste the OKX-provided alert message template into the "Message" section.
- Under Webhook URL, paste your copied OKX webhook and click "Create".
🔐 A paid TradingView subscription is required to use webhook alerts.
Step 3.2: Using a TradingView Indicator/Study Script
- Configure your indicator in the Pine Editor and add it to the chart.
- Click "Alerts", set the condition (e.g., MACD Golden Cross), and choose "Open-ended" alert duration.
- From OKX’s Custom tab under AlertMsg specs, copy the correct message template and paste it into the alert’s Message field.
- Insert your webhook URL and create the alert.
📌 Important: OKX supports four key actions:
ENTER_LONGEXIT_LONGENTER_SHORTEXIT_SHORT
Choose the correct message type based on your trading logic.
Step 3.3: Using Chart Analysis (No Scripting)
- Click "Alerts", set a condition (e.g., RSI(14) crosses above 30), then paste the OKX AlertMsg specification into the message box.
- Add your webhook URL and create the alert.
Ensure your message includes one of the four supported actions listed above.
Step 3.4: Using Third-Party Programs (e.g., Python)
For developers sending signals from native applications:
Use the following Python example to send POST requests:
import datetime
import json
import requests
symbol = 'BTC-USDT-SWAP'
signal_data = {
"action": "ENTER_LONG",
"instrument": symbol,
"signalToken": "your_signal_token",
"timestamp": datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
"maxLag": "2000",
"orderType": "market",
"orderPriceOffset": "0.1",
"investmentType": "percentage_balance",
"amount": "100"
}
response = requests.post('https://www.okx.com/join/8265080algo/signal/trigger', data=json.dumps(signal_data))
if response.status_code == 200:
print("Signal triggered successfully")
else:
print("Signal trigger failed")⚠️ To send signals from a fixed IP address, contact OKX support or email [email protected] with justification. Otherwise, external signals will be rejected.
Step 4: Set Up Your Signal Bot on OKX
Now that signals are being sent, it’s time to link them to a live bot.
Click "Create Bot" and configure:
- Trading Pair: Match it with your signal source
- Leverage: Choose based on risk tolerance (higher leverage increases both gains and risks)
- Margin: Allocate capital you’re comfortable committing
Advanced Settings:
- Order Type: Market or limit orders
- Entry Settings: Define investment per trade as a fixed amount (e.g., 1000 USDT) or percentage of balance (e.g., 10%)
- Exit Settings: Set Take Profit (TP) and Stop Loss (SL) levels to manage risk automatically
You can define these parameters either at the bot level or receive them dynamically via alert messages—offering flexibility for both beginner and advanced traders.
Click "Confirm" to activate your bot.
Step 5: Monitor and Manage Your Signal Bot
Congratulations! Your signal bot is now live, receiving signals and executing trades in real time.
Access full control via:
- The Bot Details page
- The Bot Orders tab at the bottom of the trading interface
Key Management Features:
1. Adjust Bot Margin
Add or withdraw margin anytime to scale exposure or secure profits.
2. Place Manual Orders
Execute manual trades within the bot regardless of incoming signals—ideal for adjusting positions based on real-time analysis.
3. Close Open Positions Instantly
Click "Close All" to liquidate any open position at market price. A confirmation popup ensures accuracy before execution.
4. Stop the Signal Bot
Stopping the bot will:
- Liquidate all open positions
- Cancel pending orders
- Return remaining assets to your trading account
You can stop the bot from either the Bot Details page or the Bot Orders tab.
👉 Start automating your trading strategy with precision and confidence.
Frequently Asked Questions (FAQ)
Q1: Can I use free TradingView alerts with OKX?
No. Webhook integration requires a paid TradingView subscription (Pro, Pro+, or Premium).
Q2: What happens if a signal is delayed?
OKX uses a maxLag parameter (in seconds) to validate signal freshness. If a signal exceeds this threshold, it’s rejected to prevent outdated executions.
Q3: Can I run multiple signal bots simultaneously?
Yes. You can create separate bots for different strategies, pairs, or signal sources—all running independently.
Q4: Do I need coding skills to set this up?
Not necessarily. While Pine Script offers advanced customization, basic setups using built-in indicators or chart conditions require no coding.
Q5: How do I test my setup before going live?
Use OKX’s demo trading environment or start with small capital allocations to validate performance under real market conditions.
Q6: Are there fees for using the signal bot?
There are no additional fees for using the signal bot feature. Standard trading fees apply based on your tier and volume.
Final Thoughts
Integrating TradingView signals with OKX’s signal trading bot empowers traders with automation, precision, and scalability. Whether you're a technical analyst using MACD crossovers or a developer running custom algorithms, this system adapts to your workflow.
With proper configuration and risk management, automated trading becomes not just convenient—but strategically powerful.
👉 Unlock advanced trading automation tools now—start building smarter strategies today.