The launch of the Signal Bot allows TradingView users and signal providers to publish and set up automated trading directly using their TradingView signals. This guide provides a step-by-step process to start signal-based trading on OKX.
Step 1: Accessing the Signal Bot
Log in to your OKX account and navigate to Trade -> Trading Bots -> Marketplace. Next, select the Signal Bot sub-tab and click the 'Create' button to begin the setup process.
Step 2: Creating Your Signal
You will find an option to create a custom signal. Select 'Add Custom Signal' to start. The process is streamlined for user convenience. First, assign a name to your signal and add an optional description (up to 500 characters). Once completed, select 'Create Signal' to proceed to the next stage.
After creation, you will be directed to a new page prompting you to add the automatically generated OKX Webhook URL and AlertMsg specifications. This is where you will configure your signal push alert on TradingView. There are two distinct configuration methods:
- TradingView: For users employing TradingView strategy scripts, specifically those utilizing strategy.*() functions to transmit signals.
- Custom: Designed for a broader audience, including users of TradingView indicators, chart alerts, and third-party program providers.
A Quick Overview: Pine Script™ "Strategy" vs. "Indicator"
TradingView Strategy
Pine Script™ strategies are designed for conducting historical backtesting and live market testing. Beyond performing indicator calculations, a strategy includes calls to strategy.*() functions to send trade orders to Pine Script™'s broker simulator. This simulator can then simulate the execution of these orders. Backtest results are displayed in the "Strategy Tester" tab at the bottom of the chart, next to the "Pine Script™ Editor" tab. If you use a TradingView strategy script with strategy.*() functions, proceed directly to the TradingView strategy.*() function guide.
TradingView Indicator
Pine Script™ indicators also involve calculations but are not intended for use in backtesting scenarios. Due to their independence from the broker simulator, indicators consume fewer resources and execute faster. In PineScript™ v4+, these are also referred to as study scripts. For users of indicators/study scripts and third-party programs, please proceed to the relevant section tailored for these more general use cases, including chart alerts.
Step 3: Configuring the TradingView Alert
To begin, open your TradingView chart and select the trading pair you wish to use. Ensure you have selected the appropriate perpetual swap contract. You can access the full list of supported perpetual swaps on OKX through the pair selector on the Trading page.
Step 3.1 [TradingView Strategy Script Guide]: For PineScript™ Strategy Creators Using strategy.*()
- Configure your strategy script in the Pine Editor and click "Save" and "Add to Chart." Alternatively, if you already have a strategy script, add it to your chart.
- Click the gear icon linked to the strategy you added. Adjust the strategy properties, such as order size, to your preferences. Click "OK" to confirm the settings.
How to Align TradingView Strategy Order Settings with OKX?
In a TradingView strategy, you have three options to configure order parameters: defining "order size" in USDT, number of contracts, or as a percentage of equity based on your Initial Capital. While all these approaches can be adapted for OKX, it's crucial to understand how each functions.
1. Order Size: USDT
This method is straightforward. You directly input the order size as an absolute value in the quote currency, USDT. For seamless OKX compatibility, set "investmentType" to "base" and configure "amount" to "{{strategy.order.contracts}}".
2. Order Size: Contracts
A key distinction is that the concept of a "contract" is defined differently on TradingView and OKX. On TradingView, one contract represents one unit of the perpetual swap at the current price. On OKX, "contract size" is unique to each perpetual swap. To ensure seamless alignment with OKX, configure "investmentType" to "base" and set "amount" to "{{strategy.order.contracts}}".
3. Order Size: % of Equity
When using "% of equity," the starting equity is the value you specify as Initial Capital. Equity is then determined and evaluated through the TradingView backtesting process. While this can be simulated, it's often recommended to use USDT or contract terms for order size definition on TradingView due to differences between backtesting and live trading.
- Click the "Alert" button on the top toolbar. Change the "Condition" to the script you just added using "Order Fills Only." You may also set the Expiry to "Open-Ended Alert" for convenience.
- Retrieve the alert message template from the TradingView tab in the OKX AlertMsg Specifications on your OKX Signal. Paste this template into the "Message" section of your TradingView alert, along with a corresponding Alert Name.
- Select the Webhook URL* option under "Notifications." Paste the webhook URL copied from OKX into the TradingView field and click "Create."
*Please note: A paid TradingView subscription is required to access the Webhook feature.
Step 3.2 [TradingView Indicator/Study Guide]: For PineScript™ Indicator/Study Creators
- Configure your script in the Pine Editor and click "Save" and "Add to Chart."
- Click the "Alert" button on the top toolbar. Change the "Condition" to the script you just added using the corresponding Alert Condition. Finally, retrieve the alert message template from the Custom tab in the OKX AlertMsg Specifications on your OKX Signal. Paste this template into the "Message" section.
*IMPORTANT: OKX provides 4 different message templates for different operations (i.e., ENTER\_LONG, EXIT\_LONG, ENTER\_SHORT, EXIT\_SHORT). When setting up your alert, please choose the appropriate template based on your trading logic.
- Select the Webhook URL* in "Notifications." Paste the webhook URL copied from OKX into TradingView and click "Create."
Step 3.3 [Chart Analysis Guide]: For Users Employing Chart Analysis
- Click the "Alert" button on the top toolbar and set your condition based on your typical trading triggers (e.g., RSI-14 crossing above 30). Next, paste the OKX AlertMsg Specifications into the "Message" section.
*IMPORTANT: We support 4 different message types for different operations. Please select the appropriate alert based on your trading logic.
- Select the Webhook URL* in "Notifications." Paste the webhook URL copied from OKX and click "Create."
- To view the created alert, click the "Alerts" tab and select the corresponding alert.
Step 3.4 [Third-Party Program Guide]: For Signal Providers
For providers using native programs to transmit messages, please refer to the provided Python webhook request example in the appendix. If you plan to send requests from a fixed third-party IP address to OKX, please contact our customer service team with the relevant reason to ensure your request is managed appropriately.
Step 4: Creating Your Signal Trading Bot
Now that your signal is successfully published on OKX, it's time to connect it to a Signal Bot! Click 'Create Bot,' which will take you to the Signal Bot creation page.
You need to provide the minimum required bot settings, including applicable trading pairs, leverage ratio, and the amount (margin) you wish to invest. Selecting the correct trading pairs is essential for your bot to identify the right opportunities. Next, define your desired leverage ratio, remembering that leverage can amplify both profits and risks. Finally, decide the amount of capital to allocate.
Beyond basic settings, the bot offers advanced customization options to fine-tune your trading preferences. You can choose between order types like Market or Limit. The investment per order setting allows you to define the amount allocated to each trade, either as an absolute value (e.g., 1000 USDT) or a percentage (e.g., 10% of available balance).
Additionally, you can set Take Profit (TP) and Stop Loss (SL) levels as part of your exit strategy. For most advanced settings (except TP/SL), you can define them at the bot level or rely on your TradingView alert message to receive these parameters, offering flexibility for your workflow.
After entering your desired bot parameters, select 'Confirm' to complete the creation of your Signal Trading Bot.
Step 5: Monitoring and Managing Your Signal Bot
Congratulations! Your Signal Bot is now active. This powerful tool will listen for signals from your chosen source and execute trades automatically in real-time.
You have full control and visibility over your bot. You can monitor its performance and access detailed insights by clicking the 'Details' icon. This comprehensive view allows you to track performance history, review open positions, monitor pending orders, and explore your position and signal history.
You can also review the historical signal log and corresponding operations, a valuable resource for analyzing successes and failures. Furthermore, you can manually intervene whenever necessary.
1. Adjust (Add/Remove) Bot Margin
Within the Bot Details section, you can easily add or remove margin from the bot as needed.
2. Place Manual Orders
You have the freedom to place manual orders within the bot, regardless of incoming signals. This feature allows you to add orders manually for any trading pair based on your specific requirements.
3. Instantly Close Open Positions
You can conveniently view open positions and directly close any existing open position for a specific trading pair with a simple click, closing the position at the current market price.
4. Stop the Signal Bot
When you stop the bot, the system will close all open positions and cancel all pending orders for this bot. Any remaining assets will be returned to your trading fund. You can stop the bot either from the Bot Details page or the Bot Orders tab.
Congratulations on successfully setting up your OKX Signal Bot with TradingView! This achievement marks a significant milestone in optimizing your trading strategy. 👉 Explore more advanced automation strategies
Frequently Asked Questions
Q: Do I need a paid TradingView plan to use the Signal Bot?
A: Yes, a paid TradingView plan is required to access the Webhook alerts feature, which is necessary to send signals from TradingView to your OKX bot.
Q: What is the difference between a 'Strategy' and an 'Indicator' in Pine Script?
A: A Strategy includes backtesting capabilities and simulated order execution using strategy.*() functions. An Indicator (or Study) performs calculations and plots data but does not place simulated orders, making it lighter and faster.
Q: Can I use the same signal for multiple trading bots?
A: Yes, a single published signal can be linked to multiple Signal Trading bots, allowing you to allocate different capital amounts or apply the strategy to various pairs.
Q: What happens if my TradingView alert fails to trigger?
A: If an alert fails to send from TradingView, the OKX bot will not receive a signal and thus will not execute a trade. It's crucial to ensure your TradingView alerts are configured correctly and are triggering as expected.
Q: Can I modify my bot's settings after it's been created?
A: Yes, you can adjust certain settings like allocated margin, leverage, and take profit/stop loss levels after the bot is running from the Bot Details page.
Q: Is there a risk of over-trading with a Signal Bot?
A: The bot only executes trades when it receives a valid signal from your configured source. The risk depends on the frequency of your TradingView alerts. You control the capital allocation per trade, which helps manage overall risk.