This Pine Script is designed for the TradingView platform to create a multi-timeframe MACD (Moving Average Convergence Divergence), Signal, and Histogram table that displays values across different timeframes. The script leverages the MACD indicator to analyze market trends and presents the results in a structured table format on the chart.
Key Features
1. Customizable Timeframes
Users can input five distinct timeframes (e.g., 5 minutes, 15 minutes, 1 hour, 4 hours, daily) via input.string for flexible analysis.
2. Adjustable MACD Settings
- Short-Term MA Length (
macdShortLength): Default 12. - Long-Term MA Length (
macdLongLength): Default 26. - Signal Line Length (
macdSignalLength): Default 9 (EMA of MACD line).
3. MACD Calculation Function (calc_macd)
- MACD Line: Difference between fast and slow EMAs.
- Signal Line: EMA of the MACD line.
- Histogram: Difference between MACD and Signal lines.
4. Multi-Timeframe Data Retrieval
The script uses request.security to fetch MACD, Signal, and Histogram values for each selected timeframe (tf1 to tf5).
5. Dynamic Color Coding
Values in the table are color-coded based on positivity/negativity:
- Green: Positive values (≥0).
- Red: Negative values (<0).
6. Rounded Values for Readability
A helper function (roundDecimal) rounds all values to two decimal places.
7. Table Population Logic
- Each timeframe’s data populates rows 1–5.
- Columns display: Timeframe Label, MACD, Signal, Histogram.
How It Works
- User Inputs: Define timeframes and MACD parameters.
- Data Calculation: Compute MACD, Signal, and Histogram for each timeframe.
- Table Generation: Dynamically update the table with color-coded values.
FAQs
Q1: Can I add more than five timeframes?
A: No, the script is designed for five timeframes to maintain clarity. Modify the source code to expand this limit.
Q2: How often does the table update?
A: The table refreshes with each new bar (e.g., every candle close).
Q3: Why are values rounded to two decimals?
A: Rounding improves readability without sacrificing analytical precision.
👉 Explore advanced MACD strategies
Q4: Is this script free to use?
A: Yes, it’s open-source under TradingView’s House Rules.
Q5: How do I interpret negative Histogram values?
A: Negative values suggest bearish momentum; positive values indicate bullish momentum.
Benefits
- Multi-Timeframe Analysis: Spot trends across different intervals at a glance.
- Visual Clarity: Color-coded cells highlight momentum shifts.
- Customizable: Adapt timeframes and MACD settings to your strategy.
👉 Master MACD trading techniques
Disclaimer
This script is for educational purposes only. TradingView does not endorse financial advice. Always conduct independent research.