Page 1 of 1

how to use timeframe.period

Posted: Fri Oct 06, 2023 2:53 pm
by crazynou
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.

Re: how to use timeframe.period

Posted: Tue Oct 17, 2023 3:21 am
by Steve Burman
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.