crazynou
Pine Script Rookie
Pine Script Rookie
Posts: 4
Joined: October 3rd, 2023

how to use timeframe.period

Hello pinescripters,

i have this

TF = input.timeframe(defval = '15', title = "Time Frame")

i want the TF defval change automaticly when i change the time frame

exmpl with timeframe.period :

if timeframe.period == "60"
TF := 15

thank you.

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

Re: how to use timeframe.period

You can do something like this:

float TF = switch timeframe.period
"5" => 1
"60" => 15
"D" => 60
=> 30 // this is the default if none of the above options are a match

or whatever values you like. It compares timeframe.period to the 3 options (or as many as you want) "5", "60" and "D" and whichever one is a match it uses the value after the => sign but make sure you have listed all of the values you want to include or the default will be used.

Return to “Pine Script Q&A”