Page 1 of 1

Selecting of date range in strategy script

Posted: Thu Jan 19, 2023 6:11 pm
by Gooogle
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.

Re: Selecting of date range in strategy script

Posted: Thu Jan 19, 2023 11:37 pm
by Steve Burman
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