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提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?