Automating your trading strategy has never been easier. With the integration between OKX and TradingView, users can now seamlessly connect their technical analysis and signal scripts to execute real-time trades through the OKX signal bot. Whether you're a strategy developer, an indicator creator, or a third-party tool user, this guide walks you through setting up a fully functional signal bot on OKX using TradingView alerts — step by step.
This comprehensive walkthrough ensures compatibility, accuracy, and flexibility across various trading styles. Let’s dive in.
Step 1: Access the Signal Bot on OKX
Log in to your OKX account and navigate to:
Trade → Trading Bots → Marketplace
From there, select Signal Bot and click Create to begin setting up your automated trading system.
This section is where your external signals — generated from TradingView or custom tools — are linked to live trading execution on OKX.
👉 Start automating your trades with precision and speed today.
Step 2: Create a New Signal
Click Add Custom Signal to initiate the setup process.
The interface is streamlined for ease of use. Enter a signal name and optionally add a description (up to 500 characters). Once done, click Create Signal to proceed.
You’ll be provided with:
- A webhook URL
- An auto-generated AlertMsg specification
These are critical for connecting your TradingView alerts to OKX. You’ll paste the webhook into TradingView and format your alert messages according to OKX’s required JSON structure.
There are two primary ways to configure alerts:
- TradingView (Strategy) – Ideal for users leveraging Pine Script™ strategies using
strategy.*()functions. - Custom (Indicator or Third-Party Tools) – Designed for those using indicators, chart-based alerts, or external programs like Python scripts.
Quick Guide: Pine Script™ Strategy vs Indicator
Understanding the difference between Pine Script™ strategies and indicators helps determine which setup path suits your needs.
1. TradingView Strategy
Strategies in Pine Script™ allow backtesting on historical data and forward-testing in live markets. They utilize strategy.*() functions to simulate trade entries and exits via Pine’s broker emulator. Results appear under the Strategy Tester tab below your chart.
If you’re using strategy scripts with strategy.entry(), strategy.close(), etc., follow the TradingView Strategy Setup guide below.
2. TradingView Indicator
Indicators perform calculations but do not support backtesting or order simulation. Known as “study” scripts in Pine Script v4, they consume fewer resources and execute faster than strategies.
Use the Custom Alert Setup if you're working with:
- MACD, RSI, or other technical indicators
- Chart-based triggers (e.g., price crossing a moving average)
- External platforms sending signals
Before proceeding, ensure you’re trading the correct instrument — especially perpetual swap contracts supported by OKX. You can view all available pairs under the Trade section on OKX.
Step 3.1: Setting Up a TradingView Strategy Script
Follow these steps if you're using a Pine Script™ strategy that includes strategy.*() functions.
Step 1: Open the Pine Editor, set up your strategy script, then click Save and Add to Chart.
Step 2: Click the gear icon next to your added strategy. Adjust settings like order size according to your preferences, then click OK.
Matching Order Size Between TradingView and OKX
OKX supports three methods for defining position size:
1. Order Size in USDT
Enter a fixed amount in USDT (quote currency). For full compatibility:
- Set
"investmentType": "base" - Use
"amount": "{{strategy.order.contracts}}"
This ensures direct translation of contract quantities from TradingView to OKX.
{
"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 in Contracts
Note: “Contract” means different things on each platform.
- On TradingView: 1 contract = 1 unit of base asset (e.g., 1 BTC)
- On OKX: BTCUSDT-SWAP contract = 0.01 BTC
To align:
- Use
"investmentType": "base" - Map
"amount": "{{strategy.order.contracts}}"
This maintains consistency in base asset sizing.
3. Order Size as % of Capital
While possible, this method relies heavily on backtest calculations and may lead to discrepancies in live trading due to simulated vs actual execution. We recommend using fixed USDT or contract values instead.
Step 3: Click Create Alert on the toolbar. Set condition to "Order fills only" and choose "No expiration".
Step 4: Copy the OKX alert template from the Signal Bot specifications and paste it into the Message field of the alert.
Step 5: Paste the webhook URL from OKX into the Webhook URL field. Click Create.
⚠️ A paid TradingView subscription is required for webhook functionality.
Step 3.2: Setting Up a TradingView Indicator Script
For indicator-based signals (e.g., MACD crossover):
Step 1: Save and add your indicator script to the chart.
Step 2: Create an alert using alertcondition() logic (e.g., ta.crossover(macdLine, signalLine)). Choose a relevant message like ENTER_LONG.
Select "No expiration" for continuous monitoring.
Copy the OKX alert template into the message field.
✅ Important: OKX supports four action types:
ENTER_LONGEXIT_LONGENTER_SHORTEXIT_SHORT
Choose the correct one based on your strategy logic.
Step 3: Paste the OKX webhook URL and create the alert.
Step 3.3: Using Chart Analysis Without Scripts
Even without Pine Script™, you can trigger signals based on visual chart patterns:
Step 1: Click Create Alert, define your condition (e.g., RSI crosses above 30), and insert the OKX AlertMsg JSON into the message box.
Ensure you specify the correct action type (ENTER_LONG, etc.).
Step 2: Paste the webhook URL and confirm.
You can manage all alerts under the Alerts tab in TradingView.
Step 3.4: Using Third-Party Programs (e.g., Python)
Developers can send signals directly from native applications.
For example, here's how to trigger a long entry via 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": "100"
}
response = requests.post('https://www.okx.com/join/8265080algo/signal/trigger', data=json.dumps(signal_data))📌 If sending from a fixed third-party IP, contact support at [email protected] to whitelist your address. Otherwise, signals will be rejected by default.
Step 4: Configure Your Signal Bot
Now that your signal is live, return to OKX and click Create Bot.
Configure these key settings:
- Trading Pairs: Select instruments matching your signal logic.
- Leverage: Choose a multiplier (e.g., 5x, 10x). Higher leverage increases both potential gains and risks.
- Investment Amount: Define total margin allocated to the bot.
Advanced Settings:
- Order Type: Choose between market orders (instant execution) or limit orders (price-controlled).
- Per Order Investment: Set fixed amounts (e.g., 500 USDT) or percentages (e.g., 10% of balance).
- Take Profit (TP) & Stop Loss (SL): Automate exit rules for risk management.
- Source-specific parameters can be overridden via incoming alerts for dynamic control.
Click Confirm when done.
👉 Unlock advanced automation features with OKX’s powerful trading bots.
Step 5: Monitor and Manage Your Signal Bot
Congratulations! Your signal bot is now active and executing trades in real time based on your defined logic.
Access full details via the bot’s info page, where you can view:
- Current positions
- Open orders
- Trade history
- Signal processing logs
Use this data to refine strategies and improve performance over time.
Key Management Features:
1. Adjust Margin (Add/Reduce)
Modify margin anytime — increase funding or withdraw profits after strong ROI.
2. Manual Order Placement
Place trades manually regardless of incoming signals. Useful for scaling positions or taking discretionary actions.
3. Instant Position Closure
Close any open position with one click at market price. Ideal during volatile conditions or strategy shifts.
4. Stop the Signal Bot
Stopping the bot closes all positions and cancels pending orders. Assets are returned to your main account.
You can stop it from:
- The bot info page (top-right “Stop” button)
- The orders tab under Trade → Bot Orders
Frequently Asked Questions (FAQ)
Q: Can I use free TradingView accounts for webhook alerts?
A: No. Webhook integration requires a paid TradingView plan (Pro or higher).
Q: What happens if a signal is delayed or missed?
A: Use the maxLag parameter (in seconds) to define acceptable delay tolerance. Signals exceeding this threshold are ignored for safety.
Q: Can I use multiple signals for one bot?
A: Yes. As long as they share the same signalToken, multiple alert sources can feed into a single bot.
Q: Is leverage applied per trade or globally?
A: Leverage is set globally at the bot level and applies uniformly across all trades unless overridden by smart routing logic.
Q: How do I test my setup before going live?
A: Use paper trading in TradingView combined with demo mode on OKX (if available) to validate signal accuracy and execution flow.
Q: Can I change TP/SL levels after entering a trade?
A: Yes. You can manually update take-profit and stop-loss levels anytime via the bot interface.
Final Thoughts
Integrating TradingView with OKX unlocks powerful opportunities for automated crypto trading. By following this guide, you’ve taken a major step toward efficient, data-driven decision-making in real time.
Whether you’re building Pine Script™ strategies, using technical indicators, or coding custom solutions, the flexibility of OKX’s signal bot system empowers traders at every level.
👉 Maximize your trading efficiency — connect your first signal today.