Get Value of MACD on different TimeFrame

3.5k views Asked by At

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)

2

There are 2 answers

0
e2e4 On BEST ANSWER

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 in Pine Script version < 5, as TV doesn't support intrabar data there. In Pine Script V5, an additional request.security_lower_tf() function was added to handle this case.

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)
0
hgmahan On

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