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

Fact checked by
Mike Christensen, CFOA
September 2, 2024
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.

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.

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.

Ready to automate your trading? Try a free 7-day account:
Try it for free ->