Automated trading has become increasingly accessible, and with the integration between OKX and TradingView, users can now seamlessly configure a signal bot to execute trades based on real-time alerts. Whether you're a strategy developer, technical analyst, or third-party signal provider, this step-by-step guide will help you connect your TradingView signals to an OKX trading bot for automated, efficient, and precise trading.
By following this guide, you’ll learn how to set up your signal, configure alerts correctly, and manage your bot with advanced settings like leverage, position sizing, stop loss, and take profit—maximizing your trading potential.
Step 1: Access the Signal Bot on OKX
Log in to your OKX account, then navigate through the platform as follows:
- Go to Trade → Trading Bots → Market
- Select the Signal Bot tab
- Click on Create to begin setting up your bot
This opens the gateway to building a fully automated trading system powered by your own strategies or third-party signals from TradingView.
👉 Start automating your trading strategy today with powerful tools
Step 2: Create Your Trading Signal
Click Add Custom Signal to start creating your personalized trading signal.
You’ll be prompted to:
- Assign a name to your signal
- Optionally add a description (up to 500 characters)
Once completed, select Create Signal to proceed.
After creation, you’ll be directed to a new page displaying two critical pieces of information:
- The Webhook URL
- The Alert Message Template
These are essential for connecting your TradingView alerts to OKX. Keep this page open—you’ll need both elements in the next steps.
Understanding Pine Script: Strategy vs Indicator
Before configuring alerts, it’s important to understand the difference between two types of Pine Script™ scripts used in TradingView:
1. TradingView Strategy Scripts
These scripts are designed for backtesting and forward testing on live markets. They use strategy.entry() and other strategy functions that simulate trade execution through Pine Script’s broker emulator. Results appear in the Strategy Tester panel below the chart.
If you're using a Pine Script strategy with built-in order logic, follow the Strategy Script Guide.
2. TradingView Indicator (Study) Scripts
Indicators perform calculations but do not support backtesting or simulated order execution. Known as "studies" in Pine Script v4+, they consume fewer resources and run faster than strategies.
If you’re using custom indicators, chart-based analysis, or third-party tools, use the Custom/Indicator Method instead.
Step 3: Configure TradingView Alerts
Open TradingView.com, choose your preferred trading pair (e.g., BTC-USDT-SWAP), and ensure you're viewing the correct perpetual contract supported by OKX.
Now, depending on how your signal is generated, follow one of the four methods below.
Method A: TradingView Strategy Scripts
Use this method if you're working with a Pine Script strategy that includes strategy.entry() or similar functions.
Step 1: Set Up Your Strategy
- Open the Pine Editor
- Load or write your strategy script
- Click Save and then Add to Chart
Step 2: Configure Strategy Settings
- Click the gear icon next to the strategy name on the chart
- Adjust parameters like order size, initial capital, etc.
- Confirm with OK
Step 3: Align Order Size with OKX
Ensure compatibility between TradingView and OKX by correctly mapping order values. OKX expects the "amount" field to reflect base currency units (e.g., BTC), so configure accordingly:
Option 1: Order Size in USDT
Set "investmentType": "base" and "amount": "{{strategy.order.contracts}}"
Since {{strategy.order.contracts}} represents base currency quantity (not quote), this aligns directly with OKX.
{
"id": "{{strategy.order.id}}",
"action": "{{strategy.order.action}}",
"instrument": "{{ticker}}",
"signalToken": "********",
"timestamp": "{{timenow}}",
"maxLag": "60",
"investmentType": "base",
"amount": "{{strategy.order.contracts}}"
}Option 2: Order Size in Contracts
Note: “Contract” means different things on TradingView vs OKX.
On TradingView, 1 contract = 1 unit of base asset (e.g., 1 BTC).
On OKX, BTC-USDT-SWAP = 0.01 BTC per contract.
To align:
- Use
"investmentType": "base" - Set
"amount": "{{strategy.order.contracts}}"
This ensures proper scaling when translated to OKX contract sizes.
Option 3: Order Size as % of Equity
While possible, backtested equity calculations may not reflect live performance accurately. For reliability, prefer fixed USDT or contract-based sizing.
Step 4: Create the Alert
- Click Alert in the top toolbar
- Change alert condition to “Order Execution Only”
- Set expiration to “Open-ended” for continuous monitoring
- Paste the OKX alert message template into the Message field
- Under Notifications, select Webhook URL
- Paste the Webhook URL from your OKX signal page
- Click Create
💡 A paid TradingView subscription is required to use Webhook alerts.
Method B: Custom Indicator or Study Scripts
For users leveraging Pine Script indicators (e.g., MACD crossovers):
Step 1: Add Script to Chart
- Edit and save your indicator in Pine Editor
- Click Add to Chart
Step 2: Create Alert
- Click Alert
- Choose the relevant trigger condition (e.g., “MACD Golden Cross”)
- Set expiration to “Open-ended”
- Paste the Custom Alert Template from OKX into the message box
⚠️ OKX supports four action types:ENTER_LONG,EXIT_LONG,ENTER_SHORT,EXIT_SHORT. Select the correct one based on your trading logic.
Step 3: Add Webhook
- In Notifications, choose Webhook URL
- Paste your unique Webhook from OKX
- Click Create
Method C: Chart-Based Technical Analysis
For traders using drawing tools or basic indicators (e.g., RSI > 30):
Step 1: Create Manual Alert
- Click Alert
- Define condition (e.g., price crosses moving average)
- Paste OKX’s alert message format into the message field
🔗 Learn more about OKX alert message specifications
Step 2: Connect via Webhook
- Paste your signal’s Webhook URL
- Confirm creation
Method D: Third-Party Software Integration
Signal providers using external platforms (e.g., Python scripts) can push signals directly via HTTP POST requests.
Here’s an example using Python:
import requests
import datetime
import json
signal_data = {
"action": "ENTER_LONG",
"instrument": "BTC-USDT-SWAP",
"signalToken": "your_token_here",
"timestamp": datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
"maxLag": "2000",
"investmentType": "percentage_balance",
"amount": "50"
}
response = requests.post('https://www.okx.com/join/8265080algo/signal/trigger', json=signal_data)
print(response.status_code, response.json())🔒 If sending from a fixed IP address, contact OKX customer support to whitelist your endpoint. Otherwise, signals may be rejected.
Step 4: Configure Your Signal Bot
Now that your signal is active, return to OKX and create your bot:
Click Create Bot, then configure:
Basic Settings
- Trading Pairs: Select which markets the bot will monitor
- Leverage: Choose isolated or cross margin; set leverage ratio (e.g., 10x)
- Margin Amount: Allocate funds for trading
⚠️ Leverage amplifies both gains and losses—choose wisely based on risk tolerance.
Advanced Settings
- Order Type: Market or Limit orders
- Position Size: Define per trade (fixed amount or % of balance)
- Take Profit (TP) & Stop Loss (SL): Automate exits for risk management
You can define these parameters either at the bot level or let them be dynamically controlled by incoming alerts.
Once configured, click Confirm to launch your bot.
👉 Maximize your strategy’s potential with automated execution
Step 5: Monitor and Manage Your Bot
Congratulations! Your signal bot is now live and executing trades based on real-time alerts.
Access full control via:
- Bot Details Page: View performance history, open positions, orders, and signal logs
- Manual Controls: Add/remove margin, place manual orders, close positions instantly
Key Management Features
1. Adjust Margin
Add or withdraw funds anytime based on performance or market outlook.
2. Place Manual Orders
Override automation when needed—enter, scale in/out of positions manually.
3. Close Open Positions Instantly
One-click closure at market price with confirmation prompt.
4. Stop the Bot
Two ways:
- From Bot Details → Click “Stop”
- From Trading Bots → Find and stop via list
Stopping closes all open positions and cancels pending orders. Remaining assets return to your trading account.
Frequently Asked Questions (FAQs)
Q1: What is a TradingView webhook?
A webhook allows TradingView to send real-time data (like trade signals) to external services such as OKX. It enables automated trading without manual intervention.
Q2: Can I use free TradingView alerts with OKX?
No. Webhook functionality requires a Pro, Pro+, or Premium TradingView plan. Free accounts cannot send data to external URLs.
Q3: Why isn’t my bot executing trades?
Common causes include:
- Incorrect alert message format
- Expired or misconfigured webhook
- Mismatched instrument names (e.g., BTCUSD vs BTC-USDT-SWAP)
Double-check formatting and ensure your signal matches OKX specifications.
Q4: How do I test my signal before going live?
Use demo mode in TradingView or send test alerts to verify connectivity. You can also simulate executions using small amounts initially.
Q5: Can I run multiple bots with one signal?
Yes. One signal can feed multiple bots across different pairs or configurations—ideal for portfolio diversification.
Q6: Is there a delay between signal and execution?
Delays depend on network speed and "maxLag" setting. We recommend setting "maxLag" between 60–2000 milliseconds to balance responsiveness and reliability.
Core Keywords for SEO
OKX trading bot, TradingView signal integration, automated crypto trading, Pine Script strategy, webhook trading bot, crypto signal bot, perpetual swap trading, algorithmic trading setup
👉 Turn your trading ideas into automated actions—start building now