pooripro

MACD Higher TimeFrame

This Pine script is an indicator called "MACD Higher TimeFrame" that calculates and displays the Moving Average Convergence Divergence (MACD) on a higher timeframe. It is designed to be used on a lower timeframe chart but show the MACD values from a specified higher timeframe.

The indicator takes several inputs, including the fast length, slow length, source data, signal smoothing length, and the types of moving averages to be used for the MACD and signal lines. The default values are set to 12, 26, the closing price, 9, and exponential moving averages (EMA) for both lines, respectively. These inputs can be modified by the user.

The script calculates the MACD and signal lines based on the specified inputs and the source data. It uses the `init_ma` function to initialize the moving average calculation based on the selected moving average type (EMA or SMA) and length.

To display the MACD and signal lines from the higher timeframe, the script utilizes the `request.security` function, fetching the values of MACD and signal lines one bar ago on the higher timeframe. It handles any gaps in data and lookahead considerations.

The script also includes a function called `int_htf_fillna`, which handles the filling of `na` (not available) values for the higher timeframe indicators. It ensures that the indicator values are carried forward if they are not available for a particular bar.

To enhance the visualization, the script includes customizable colors for the MACD line, signal line, and histogram bars. The histogram bars are styled using the `plot.style_columns` option, and their color is determined by the `color_handle_ducplicate_value` function. This function checks for duplicate values and assigns colors based on whether the indicator is rising or falling, and whether it is above or below zero.

The script also includes a zero line (color #787B86) to provide a visual reference for the zero level.

Overall, this Pine script allows users to view the MACD indicator from a higher timeframe on a lower timeframe chart, providing insights into the broader market trend.
Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Отказ от ответственности

Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.

Хотите использовать этот скрипт на графике?