I want to set a variable, 'multiplier' based on the current timeframe view.
This:
multiplier = (interval == 5 and isintraday ?
1
: interval == 15 and isintraday ?
1
: interval == 30 and isintraday ?
1
: interval == 45 and isintraday ?
1
: interval == 60 and isintraday ?
2
: interval == 120 and isintraday ?
2
: interval == 180 and isintraday ?
2
: interval == 240 and isintraday ?
2
: period == "1D" ?
2
: period == "1W" ?
2
: period == "1M" ?
2
: "blah")
... works for everything, except returns "blah" even when I'm viewing a day, week, or month.
What am I doing wrong with the period() function? It seems to not think that the period is "1D" when I'm looking at the 1D chart.
Also, is this the only way I work out what timeframe is currently being viewed? Surely there's an easier way to determine the currency view?
Promoted
Response

Hi!
Please look at https://www.tradingview.com/studyscr...
In other words period returns "D" instead of "1D" and so on.
Thanks...

I'd really LOVE if TradingView can answer this.
How do I write the code which is:
"If the current view is 1 Day then set a certain variable to x" ?
I can get it to work for everything (see above) except 1D, 1W, and 1M 



Hi!
Please look at https://www.tradingview.com/studyscr...
In other words period returns "D" instead of "1D" and so on.
Thanks... 

I've read (very thoroughly all your documentation).
My question is, is this code correct:
multiplier = (interval == 5 and isintraday ?
1
: interval == 15 and isintraday ?
1
: interval == 30 and isintraday ?
1
: interval == 45 and isintraday ?
1
: interval == 60 and isintraday ?
2
: interval == 120 and isintraday ?
2
: interval == 180 and isintraday ?
2
: interval == 240 and isintraday ?
2
: period == "1D" ?
2
: period == "1W" ?
2
: period == "1M" ?
2
: "blah")
No, it's not. The problem in type of the last "blah" literal is string. But type of all other possible values is integer. This is not allowed  types of all branches of operator ?: must be the same (or convertible). So replace "blah" with... say 0 and it would be fine. Also, there should be an indent on the all lines except the first.
study("My Script")
multiplier = (interval == 5 and isintraday ?
1
: interval == 15 and isintraday ?
1
: interval == 30 and isintraday ?
1
: interval == 45 and isintraday ?
1
: interval == 60 and isintraday ?
2
: interval == 120 and isintraday ?
2
: interval == 180 and isintraday ?
2
: interval == 240 and isintraday ?
2
: period == "1D" ?
2
: period == "1W" ?
2
: period == "1M" ?
2
: 0)
plot(multiplier)



