Integrating your trading strategies with real-time execution platforms is a game-changer for modern traders. With the launch of OKX signal bots, TradingView users can now seamlessly publish their signals and automate trades on the OKX platform. This guide outlines the updated OKX Signal Strategy Alert Specifications 2.0, ensuring you configure alerts correctly—whether you're using PineScript™ strategies or other signal generation methods.
Designed for clarity, compatibility, and precision, this specification supports both advanced algorithmic traders and general alert users. Let’s dive into the details.
Understanding Signal Integration on OKX
OKX enables traders to bridge their TradingView signals with automated trading via signal bots. Depending on how you generate signals—using PineScript™ strategy scripts or alternative methods—you can choose between two streamlined formats:
- Section A: Tailored for PineScript™ strategy.* function users
- Section B: Universally compatible for all other use cases
👉 Discover how to turn your trading ideas into automated actions with powerful tools.
Both formats are fully supported and intelligently parsed by the system. The platform automatically detects your format based on the parameters included, ensuring smooth execution regardless of your approach.
PineScript™: Strategy vs Indicator Scripts
Before diving in, it's important to understand the distinction:
- PineScript Strategies use
strategy.*()functions (e.g.,strategy.entry,strategy.exit) to simulate order execution and support backtesting. These are ideal for automated trading logic. - PineScript Indicators perform calculations but don’t generate orders or support backtesting. They’re faster and less resource-intensive.
If you're using strategy.* functions, Section A is optimized for you. If not, proceed to Section B, which offers broader flexibility.
Section A: Specifications for PineScript™ Strategy Users
This format is specifically designed for users leveraging PineScript™ strategies that rely on built-in strategy.* placeholders. It ensures full alignment between your TradingView strategy logic and OKX trade execution.
Core Alert Parameters
Below are the required and optional fields to include in your TradingView alert message.
Required Fields
| Parameter | Description |
|---|---|
id | Use {{strategy.order.id}} — unique identifier from your strategy order call |
action | Use {{strategy.order.action}} — returns "buy" or "sell" |
marketPosition | Use {{strategy.market_position}} — current position: "long", "flat", or "short" |
prevMarketPosition | Use {{strategy.prev_market_position}} — previous position state |
instrument | Use {{ticker}} or map to OKX format (e.g., BTC-USDT-SWAP) |
signalToken | Provided by OKX when creating a signal; must be manually added |
timestamp | Use {{timenow}} — UTC time in ISO 8601 format (e.g., 2023-06-01T17:38:10Z) |
Optional Fields
| Parameter | Default / Notes |
|---|---|
maxLag | Integer between 1–3600 seconds; default: 60 |
investmentType | Recommended: "base" for maximum compatibility |
amount | Must correspond to investment type (e.g., contract size, percentage) |
💡 Best Practice Tip: To ensure perfect synchronization with your PineScript strategy, setinvestmentTypeto"base"andamountto{{strategy.order.contracts}}. This mirrors your exact contract size from TradingView.
Key Placeholder Explanations
1. {{strategy.order.id}}
Unique string assigned to each order in your strategy script (used as first argument in strategy.entry() etc.).
2. {{strategy.order.action}}
Returns "buy" or "sell" based on executed order direction.
3. & 4. marketPosition and prevMarketPosition
These track entry and exit conditions:
- Use transitions like
"flat" → "long"to detect long entries "long" → "flat"indicates full exit
5. Instrument Formatting
You can use:
- TradingView Ticker: e.g.,
BTCUSDT.P - OKX Format: e.g.,
BTC-USDT-SWAP(recommended for clarity)
6. Signal Token
Generated automatically when you create a signal on OKX. Copy this into your alert message exactly as provided.
7. Timestamp ({{timenow}})
Critical for syncing signals across systems. Always use UTC in ISO 8601 format.
8. Max Lag
Defines acceptable delay (in seconds) before discarding stale signals. Helps maintain trade accuracy during network delays.
9. Investment Type & Amount
For best results:
- Entry Signals: Use
"base"with contract count - Exit Signals: Use
"percentage_position"to close partial/full positions
Section B: Universal Compatibility Specifications
This section applies to all users, including those using indicators, manual alerts, or non-strategy scripts. It provides a standardized structure that works across different workflows.
Universal Alert Parameters
Required Fields
| Parameter | Value Options |
|---|---|
action | ENTER_LONG, ENTER_SHORT, EXIT_LONG, EXIT_SHORT |
instrument | {{ticker}} or OKX format (e.g., ETH-USDT-SWAP) |
signalToken | From OKX signal creation |
timestamp | {{timenow}} in UTC ISO format |
Optional Fields
| Parameter | Conditions |
|---|---|
maxLag | 1–3600 sec; default: 60 |
orderType | market (default), limit |
orderPriceOffset | Required if orderType = limit; range: 0–100% |
investmentType & amount | Required only if not pre-configured in OKX bot |
👉 Learn how top traders automate strategies without writing code.
Action Types Explained
- ENTER_LONG / ENTER_SHORT: Open new long/short position
- EXIT_LONG / EXIT_SHORT: Close existing long/short position
These actions assume single-directional (one-way mode) trading on OKX.
Order Execution Settings
Order Type
- Market: Immediate execution at current price
- Limit: Execute at specified offset from best bid/ask
Order Price Offset Calculation
When using limit orders:
- Enter Long:
[1 - offset/100] × best ask - Enter Short:
[1 + offset/100] × best bid - Exit Long:
[1 + offset/100] × best bid - Exit Short:
[1 - offset/100] × best ask
This helps balance execution speed and price quality.
Investment Management
Same logic as Section A:
- Entry signals support margin, contracts, or percentage-based sizing
- Exit signals use
% of open position
Active investment value is set at strategy creation and can be increased manually.
Practical Examples (Section B)
Example 1: Full Long Entry & Exit
action=ENTER_LONG&instrument=BTC-USDT-SWAP&signalToken=abc123×tamp={{timenow}}
...
action=EXIT_LONG&instrument=BTC-USDT-SWAP&signalToken=abc123×tamp={{timenow}}Example 2: Reverse Position (Long → Short)
Uses one signal to close long and open short instantly.
Example 3: Partial Profit-Taking
Use multiple exit signals with decreasing percentages (e.g., 50%, then 50%).
Example 4: Multi-Entry DCA Strategy
Send multiple ENTER_LONG signals with same instrument to average in.
Example 5 & 6: Trigger-Only Signals
Omit investment details if users should decide sizing independently. Default rules apply:
- Enter: Market order, 100% (single pair), 50% (multi-pair)
- Exit: Close 100% of open position
Example 7: Parameter Priority Rules
- Signal strategy settings override alert message fields
- If neither defined, defaults apply per above rules
Frequently Asked Questions (FAQs)
Q: Can I switch between Section A and Section B formats?
A: Yes. The system auto-detects the format based on included parameters. You can even mix approaches across different strategies.
Q: What happens if my signal arrives late?
A: If the delay exceeds maxLag, the signal is rejected. This prevents outdated trades due to latency or disconnections.
Q: Do I need to use OKX’s instrument format?
A: Not mandatory, but strongly recommended. Using formats like BTC-USDT-SWAP avoids ambiguity and ensures correct pairing.
Q: How do I find my signal token on OKX?
A: After creating a signal bot, go to its configuration page. The token appears under “Alert Settings” or “Integration Info.”
Q: Can I send partial close signals?
A: Yes. Use action=EXIT_LONG with investmentType=percentage_position and set amount=50 to close half your position.
Q: Is backtesting supported through these signals?
A: While signals themselves aren't backtested directly, your PineScript strategy can be backtested in TradingView before going live.
Final Thoughts
Whether you're a seasoned coder using PineScript™ strategies or a visual trader relying on chart patterns, OKX’s Signal Strategy Alert Specifications 2.0 offer a robust, flexible framework for automation.
By following these guidelines, you ensure accurate, timely execution of your trading ideas—turning insights into actions with minimal friction.