Skip to content

Free MT5 Expert Advisor

Session Close EA

MT5 utility that closes positions and deletes pending orders at a set daily time and before the weekend, with an optional Friday cutoff.

Utilityv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Non-repainting signals Stop-loss on every trade
Strategy
Does not open trades. At the set daily time and at the Friday cutoff, it closes the selected positions and deletes pending orders.
Risk model
Opens no trades; removes overnight and weekend exposure on a schedule

What it does

Session Close EA flattens your positions on a schedule. Use it to avoid holding trades over the weekend, to make sure intraday trades are closed before the daily rollover, or simply to enforce a personal rule about when trading stops. It shows the schedule and its status on the chart and never opens a trade.

How it works

The EA checks the estimated server time every five seconds and on every tick:

  • Daily close (optional): from the set time, Monday to Friday, it closes matching positions and deletes matching pending orders, and keeps doing so for the "keep closing" period, so positions opened just after the cutoff are caught too.
  • Friday cutoff (on by default): from 20:00 server time on Friday, the same actions run. With "block rest of Friday" on, they continue until the end of Friday, so no trade is carried into the weekend.

Positions are looped from last to first and closed by ticket; each failure is printed with the broker's reply and retried on the next check, at most every five seconds. Filters choose the symbols (chart only or all) and the positions (all, manual only, one magic number, or manual plus one magic number).

How to use it

Attach it to any chart; one instance with "All symbols" covers the account. Set times in server time, which is the time shown in Market Watch. Many forex brokers stop quoting some instruments earlier than others on Friday, so choose a cutoff comfortably before the earliest close of anything you trade. Our Forex Market Hours tool helps you compare sessions.

Settings

InputDefaultWhat it changes
Use daily closefalseTurns the daily close on
Daily close time22:45Server time for the daily close
Use Friday cutofftrueTurns the weekend close on
Friday cutoff time20:00Server time on Friday
Block rest of FridaytrueKeeps Friday flat after the cutoff
Keep closing (minutes)30Length of each closing window
Close positionstrueCloses positions
Delete pending orderstrueRemoves pending orders
Show statustrueChart status text
Symbols / PositionsAll / AllScope

Limitations

The EA only acts while the terminal is running and connected. If a market is already closed at your cutoff, the close fails and the position stays open until trading resumes. Closing at a fixed time ignores where price is, so it can exit a trade at a poor moment. Spreads are often wider near the daily rollover, which raises the cost of closing then.

Before you run it live

Run it on a demo account through at least one Friday and check the log. Compare your broker's trading hours for each symbol with the cutoff you choose. Read about swap costs if you are deciding whether to hold positions overnight. Trading carries a substantial risk of loss.

Key inputs

Key inputs of Session Close EA
InputDefaultDescription
Daily closeoff, 22:45Closes every trading day at this server time.
Friday cutoffon, 20:00Closes before the weekend at this server time on Friday.
Block rest of FridaytrueKeeps closing new positions until Friday ends.
Keep closing (minutes)30How long after a cutoff the EA keeps closing positions.
Delete pending orderstrueAlso removes matching pending orders.
Symbols to manageAll symbolsWhich positions and orders are affected.

Educational tools, not advice. Automated trading can lose money quickly. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 expert advisors