How to Set Up Automatic Position Closing on Exchange Futures Using TVCBOT and TradingView

·

Automated trading strategies are transforming the way traders manage risk and optimize their workflows. One of the most practical applications is scheduled position closing, allowing you to automatically exit open futures positions at a specific time—even while you're asleep or away from your screen. By combining TradingView’s powerful Pine Script indicators with TVCBOT’s WebHook integration, you can set up a reliable, no-code solution for automatic market exit.

This guide walks you through setting up a time-based close signal using a custom Pine Script on TradingView, then connecting it to TVCBOT for real-time execution across major exchanges. Whether you're managing leveraged positions or simply want to avoid overnight risk, this system offers precision and peace of mind.

Why Automate Position Closing?

Manually monitoring open trades is time-consuming and prone to emotional decision-making. Automated position closing helps:

With the right tools, automation becomes accessible—even without programming skills.

👉 Discover how automated trading signals can simplify your strategy execution

Step-by-Step: Create a Scheduled Close Signal in TradingView

To trigger an automatic close at a predefined time, we use a custom Pine Script indicator that sends an alert when the current time matches your specified hour and minute.

Below is the fully functional script designed for TradingView version 5 (Pine Script v5). Copy and paste this into the Pine Editor on TradingView:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © blockplus
//@version=5
indicator("TVCBOT定时平仓", overlay=true)
h = input.int(00, "平仓小时", minval=0, maxval=23, step=1)
m = input.int(00, "平仓分钟", minval=0, maxval=59, step=1)
offset = input.int(8, "时区(默认UTC+8)", minval=-20, maxval=20)
// 注意时区,这里是 UTC+8 时间.
label1 = label.new(bar_index, low, text="当前时间 - " + str.tostring(hour+offset) + ":" + str.tostring(minute), style=label.style_label_up, color=color.white)
label.set_x(label1, bar_index)
label.delete(label1[1])
alertcondition(hour+offset==h and minute==m, title='定时平仓信号', message='定时平仓信号')

Key Features of the Script

After pasting the code:

  1. Click "Add to Chart"
  2. Use a 1-minute timeframe chart for maximum precision
  3. Adjust the hour, minute, and timezone offset to match your preferred closing time

Setting Up the Alert in TradingView

Once the script is active on your chart, you need to configure an alert to notify TVCBOT.

Steps to Create the Alert:

  1. Click the "Alert" button (bell icon) above the chart
  2. In the condition dropdown, select "TVCBOT定时平仓"
  3. Set the alert frequency to "Once Per Bar Close"
  4. Under "Alert Actions", ensure the message reads exactly: 定时平仓信号
  5. Paste your TVCBOT WebHook URL in the notification field
⚠️ Tip: Always test with a paper trading account first to confirm timing accuracy.

Connecting to TVCBOT for Execution

TVCBOT acts as the bridge between TradingView alerts and your exchange account. It receives the signal and executes a market-wide close on your behalf.

Setup Process:

  1. Log in to your TVCBOT dashboard
  2. Go to Account > Select Exchange & Trading Pair
  3. Choose Indicator > Market Close All
  4. Select your margin mode (isolated or cross)
  5. Generate the WebHook URL and copy it

Now return to TradingView and paste this URL into the alert’s notification field.

When the clock hits your designated time, TradingView fires the alert → TVCBOT receives it → All open positions are closed at market price.

👉 Learn how WebHook integrations can power your next automated strategy

Frequently Asked Questions (FAQ)

Q: Can I schedule multiple close times per day?

Yes. You can create multiple instances of the script or duplicate alerts with different times. Just ensure each alert triggers at unique HH:MM values.

Q: Does this work with both long and short positions?

Absolutely. The "Market Close All" command exits all open positions regardless of direction—ideal for daily resets or session-based trading.

Q: What happens if the market is closed when the alert triggers?

If no liquidity exists (e.g., futures contract expired), the order will fail silently. Always verify contract validity before scheduling.

Q: Is my API key secure with TVCBOT?

TVCBOT uses encrypted storage and read-only permissions for balance checks. However, always use API keys with minimal required permissions (avoid withdrawal rights).

Q: Can I backtest this strategy?

While Pine Script doesn’t support direct backtesting of time-based exits, you can simulate results by plotting exit times over historical data and reviewing hypothetical P&L manually.

Q: Will this work on weekends or holidays?

Yes—the script runs continuously as long as TradingView is loaded. However, ensure your exchange supports weekend trading for the selected pair.

Best Practices for Reliable Automation

To maximize reliability:

Automation should enhance—not replace—sound trading judgment.

👉 Explore advanced tools that bring your trading ideas to life

Final Thoughts

Scheduled position closing is a simple yet powerful technique that brings structure and safety to futures trading. By leveraging TradingView’s scripting flexibility and TVCBOT’s execution speed, you gain control over your exposure without constant monitoring.

Whether you're day trading BTC perpetuals or swing trading altcoin futures, automating exits ensures consistency—and gives you more time to focus on what really matters: refining your edge.

Start small, test thoroughly, and scale with confidence. The future of trading isn't just automated—it's intelligent, timely, and within your control.