The MTF functionality is a feature that allows you to change any indicator’s timeframe with just two clicks in Inputs, using the Resolution dropdown.
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 the indicator with a custom resolution setting can sometimes display ‘n/a’ instead of a numerical value. This behavior is expected. You can learn more about it in our Help Center.