Feature to Return Current Timeframe

Provide a script function that provides the timeframe of the current chart. This feature will be very helpful and enable certain actions or features be triggered depending on the different timeframes.

The system currently has Security() that returns the security of the chart. I’m looking for something like Timeframe() that would return the timeframe accordingly.

As a background, the reason I’m requesting this feature because I’m writing a 3 MAs indicator that dynamically adjusts the periods based on 3 timeframes: current and 2 higher timeframes. It seems impossible to have write this indicator without knowing the current timeframe.

Thank you.

Hi Peter,

We can add the TimeFrame on the chart using a Chart Element tool but I can see no way to access that in the DataField() function. It looks like we are filtering that out in the scripting. We’ll have a look at that as it should not be a hard thing to remove that filter.

It will be part of the next major update early next year.

One thing you can do is look at the difference between the BarDates on the chart.

b1 = BARDATE(); 
diff = b1 - b1[1];
IsWeekly = if(diff > 5, True, False);
// Use 5 so that Easter with Good Friday and Easter Monday holidays (ok that is only in Australia) does not change it to weekly.

All the best

Mathew