Custom integration mode offers a distinct approach compared to quick connection mode. While quick connection relies on TradingView strategy settings to determine order quantities, custom mode allows you to preset order quantities directly within the trading bot during message parameter generation. This method is specifically recommended for strategies that do not involve scaling in/out of positions. Strategies incorporating partial take-profit, stop-loss, or position scaling should utilize the quick connection mode instead.
Preparation Before Getting Started
Before connecting your automated trading system, proper setup is essential to ensure smooth operation.
- Exchange Account Preparation: You need an active OKX exchange account. If you don't have one, you must register for a new account first. Subsequently, apply for a V5 API key within your account settings. The备注名称 (remark name) can be arbitrary, but the permissions must be set to 'Read-Only' and 'Trade'. Importantly, do not enable 'Withdraw' permissions. Confirm and add the API key once configured.
- Position Management: Before initiating any strategy, it is critical to clear any existing open positions for the specific cryptocurrency pair you intend to trade. This prevents management conflicts and ensures the bot operates from a clean slate.
- Strategy Allocation: The system supports running multiple strategies across different cryptocurrency pairs simultaneously. However, you must avoid running more than one strategy on the same currency pair at the same time, as this will lead to position management conflicts. You can customize connection indicators based on your specific requirements.
- Manual Intervention Caution: If you manually manage a position that is currently being managed by the bot, it may cause data synchronization issues. Should this occur, you must stop and then restart the service within the bot's interface to re-synchronize.
- Order Mode Configuration: A common reason for failed orders is an incompatible exchange order mode. If orders are not executing successfully upon startup, log into your OKX trading interface. Locate the settings menu (often on the left or right side) and change the
Order Mode(下单模式) toBuy/Sell Mode(买卖模式). The same principle applies to other exchanges like Binance. You can review the 'Call Log' interface within the bot for common error troubleshooting, which often involves correcting the position mode.
Step-by-Step Guide to Custom Integration
Please ensure you select OKX as the data source within TradingView when using the OKX Trading Bot.
Automated trading is achieved by utilizing TradingView's alert signals. The process for connecting a strategy differs slightly from connecting an indicator. For strategy integration, click the clock icon on the strategy back-testing interface.
Next, return to the OKX trading bot interface. Select the trading pair you wish to trade (remember to use OKX data source; for TV perpetual contracts, select pairs ending with PERP). Choose the 'Custom Integration' option for strategies and define the specific parameters for each order, including the quantity.
Within your TradingView strategy settings, you can set the 'Pyramiding' parameter to 1. This instructs the strategy to open only one long or short position at a time. Then, in the trading bot's integration interface, enable the 'Anti-Adding' protection (加仓保护) and check the 'Reverse Position' (做反手) option. This configuration means that before opening a sell order, the bot will check your current position. If you are long, it will close the long position before selling to open a short position.
Finally, click to generate the TradingView alert configuration.
The alert name can be chosen arbitrarily, for example: "XX Strategy".
Key Configuration Explanations
- Reverse Position (做反手): When enabled, the bot checks your current holdings before executing a new order. For a sell signal: if you hold a long position, it will close the long first before selling to open a short. For a buy signal: if you hold a short position, it will close the short first before buying to open a long. If disabled, the bot does not check your position. For example, if you hold a 2 BTC long position and receive a signal to open a 1 BTC short, the result would be a reduced net long position of 1 BTC. The system defaults to this being enabled.
- Anti-Adding Protection (加仓保护): When checked, this function prevents repeated orders for the same position, effectively disabling the ability to add to (scale into) a position. If your TradingView strategy has the 'Pyramiding' parameter set to a value other than 1, you must uncheck this option. It is checked by default.
👉 Explore advanced trading automation tools
Frequently Asked Questions
What is the main difference between Custom and Quick connection modes?
Custom mode allows you to preset the order quantity directly within the trading bot's parameters, making it suitable for simple strategies. Quick connection mode defers quantity control entirely to the settings within your TradingView strategy, which is necessary for more complex strategies involving scaling.
Why is it important to clear existing positions before starting a bot?
The trading bot manages positions based on its internal logic and signals. Pre-existing positions can confuse the bot's accounting, leading to incorrect order sizes, unintended net exposure, or management conflicts. Starting from a zero position ensures clean and accurate operation.
Can I run the same strategy on multiple timeframes for one coin?
No, it is strongly advised against running multiple strategies, even the same one on different timeframes, on a single cryptocurrency pair simultaneously. This will result in conflicting orders and unmanageable position overlap, likely causing significant financial loss.
What should I do if I manually close a position managed by the bot?
Manual intervention disrupts the bot's internal tracking. If you manually modify a bot-managed position, you must stop the bot's service and then restart it. This allows the bot to perform a fresh check of the current exchange state and re-synchronize before processing new signals.
Why might my strategy not be placing any orders?
The most common cause is an incorrect 'Order Mode' on the connected exchange. Ensure it is set to 'Buy/Sell Mode' (买卖模式) instead of a different mode like 'Net' mode. Always check the bot's call logs for specific error messages related to API calls or exchange rejections.
When should I disable 'Anti-Adding Protection'?
You should disable this feature if your TradingView strategy is designed to scale into positions by having a 'Pyramiding' value greater than 1. If pyramiding is set to 1 (only one open position), keeping anti-adding protection enabled is recommended to prevent accidental duplicate orders.