How to Only Trade TradingView Alerts During Set Hours on MT5

Last updated · By the TradingView Link team
Short answer

Add s= with a time window to the order line, such as long EURUSD q=0.1 s=09:00-17:00. The EA opens the trade only if your broker's server clock is inside that window, and skips the alert otherwise. Add a day number for single days, and r= to trade only inside a price range.

How do you limit TradingView alerts to trading hours?

TradingView fires an alert whenever its condition is met, at any hour the market moves. A strategy built for the London or New York session can then trade in the thin hours around them. With TradingView Link, you add s= to the order line, and the EA checks the clock before it opens the trade:

YourWebhookPassword
long EURUSD q=0.1 s=09:00-17:00

The first line is your webhook password, and the webhook guide has the full message format. The window is written as hours and minutes, 24-hour, with a colon: 09:00-17:00. Both ends count, so this one accepts alerts up to 17:00:59. Write 16:59 as the end to stop before 17:00.

For several windows a day, separate them with commas, with no spaces:

YourWebhookPassword
long EURUSD q=0.1 s=08:00-11:00,14:00-17:00

The message is split into words at spaces, so a space inside the value cuts it short. The table shows the forms the EA reads:

Session filter values and what they allow
ValueTrades allowed
s=09:00-17:00 Every day, 09:00 to 17:00 server time
s=08:00-11:00,14:00-17:00 Two windows a day, with a break from 11:01 to 13:59
s=5=09:00-15:00 Fridays only, 09:00 to 15:00
s=1=09:00-17:00,2=09:00-17:00 Mondays and Tuesdays, 09:00 to 17:00
s=22:00-02:00 Every night from 22:00 to 02:00, across midnight
s=1-5=09:00-17:00 Mondays only: a day range is read as its first day

Which time zone does s= use?

Your broker's server time. The EA reads MetaTrader's TimeCurrent(), which the MQL5 docs say "Returns the last known server time", and "The time value is formed on a trade server and does not depend on the time settings on your computer". It's the clock in the title of the Market Watch window, which the same page calls "the time shown in the title of this window".

That clock is often hours away from yours and from the exchange's. To filter for the US stock open at 09:30 New York time on a server that runs 7 hours ahead of New York, write s=16:30-23:00. Check the gap on your own terminal: compare the Market Watch time with the time in New York or London at that moment.

Watch the clock changes. Some places keep the same offset all year, and the Pine Script docs note that others have "an offset that changes over time due to daylight saving time (DST) and other factors". The US and Europe change on different dates in March and in October and November, so if your broker's server follows one and the market you trade follows the other, the gap shifts by an hour for a few weeks. Check the window again after each change.

How do you filter by day of the week?

Put a day number and an equals sign before the window. Days run from 1 for Monday to 7 for Sunday, by the server's calendar, so s=5=09:00-15:00 allows trades on Fridays only. For several days, give each its own window, separated by commas. This alert trades the US cash session on weekdays, on the server from the example above:

YourWebhookPassword
long NAS100 q=0.1 s=1=16:30-23:00,2=16:30-23:00,3=16:30-23:00,4=16:30-23:00,5=16:30-23:00

The EA has no day ranges. In s=1-5=09:00-17:00 it reads the day as 1, so that filter allows Mondays only. Windows without a day number apply every day, and you can mix the two in one value.

How do you set a session that crosses midnight?

Write the later time first. s=22:00-02:00 allows trades from 22:00 to 23:59 and from 00:00 to 02:00 every day, which suits the Asian session on many servers.

With a day number, the whole window belongs to that calendar day. s=5=22:00-02:00 allows Friday from 00:00 to 02:00 and Friday from 22:00 to midnight, not the early hours of Saturday. To cover Friday night, split it at midnight:

YourWebhookPassword
long XAUUSD q=0.1 s=5=22:00-23:59,6=00:00-02:00

Does s= block closing trades?

It depends on the platform. The MT5 EA applies s= to long and short lines only, so a flat, cancel or modify line still runs at any hour. The MT4 EA checks it on every line that carries it. On MT4, an exit with s= sent after the session ends is skipped, and the trade stays open.

So put s= on entry lines only, and send exits without it on both platforms:

YourWebhookPassword
flat EURUSD

Reversals need care too. An entry closes opposite trades on the symbol before it opens, but the EA checks the session first. If a long arrives outside the session, nothing happens: the short stays open. If the short must close at any hour, send a flat line without s= before the entry, as the close guide explains. To close everything at the end of a session, send a flat alert at that time. The filter only blocks new trades. It never closes open ones.

How do you only trade inside a price range?

Add r= with a low and a high price, separated by a dash. The EA opens a long only if the ask is inside the range, and a short only if the bid is. Both ends count, and if you write the high first, the EA swaps them:

YourWebhookPassword
long EURUSD q=0.1 r=1.0700-1.0900

Both EAs apply r= to long and short lines only, so exits are never blocked. On a limit or stop order, the range tests the current price when the alert arrives, not the order's price. Our limit and stop order guide covers p=.

Write both prices with digits and a decimal point. If the EA can't read the range, the two platforms differ: MT5 treats it as out of range and skips every order, while MT4 ignores the filter and trades. A test on a demo account shows which you have.

s= and r= work together. Both must pass:

YourWebhookPassword
short XAUUSD q=0.1 s=09:00-17:00 r=2300.0-2500.0

Should you filter in Pine Script or in the alert?

If you can edit the script, a filter in Pine Script keeps the backtest honest, because TradingView tests the same hours it trades. Pine uses session strings with time(), which returns a timestamp for the bar, "or na if the bar is not in the specified session":

inSession = not na(time(timeframe.period, "0830-1700:23456"))
if longSignal and inSession
    alert("YourWebhookPassword\nlong EURUSD q=0.1", alert.freq_once_per_bar_close)

The two filters read time differently. Pine's time() uses "the time zone of the exchange by default, unless a timezone argument is specified", and its day numbers start from Sunday, so its 23456 means Monday to Friday. The EA uses server time and starts from Monday:

Pine Script session strings compared with s=
PointPine Scripts= in the alert
Time zone The exchange's, unless you pass a time zone Your broker's server time
Format 0930-1600 09:30-16:00
Day 1 Sunday Monday
Backtests Filtered too Not seen by TradingView
Needs the script code Yes No

The Pine docs also advise you to "align the start and end times of time-based sessions with the start and end times of chart bars at the expected timeframe". Use s= when you can't edit the script, such as a published indicator, or as a second check on the account. Our indicator alerts guide shows how to automate one.

What happens to an alert outside the session?

The EA skips the line and reports it back. Outside the window you get Out of session, error 10005, and outside the price range Out of range, error 10006. Both show on the error message in your Telegram chat and on the dashboard's log page, and the EA prints the filter value in MetaTrader's Experts tab.

A skipped alert isn't kept for later. If the session opens five minutes after it arrived, the trade still doesn't happen, so the next trade waits for the next signal. The EA checks the filters before MaxTradePerSymbol and pyramiding, so a skipped line uses up none of those limits.

If every alert comes back Out of session, check the server time against your window, a day range, and an overnight window with a day number. Our troubleshooting guide lists the other EA messages.

Test a session filter on a demo account
Connect TradingView to MT4 or MT5 and send one alert inside your window and one outside it. 5 free alerts a month, no credit card.

Frequently asked questions

Does s= use my local time or the broker time?

The broker's server time, the clock MetaTrader shows in the Market Watch title. Your computer's time zone and TradingView's chart time zone make no difference.

How do I trade weekdays only?

List each day with its own window, from 1 for Monday to 5 for Friday, separated by commas. A range such as 1-5= is read as Monday alone.

What happens to an alert that arrives outside the session?

The EA skips it and reports Out of session, error 10005, to your Telegram and the dashboard log. It is not queued, so it never trades later.

Will a session filter stop my exits?

On MT5 it only blocks long and short lines. On MT4 it blocks every line that carries it, including flat, cancel and modify, so leave s= off exit alerts.

Can I use s= and r= together?

Yes. Put both on the same line, and the order is placed only if the time is inside the session and the price is inside the range.

Does the session filter work on MT4?

Yes. The MT4 EA reads the same s= and r= values with the same day numbers and server time. It differs in which lines it blocks and in how it treats a broken range.

Sources

All checked November 2026. How s= and r= read times, days and prices, and which lines they block, comes from our own MT4 and MT5 EA code.

Related guides