'How to get the chart's resolution while using MTF

With the support of multi-timeframe (MTF) functionality:

the value of timeframe.* variables will represent the resolution the script is currently running on as determined by the value of the Timeframe field in the script's Inputs, regardless of the chart's resolution.

So how to get the chart's resolution now that it's different from the script resolution? Or how to know whether they are different?



Solution 1:[1]

timeframe.period returns your chart's resolution.

//@version=5
indicator("My script", overlay=true)

in_htf = input.timeframe("", "Timeframe")

curr_tf = timeframe.period

var testTable = table.new(position = position.top_right, columns = 1, rows = 1, bgcolor = color.yellow, border_width = 1)
if barstate.islast
    s = (in_htf == curr_tf) or (in_htf == "") ? "True" : "False"
    table.cell(table_id = testTable, column = 0, row = 0, text = s)

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vitruvius