7

I want to write an indicator for tradingview that should draw a vertical line on a specific level depending on the active time frame, e.g. on the 5-minute-chart the indicator should draw the line at a different level than on the 60-minute-chart.

I have allready tried "resolution". Here is a snippet of the code:

x = (resolution == "5") ? 10 : (resolution == "60") ? 20 : 30

plot(x)

So this should draw a line at level 10, if the chart is on the 5-minute-time-frame, at level 20 on the 60-minute-time-frame and at level 30 for all other time frames.

But it allways draws at level 30, so the code has to be incorrect. I allready researched that "resolution" is a constant of the "input"-function, so it seems that it cannot be used outside of this function.

So my question is: What is the right code? Thank you!

a kind person
  • 329
  • 1
  • 6
  • 17

2 Answers2

8

For Pine Script v4 the variable you are looking for is called timeframe.period.

E.g. '60' - 60 minutes, 'D' - daily, 'W' - weekly, 'M' - monthly, '5D' - 5 days, '12M' - one year, '3M' - one quarter

Pine reference

Diego Ferri
  • 2,657
  • 2
  • 27
  • 35
4

I have found the answer myself: "period"

So my example code has to look like this:

x = (period == '5') ? 10 : (period == '60') ? 20 : 30

plot(x)
a kind person
  • 329
  • 1
  • 6
  • 17