elcounto
Pine Script Rookie
Pine Script Rookie
Posts: 8
Joined: February 5th, 2023

RTH trading

Hey,

Is there a youtube video that details how to only take trades during certain times of the day like the RTH session and not overnight?

Thanks.

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: RTH trading

Not that I have seen. You can do something like this:

// Get user input
session_overnight = input.session(title="Overnight. Session", defval="1800-0800")

// Check if the current bar falls within the given time session
isInSession(_sess) => not na(time(timeframe.period, _sess))

// You can check when it has started the overnight session
startedOvernight = isInSession(session_overnight ) and not isInSession(session_overnight )[1]

// You can check when it exits the overnight session
exitedOvernight = isInSession(session_overnight )[1] and not isInSession(session_overnight )

So you could stop trading if startedOvernight = true and start trading again if exitedOvernight is true or use different logic to do similar

I hope this helps!

Return to “Pine Script Q&A”