How to Set Up Automatic Contract Position Closing with TVCBOT and TradingView While You Sleep

·

Automated trading strategies are transforming the way traders manage risk and optimize their time. One powerful use case is setting up scheduled position closing using TradingView and TVCBOT, allowing you to automatically close open futures or contract positions at a specific time—whether you're asleep, at work, or simply away from your screen.

This guide walks you through how to implement a time-based auto-close script using Pine Script on TradingView, integrated with TVCBOT via WebHook alerts. By the end, you'll have a fully functioning system that sends a market-wide close signal at your chosen hour and minute—every day.


Why Automate Position Closing?

Manual trading comes with limitations—especially when it comes to timing. If you're holding leveraged positions overnight or during volatile periods, unexpected price swings can erode profits or increase losses while you're offline.

By automating your exit strategy:

👉 Discover how automated trading tools can help secure your profits around the clock.


Core Components of the System

To set up scheduled position closing, you need three key elements:

  1. TradingView Account – To run the Pine Script indicator and trigger alerts.
  2. TVCBOT Integration – A bot platform that executes trading actions based on alert signals.
  3. Pine Script Code – Custom logic that checks for a specific time and triggers an alert.

The following solution uses UTC+8 time zone as default but allows adjustment for global users.


Step-by-Step: Setting Up the Auto-Close Script

1. Add the Pine Script Indicator to TradingView

Copy and paste the code below into the Pine Editor in TradingView. Save it as TVCBOT Scheduled Close.

// 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 Scheduled Close", overlay=true)
h = input.int(00, "Close Hour", minval=0, maxval=23, step=1)
m = input.int(00, "Close Minute", minval=0, maxval=59, step=1)
offset = input.int(8, "Time Zone (Default UTC+8)", minval=-20, maxval=20)

label1 = label.new(bar_index, low, text="Current Time - " + 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='Scheduled Close Signal', message='Scheduled Close Signal')
🔍 Note: The script displays real-time clock on your chart (adjusted by UTC offset) and triggers an alert only when both the hour and minute match your input.

2. Configure Your Desired Closing Time

After saving and adding the script to a chart (use 1-minute timeframe for precision), click the gear icon (Settings) on the indicator.

Set the following:

This flexibility ensures accurate timing regardless of your location.


3. Create a TradingView Alert

Click the "Alert" button below the chart or go to the Alerts section in TradingView.

Configure the alert:

👉 Learn how real-time alerts can enhance your trading discipline and execution speed.


4. Connect Alert to TVCBOT via WebHook

In TVCBOT:

  1. Go to Account Settings
  2. Select your connected exchange (e.g., Binance, Bybit, OKX)
  3. Choose the trading pair(s) you want this rule to apply to
  4. Under Indicator, select Market Close All
  5. Set margin mode (Isolated/Cross) as needed
  6. Click Generate WebHook URL

Now return to the TradingView alert settings:

You’ll now see the alert listed in your TradingView alerts dashboard.


How It Works: Behind the Scenes

Every minute, the Pine Script runs and compares the current time (adjusted for your offset) with your target close time.

When hour + offset == h and minute == m, TradingView fires an alert containing the message close_all_market. This message travels via HTTPS POST request to TVCBOT’s server through the WebHook URL.

TVCBOT receives the signal and immediately issues a market order to close all open positions on your linked account for the specified trading pair(s).

✅ Result: Full automation without manual intervention.


Frequently Asked Questions (FAQ)

Q1: Can I schedule multiple close times per day?

Yes. You can duplicate the indicator on the same chart and set different hours/minutes for each instance. Then create separate alerts for each one—ideal for closing partial positions at different times.

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

Absolutely. The close_all_market command closes all open long and short contract positions regardless of direction.

Q3: Is my account safe using WebHook integration?

Yes—WebHooks are one-way signals that tell TVCBOT what action to take, but they don’t grant access to your funds or private keys. Always keep API keys restricted to necessary permissions only.

Q4: What happens if TradingView misses the alert?

On rare occasions due to connectivity issues, alerts may be delayed. To minimize risk:

Q5: Can I customize the close signal for specific pairs only?

Yes. In TVCBOT, assign the WebHook to a specific trading pair or group. That way, only those markets will be affected when the alert fires.

Q6: Do I need a paid TradingView plan?

Free accounts support basic alerts, but for reliable timing and multiple active alerts, a Pro or higher plan is recommended to avoid delays or throttling.


Best Practices for Reliable Automation

👉 See how top traders automate their strategies with precision tools like these.


Final Thoughts

Setting up automatic contract position closing using TradingView and TVCBOT gives you peace of mind and tighter control over your trading lifecycle. Whether you're managing risk across multiple positions or simply want to avoid overnight exposure, this system delivers consistent, hands-free execution.

With just a few minutes of setup, you can ensure your portfolio adheres to your strategy—even while you sleep.

By integrating core keywords like automatic position closing, TradingView Pine Script, TVCBOT WebHook, scheduled trade exit, crypto futures automation, time-based trading bot, and risk management automation, this guide aligns with top search intents while delivering actionable value.

Start building smarter exit rules today—and let automation do the work for you.