How to Connect TradingView Strategies with OKX Trading Bot Using Custom Mode

·

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.

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

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