I don't think so.
There is a function BarInterval, but I don't think you can put it as input and optimize it.
Here it is:
BarInterval (Reserved Word)
Disclaimer
Reserved word that returns the bar interval for the type of data that an analysis technique is applied to.
Remarks
BarInterval is only valid when used on intraday, volume, and tick data. Returns minutes for intraday time-based bars, shares/contracts for volume-based bars, or tick count for tick-based bars.
Examples
Condition1 = (BarInterval = 5)
is a statement that will cause Condition1 to be true if the analysis technique is applied to a 5-minute intraday chart..
CalcTime(Sess1StartTime, BarInterval)
will add the bar interval to the start time of the asset in an intraday time-based chart.
Additional Example
CalcTime(Sess1EndTime, -BarInterval) returns the time of the last bar before the close of the trading session for an intraday time-based chart.
I'm not sure. You may try it.