OPEN-SOURCE SCRIPT
Fanfans-macd multi

# 指标功能总结(Function Summary)
## 中文功能总结
该指标是一款基于双MACD系统的多状态趋势分析工具,核心功能围绕“多空状态识别+可视化跟踪”设计,具体包括:
1. **双MACD计算体系**:同步运行两套MACD指标——MACD1(参数12,26,9,常规短周期)与MACD2(参数48,96,35,长周期),分别捕捉短期和中长期动量信号;
2. **精细化趋势判断**:通过“趋势周期(默认5根K线)+涨跌阈值(默认3次)”,统计MACD在周期内的涨跌次数,判断每套MACD是否处于“0轴上上升/下降”“0轴下上升/下降”4种基础状态;
3. **16种多空组合状态**:将两套MACD的4种基础状态交叉组合,形成16种多空强度状态(如“状态1:多头最强”“状态16:空头最强”),每种状态对应独立可自定义的颜色;
4. **多维可视化呈现**:① K线按当前组合状态染色,直观区分多空氛围;② 右上角表格显示当前及前8根K线的MACD1/MACD2状态、组合状态历史,便于回溯趋势变化;③ 标记MACD2的金叉、死叉、上穿0轴、下穿0轴4类关键信号,提示动量转折;
5. **参数可调节性**:支持自定义趋势周期、涨跌阈值、16种状态颜色、信号标记大小及颜色,适配不同品种(股票/期货/加密货币)和时间周期。
## English Function Summary
This indicator is a multi-state trend analysis tool based on a dual-MACD system, with core functions designed around "long-short state identification + visual tracking", including:
1. **Dual-MACD Calculation System**:Runs two sets of MACD indicators simultaneously — MACD1 (parameters 12,26,9, regular short-cycle) and MACD2 (parameters 48,96,35, long-cycle) — to capture short-term and medium-to-long-term momentum signals respectively;
2. **Refined Trend Judgment**:Through "trend length (default 5 bars) + up/down threshold (default 3 times)", count the number of ups and downs of MACD within the cycle to determine whether each MACD is in 4 basic states: "above 0-axis rising/falling" and "below 0-axis rising/falling";
3. **16 Long-Short Combined States**:Cross-combine the 4 basic states of the two MACDs to form 16 long-short intensity states (e.g., "State 1: Strongest Long", "State 16: Strongest Short"), each with an independently customizable color;
4. **Multi-dimensional Visualization**:① Candles are colored according to the current combined state for intuitive distinction of long-short sentiment; ② A table at the top-right shows the MACD1/MACD2 states and combined state history of the current and previous 8 bars, facilitating trend change review; ③ Marks 4 key signals of MACD2 (golden cross, death cross, cross above 0-axis, cross below 0-axis) to indicate momentum turning points;
5. **Adjustable Parameters**:Supports customization of trend length, up/down thresholds, colors of 16 states, signal marker size and colors, adapting to different varieties (stocks/futures/cryptocurrencies) and timeframes.
# 指标使用方法(Usage Guide)
## 中文使用方法
1. **核心信息读取:看表格与K线颜色**
- 右上角表格:首行是“MACD1状态/MACD2状态/组合状态”标题,下方行显示历史数据(第1行是当前K线,背景浅蓝色标注);其中“0轴上↑”代表MACD在0轴上方且呈上升趋势,“0轴下↓”代表MACD在0轴下方且呈下降趋势,结合“组合状态”文字可快速判断当前多空强度(如“状态1:多头最强”适合观望或持仓多头,“状态16:空头最强”适合观望或持仓空头);
- K线颜色:不同颜色对应16种状态(可在参数面板查看颜色与状态的对应关系),绿色系通常代表多头状态,红色系代表空头状态,颜色越深强度越高,通过K线颜色变化可快速跟踪多空力量转换。
2. **关键信号捕捉:看形态标记**
- 下方绿色“金叉”标记:MACD2出现快线交叉慢线的金叉信号,提示中长期多头动量启动,可结合当前组合状态(如绿色系多头状态)进一步确认;
- 上方红色“死叉”标记:MACD2出现快线交叉慢线的死叉信号,提示中长期空头动量启动,需结合当前组合状态(如红色系空头状态)警惕趋势反转;
- 蓝色三角形(下)/紫色三角形(上):分别代表MACD2上穿0轴(多头趋势强化)、下穿0轴(空头趋势强化),是趋势方向确认的辅助信号。
3. **参数调整技巧**
- 趋势周期/阈值:波动大的品种(如加密货币)可将“趋势判断周期”调至7-10,“上升/下降阈值”调至4,避免频繁切换状态;波动小的品种(如蓝筹股)可保持默认参数(周期5、阈值3);
- 状态颜色:建议将多头状态设为不同深浅的绿色,空头状态设为不同深浅的红色,便于视觉区分;
- 信号标记:若觉得标记杂乱,可在参数面板调小“信号标记大小”,或调整标记颜色使其与K线颜色区分开。
## English Usage Guide
1. **Core Information Reading: Check the Table and Candle Color**
- Top-right table: The first row is the header "MACD1 State/MACD2 State/Combined State", and the rows below show historical data (the first row is the current bar, marked with a light blue background); "Above 0↑" means MACD is above the 0-axis and in an upward trend, "Below 0↓" means MACD is below the 0-axis and in a downward trend. Combining the "Combined State" text, you can quickly judge the current long-short intensity (e.g., "State 1: Strongest Long" is suitable for holding long positions or waiting, "State 16: Strongest Short" is suitable for holding short positions or waiting);
- Candle color: Different colors correspond to 16 states (check the parameter panel for the color-state correspondence). Green tones usually represent long states, red tones represent short states, and darker colors indicate higher intensity. You can track the conversion of long-short forces through candle color changes.
2. **Key Signal Capture: Check Pattern Markers**
- Green "Golden Cross" marker below bars: Indicates a golden cross (fast line crossing slow line) of MACD2, suggesting the start of medium-to-long-term long momentum. Confirm further with the current combined state (e.g., green long states);
- Red "Death Cross" marker above bars: Indicates a death cross (fast line crossing slow line) of MACD2, suggesting the start of medium-to-long-term short momentum. Be alert to trend reversal when combined with the current state (e.g., red short states);
- Blue triangle (below bars)/Purple triangle (above bars): Represent MACD2 crossing above the 0-axis (long trend strengthening) and crossing below the 0-axis (short trend strengthening) respectively, serving as auxiliary signals for trend direction confirmation.
3. **Parameter Adjustment Tips**
- Trend length/threshold: For high-volatility varieties (e.g., cryptocurrencies), adjust "Trend Judgment Length" to 7-10 and "Up/Down Threshold" to 4 to avoid frequent state switches; for low-volatility varieties (e.g., blue-chip stocks), keep default parameters (length 5, threshold 3);
- State colors: It is recommended to set long states to green of different shades and short states to red of different shades for visual distinction;
- Signal markers: If markers are cluttered, reduce "Signal Marker Size" in the parameter panel or adjust marker colors to distinguish them from candle colors.
## 中文功能总结
该指标是一款基于双MACD系统的多状态趋势分析工具,核心功能围绕“多空状态识别+可视化跟踪”设计,具体包括:
1. **双MACD计算体系**:同步运行两套MACD指标——MACD1(参数12,26,9,常规短周期)与MACD2(参数48,96,35,长周期),分别捕捉短期和中长期动量信号;
2. **精细化趋势判断**:通过“趋势周期(默认5根K线)+涨跌阈值(默认3次)”,统计MACD在周期内的涨跌次数,判断每套MACD是否处于“0轴上上升/下降”“0轴下上升/下降”4种基础状态;
3. **16种多空组合状态**:将两套MACD的4种基础状态交叉组合,形成16种多空强度状态(如“状态1:多头最强”“状态16:空头最强”),每种状态对应独立可自定义的颜色;
4. **多维可视化呈现**:① K线按当前组合状态染色,直观区分多空氛围;② 右上角表格显示当前及前8根K线的MACD1/MACD2状态、组合状态历史,便于回溯趋势变化;③ 标记MACD2的金叉、死叉、上穿0轴、下穿0轴4类关键信号,提示动量转折;
5. **参数可调节性**:支持自定义趋势周期、涨跌阈值、16种状态颜色、信号标记大小及颜色,适配不同品种(股票/期货/加密货币)和时间周期。
## English Function Summary
This indicator is a multi-state trend analysis tool based on a dual-MACD system, with core functions designed around "long-short state identification + visual tracking", including:
1. **Dual-MACD Calculation System**:Runs two sets of MACD indicators simultaneously — MACD1 (parameters 12,26,9, regular short-cycle) and MACD2 (parameters 48,96,35, long-cycle) — to capture short-term and medium-to-long-term momentum signals respectively;
2. **Refined Trend Judgment**:Through "trend length (default 5 bars) + up/down threshold (default 3 times)", count the number of ups and downs of MACD within the cycle to determine whether each MACD is in 4 basic states: "above 0-axis rising/falling" and "below 0-axis rising/falling";
3. **16 Long-Short Combined States**:Cross-combine the 4 basic states of the two MACDs to form 16 long-short intensity states (e.g., "State 1: Strongest Long", "State 16: Strongest Short"), each with an independently customizable color;
4. **Multi-dimensional Visualization**:① Candles are colored according to the current combined state for intuitive distinction of long-short sentiment; ② A table at the top-right shows the MACD1/MACD2 states and combined state history of the current and previous 8 bars, facilitating trend change review; ③ Marks 4 key signals of MACD2 (golden cross, death cross, cross above 0-axis, cross below 0-axis) to indicate momentum turning points;
5. **Adjustable Parameters**:Supports customization of trend length, up/down thresholds, colors of 16 states, signal marker size and colors, adapting to different varieties (stocks/futures/cryptocurrencies) and timeframes.
# 指标使用方法(Usage Guide)
## 中文使用方法
1. **核心信息读取:看表格与K线颜色**
- 右上角表格:首行是“MACD1状态/MACD2状态/组合状态”标题,下方行显示历史数据(第1行是当前K线,背景浅蓝色标注);其中“0轴上↑”代表MACD在0轴上方且呈上升趋势,“0轴下↓”代表MACD在0轴下方且呈下降趋势,结合“组合状态”文字可快速判断当前多空强度(如“状态1:多头最强”适合观望或持仓多头,“状态16:空头最强”适合观望或持仓空头);
- K线颜色:不同颜色对应16种状态(可在参数面板查看颜色与状态的对应关系),绿色系通常代表多头状态,红色系代表空头状态,颜色越深强度越高,通过K线颜色变化可快速跟踪多空力量转换。
2. **关键信号捕捉:看形态标记**
- 下方绿色“金叉”标记:MACD2出现快线交叉慢线的金叉信号,提示中长期多头动量启动,可结合当前组合状态(如绿色系多头状态)进一步确认;
- 上方红色“死叉”标记:MACD2出现快线交叉慢线的死叉信号,提示中长期空头动量启动,需结合当前组合状态(如红色系空头状态)警惕趋势反转;
- 蓝色三角形(下)/紫色三角形(上):分别代表MACD2上穿0轴(多头趋势强化)、下穿0轴(空头趋势强化),是趋势方向确认的辅助信号。
3. **参数调整技巧**
- 趋势周期/阈值:波动大的品种(如加密货币)可将“趋势判断周期”调至7-10,“上升/下降阈值”调至4,避免频繁切换状态;波动小的品种(如蓝筹股)可保持默认参数(周期5、阈值3);
- 状态颜色:建议将多头状态设为不同深浅的绿色,空头状态设为不同深浅的红色,便于视觉区分;
- 信号标记:若觉得标记杂乱,可在参数面板调小“信号标记大小”,或调整标记颜色使其与K线颜色区分开。
## English Usage Guide
1. **Core Information Reading: Check the Table and Candle Color**
- Top-right table: The first row is the header "MACD1 State/MACD2 State/Combined State", and the rows below show historical data (the first row is the current bar, marked with a light blue background); "Above 0↑" means MACD is above the 0-axis and in an upward trend, "Below 0↓" means MACD is below the 0-axis and in a downward trend. Combining the "Combined State" text, you can quickly judge the current long-short intensity (e.g., "State 1: Strongest Long" is suitable for holding long positions or waiting, "State 16: Strongest Short" is suitable for holding short positions or waiting);
- Candle color: Different colors correspond to 16 states (check the parameter panel for the color-state correspondence). Green tones usually represent long states, red tones represent short states, and darker colors indicate higher intensity. You can track the conversion of long-short forces through candle color changes.
2. **Key Signal Capture: Check Pattern Markers**
- Green "Golden Cross" marker below bars: Indicates a golden cross (fast line crossing slow line) of MACD2, suggesting the start of medium-to-long-term long momentum. Confirm further with the current combined state (e.g., green long states);
- Red "Death Cross" marker above bars: Indicates a death cross (fast line crossing slow line) of MACD2, suggesting the start of medium-to-long-term short momentum. Be alert to trend reversal when combined with the current state (e.g., red short states);
- Blue triangle (below bars)/Purple triangle (above bars): Represent MACD2 crossing above the 0-axis (long trend strengthening) and crossing below the 0-axis (short trend strengthening) respectively, serving as auxiliary signals for trend direction confirmation.
3. **Parameter Adjustment Tips**
- Trend length/threshold: For high-volatility varieties (e.g., cryptocurrencies), adjust "Trend Judgment Length" to 7-10 and "Up/Down Threshold" to 4 to avoid frequent state switches; for low-volatility varieties (e.g., blue-chip stocks), keep default parameters (length 5, threshold 3);
- State colors: It is recommended to set long states to green of different shades and short states to red of different shades for visual distinction;
- Signal markers: If markers are cluttered, reduce "Signal Marker Size" in the parameter panel or adjust marker colors to distinguish them from candle colors.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
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.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
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.