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:
- You eliminate emotional decision-making.
- You enforce strict risk management rules.
- You protect gains by closing positions before high-impact news or market reversals.
- You free up mental bandwidth, knowing your trades follow a disciplined plan.
👉 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:
- TradingView Account – To run the Pine Script indicator and trigger alerts.
- TVCBOT Integration – A bot platform that executes trading actions based on alert signals.
- 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:
- Close Hour: Choose the hour (0–23) you want to close all positions.
- Close Minute: Select the exact minute (0–59).
Time Zone Offset: Adjust if you’re not in UTC+8. For example:
- New York (EST): UTC-5 → enter
-5 - London (GMT): UTC+0 → enter
0
- New York (EST): UTC-5 → enter
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:
- Condition:
TVCBOT Scheduled Closeindicator - Trigger:
Scheduled Close Signal - Message Field: Enter exactly:
close_all_market
(This must match what TVCBOT expects for full position liquidation)
👉 Learn how real-time alerts can enhance your trading discipline and execution speed.
4. Connect Alert to TVCBOT via WebHook
In TVCBOT:
- Go to Account Settings
- Select your connected exchange (e.g., Binance, Bybit, OKX)
- Choose the trading pair(s) you want this rule to apply to
- Under Indicator, select Market Close All
- Set margin mode (Isolated/Cross) as needed
- Click Generate WebHook URL
Now return to the TradingView alert settings:
- Paste the generated WebHook URL into the "Send Notification To" field
- Ensure the message format matches TVCBOT’s expected command (
close_all_market) - Click Create
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:
- Use a stable internet connection.
- Test the alert once manually before relying on it live.
- Consider setting a small buffer window (e.g., close 5 minutes earlier than needed).
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
- 🔄 Test First: Run a paper trade or small position test to confirm the signal closes correctly.
- ⏰ Double-check Time Zone: A wrong offset can cause early or missed execution.
- 📱 Enable Notifications: Turn on email/push alerts in TradingView so you’re notified when a close event occurs.
- 🧹 Clean Up Old Alerts: Delete unused alerts to avoid confusion or accidental triggers.
- 🔐 Secure API Keys: Use dedicated keys with withdrawal disabled and IP whitelisting where possible.
👉 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.