Multi-timeframe analysis (MTF) is a process in which traders can view the same ticker/indicator using a higher timeframe than the chart’s, for example, displaying a daily moving average on a one-hour chart in just two clicks. This is used by traders to situate the chart’s price action in context of the long-term trend.
TradingView has always been finely tuned to MTF, thanks to the support of custom chart intervals, multi-chart layout, and most importantly, the `security` function in Pine, which allows you to request data from other tickers or timeframes. In the Pine Public Library, you can find dozens of excellent examples of MTF scripts using `security`. You’ll even find a few of them at the end of this post.
With this most recent update, we’ve added MTF functionality to many of our built-in indicators. You can now change any indicator’s timeframe with just two clicks in Inputs, using the new “Resolution” dropdown. This offers traders many new possibilities.
Pine coders can use the same `resolution` parameter we use in our built-in indicators in their own scripts. By simply adding it to a script’s `study` declaration statement, coders now have an easy way to add MTF functionality to scripts and let users decide the timeframe they want the indicator to run on.
The `resolution` parameter’s default value can be any of the resolution strings corresponding to the values in the dropdown, with the empty string (“”) representing the chart’s resolution. Using the parameter will automatically add a “Resolution” input field to your script’s Inputs.
Let’s say, for example, that you want to use a chart with a resolution of 5m, but want it to show a Moving Average based on a resolution of 1D. Previously, you could do this by using the `security` function:
//@version=4 study(title="Moving Average", shorttitle="MA with security", overlay=true) len = input(9, minval=1, title="Length") src = input(close, title="Source") out = sma(src, len) res = input(title="Resolution", type=input.resolution, defval="1D") s1 = security(syminfo.tickerid, res, out, gaps=true) plot(s1, color=color.red)
Now, however, you’ll just need to add `resolution=”D”` to your `study` call, as shown below:
//@version=4 study(title="Moving Average", shorttitle="MA with resolution", overlay=true, resolution="D") len = input(9, minval=1, title="Length") src = input(close, title="Source") offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500) out = sma(src, len) plot(out, color=color.blue, title="MA", offset=offset)
The new `resolution` parameter provides an easy way to add MTF functionality to relatively simple scripts. More complex Pine scripts will still need `security` to implement advanced calculations using higher timeframe information.
Please note that you need to reapply the indicator in order for the `resolution` parameter to appear.
Examples of MTF scripts from the Public Library:
We hope this update and these sources have been useful for you. Please continue sending in your comments, feedback, and requests. We love hearing from you and are eager to build for our online community.
TradingView Pine Team