Reputation: 1
I’ve managed to pretty much write a whole strategy on TradingView with a time stamp that is able to filter out a range of dates for example 1st January 2023 to 17th January 2023 and backtest my strategy within these days.
I wanted to find out if there is a way to make this strategy even better by selecting a real time range. For example only trade between 08:30am and 13:00pm on the days within the date range.
This is probably really long winded for what I’m asking.
TL;DR How do I add a time range (HH:MM) to my strategy so backtested trades are within a certain time
I’ve searched online but can’t find anything apart from a day range, however, I’m looking for a time range within this day range.
Upvotes: 0
Views: 2207
Reputation: 21342
You are looking for a session
.
You can do it by getting a session
input from the user and checking if the current time is within that time window.
An example from the F.A.Q:
timeAllowed = input.session("1200-1500", "Allowed hours")
timeIsAllowed = time(timeframe.period, timeAllowed + ":1234567")
Then use timeIsAllowed
as your entry and/or your exit condition.
Upvotes: 0