0

I would like my indicator to exhibit different behavior based on the resolution of the chart to which it will be applied. Is there some function or variable which will give me the chart's resolution? I am familiar with the input.timeframe for allowing a user to select an indicator's timeframe different to the chart, but that is not relevant here.

//I want to do something like:
if Chart.Resolution == 1
    //do some stuff
else if Chart.Resolution == 1D
    //do some other stuff

I have tried using possible variable names like resolution, Resolution, chart.resolution, Chart.Resolution. I have checked the Pine Script v5 reference manual and found no variables or functions which will accomplish this for me.

1 Answer 1

0

First option:

  • timeframe.multiplier returns the multiplier of the resolution.
  • timeframe.isdaily returns true if current resolution is a daily resolution, false otherwise.
  • timeframe.isminutes returns true if current resolution is a minutes or hourly resolution, false otherwise.

You can use:

if timeframe.isminutes and timeframe.multiplier == 1
    //do stuff if 1 min 

else if timeframe.isdaily and timeframe.multiplier == 1
    // do stuff if 1 day

You can also use:

  • timeframe.ismonthly - returns true if on a monthly chart.
  • timeframe.isweekly - returns true if on a weekly chart.
  • timeframe.isseconds - returns true if on a seconds chart.

and also:

  • timeframe.isdwm - returns true if on a daily or weekly or monthly chart.
  • timeframe.isintraday -returns true if on a seconds or minutes or hourly chart.

Second option:

timeframe.period returns the current chart resolution as a string so you can use:

if timeframe.period == "1"
    //do some stuff
else if timeframe.period == "1D"
    //do some other stuff
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.