Gooogle
Pine Script Master
Pine Script Master
Posts: 1
Joined: January 19th, 2023
Contact: TradingView Profile

Selecting of date range in strategy script

I've faced some problem with strategy scripts. This problem is selecting date range for testing, for example, I have BTCUSDT Binance chart since 2017 year, but I wanna see the results of indicator for last 3 years. Or select two dates and see the results ONLY between these dates. For some reason, I'm in coders less than a month so sorry for if it's a kinda silly question.

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

Re: Selecting of date range in strategy script

Gooogle that's not a silly question at all. You can use this code:

// Date range inputs
startTime = input.time(title="Start Filter", defval=timestamp("01 Sep 2022 04:30 +0000"), group="Time Filter", tooltip="Start date & time to begin searching for setups")
endTime = input.time(title="End Filter", defval=timestamp("31 Dec 2099 19:30 +0000"), group="Time Filter", tooltip="End date & time to stop searching for setups")

// Time filter
f_dateFilter = time >= startTime and time <= endTime

Then you can use the f_dateFilter as a boolean filter such as

if emaFilter and f_dateFilter
strategy.entry(id="Long",strategy.long)

I hope this helps

Return to “Pine Script Q&A”