Page 1 of 1

RTH trading

Posted: Thu Feb 16, 2023 6:15 pm
by elcounto
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.

Re: RTH trading

Posted: Mon Feb 20, 2023 4:43 am
by Steve Burman
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!