OKX Signal Strategy Alert Specifications 2.0

·

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:

👉 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:

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

ParameterDescription
idUse {{strategy.order.id}} — unique identifier from your strategy order call
actionUse {{strategy.order.action}} — returns "buy" or "sell"
marketPositionUse {{strategy.market_position}} — current position: "long", "flat", or "short"
prevMarketPositionUse {{strategy.prev_market_position}} — previous position state
instrumentUse {{ticker}} or map to OKX format (e.g., BTC-USDT-SWAP)
signalTokenProvided by OKX when creating a signal; must be manually added
timestampUse {{timenow}} — UTC time in ISO 8601 format (e.g., 2023-06-01T17:38:10Z)

Optional Fields

ParameterDefault / Notes
maxLagInteger between 1–3600 seconds; default: 60
investmentTypeRecommended: "base" for maximum compatibility
amountMust correspond to investment type (e.g., contract size, percentage)
💡 Best Practice Tip: To ensure perfect synchronization with your PineScript strategy, set investmentType to "base" and amount to {{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:

5. Instrument Formatting

You can use:

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:


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

ParameterValue Options
actionENTER_LONG, ENTER_SHORT, EXIT_LONG, EXIT_SHORT
instrument{{ticker}} or OKX format (e.g., ETH-USDT-SWAP)
signalTokenFrom OKX signal creation
timestamp{{timenow}} in UTC ISO format

Optional Fields

ParameterConditions
maxLag1–3600 sec; default: 60
orderTypemarket (default), limit
orderPriceOffsetRequired if orderType = limit; range: 0–100%
investmentType & amountRequired only if not pre-configured in OKX bot

👉 Learn how top traders automate strategies without writing code.

Action Types Explained

These actions assume single-directional (one-way mode) trading on OKX.

Order Execution Settings

Order Type

Order Price Offset Calculation

When using limit orders:

This helps balance execution speed and price quality.

Investment Management

Same logic as Section A:

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&timestamp={{timenow}}
...
action=EXIT_LONG&instrument=BTC-USDT-SWAP&signalToken=abc123&timestamp={{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:

Example 7: Parameter Priority 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.

👉 Start building your own automated trading system today.