'Get Value of MACD on different TimeFrame

How can you get the value of the Macd Line and Signal Line real-time from different timeframe. Like for example I am on a 4HR chart and I want to get the value of the Macd Line and Signal Line from the 1 hr timeframe.

I know how to get the value of the two lines it is just that I cannot solve or find the value from the other timeframe. [macdLine, signalLine, histLine] = macd(close, 12, 26, 9)



Solution 1:[1]

You can use security function to access higher timeframe data, but trying to access lower than your chart's timeframes will lead to unreliable results, as TV doesn't support intrabar data.

You can also include tuple in the security function calls

Daily MACD, signal and histogram data from the Daily chart.

[macdLineD, signalLineD, histLineD] = security(syminfo.tickerid, "D", [macdLine, signalLine, histLine])

Security function could lead to repainting, check this article how to avoid the issue - https://www.tradingview.com/script/cyPWY96u-How-to-avoid-repainting-when-using-security-PineCoders-FAQ/

non-repainting version use the previous resolution value with lookahead argument set to true:

[macdLineD, signalLineD, histLineD] = security(syminfo.tickerid, "D", [macdLine[1], signalLine[1], histLine[1]], lookahead = true)

Solution 2:[2]

With security Functions. security(syminfo.tickerid,"{Your timeframe},

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 e2e4
Solution 2 hgmahan