Alerts & Webhooks

How to Send a Pre-Close Alert to Flatten Positions on TradingView

A new script for TradingView allows users to send pre-close alerts and flatten positions before the session ends. With granular control and multi-time frame functionality, this tool simplifies intraday position management.

Tom Hartman

Marketing

2 Min Read Reviewed by Mike Christensen Fact-checked by Mike Christensen
BluSky — The Future of Trading. Prop firm futures trading. Sign up at BluSky.pro.
Update history
  1. Traders ask how strategy exits fill, so the post now notes that strategy.close_all() fills on the next available tick, by default the next bar's open.

Many TradersPost users ask how to send an alert on TradingView to automatically flatten positions before the session ends. This functionality can be useful for day traders or those managing risk who want to exit their positions before the market closes.

Pre-Close Alert Script

A new script has been developed for this exact purpose. The script allows you to send an alert at the start or just before the end of the trading session. You can customize the session time and even the time zone in the script’s settings. This feature leverages a new time method in Pine Script that allows users to look up to 500 bars into the future, which helps determine the end of the session and trigger alerts accordingly. If you flatten from a Pine Script strategy instead, strategy.close_all() sends a market order that the broker emulator fills on the next available tick, which by default is the open of the following bar1. Order fill alerts fire on that fill, so calling it on the session’s last bar sends the alert only when the next session opens.

Granular Control

The script also allows granular control over when the alert is fired. For example, if you’re trading on a 15-minute chart but don’t want to close your positions exactly at 3:45 p.m., you can configure the alert to fire at a specific point within the last candle of the session. This is done by breaking down the candle into smaller intervals (seconds or sub-timeframe bars). This flexibility allows traders to fine-tune exactly when they want the system to send the signal to flatten positions.

Multi-Time Frame Alerts

For those using daily strategies, you can set up alerts on lower time frames, such as the one-minute or five-minute chart, while still running your strategy on a daily chart. This method allows the alert to fire at the right time without affecting the main analysis performed on the higher time frame. This flexibility can be especially useful for those who want to manage intraday exit strategies while maintaining a broader daily view.

Conclusion

This new alert script, available in the TradersPost library, simplifies the process of flattening positions before the market closes. It can be customized for different time frames and provides granular control over when the alerts are fired, offering traders more flexibility in managing their positions.

References

1 tradingview.com, Concepts / Strategies

  • Alerts & Webhooks Sep 18, 2026

    TradingView Broker Integration Explained

    How TradingView's Broker Integration API connects brokers to the platform, what data and trading endpoints require, and how webhook automation fits in.

  • Alerts & Webhooks Sep 16, 2026

    TradingView Webhook Alerts Documentation Explained

    What TradingView's official webhook documentation actually specifies: account requirements, payload rules, delivery limits, and where the docs stop.

  • Alerts & Webhooks Sep 16, 2026

    Automating a TradingView Remix Strategy

    Remix writes plain Pine Script that can fire webhook alerts. Here is the verified path from a Remix-generated strategy to a live broker order.

  • Video
    Alerts & Webhooks Jul 10, 2026

    Event-Driven TradingView Alerts for Automation

    Learn to build event-driven TradingView alerts, send webhooks to TradersPost, and paper trade automated buy, sell, exit, and reverse orders safely today.

Ready to put what you read into practice?

Free 7-day trial

Set-up in 3 minutes

Paper account for testing

By continuing, you agree to the TradersPost Terms of Service and Privacy Policy. This site is protected by reCAPTCHA.