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.
Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?