Files
tradingview-pine/参考/MaxTrendPoints.pine
2025-08-02 04:21:30 +00:00

307 lines
27 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © BigBeluga
//@version=6
indicator("Max Trend Points [BigBeluga]", overlay = true, max_lines_count = 500, max_labels_count = 500)
// ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
var line_up = line(na)
var line_dn = line(na)
var lbl_up = label(na)
var lbl_dn = label(na)
var highest = array.new_float(0)
var lowest = array.new_float(0)
var int start = na
var int last_trend_change = 0
var float last_trend_price = 0.0
// Trend Factor Inputs
factor_default = input.float(2.5, step = 0.1, title="默认趋势因子")
factor_btc = input.float(3.0, step = 0.1, title="BTCUSD 趋势因子")
factor_xau = input.float(2.5, step = 0.1, title="XAUUSD 趋势因子")
factor_eth = input.float(2.8, step = 0.1, title="ETHUSD 趋势因子")
factor_gbp = input.float(2.5, step = 0.1, title="GBPJPY 趋势因子")
// Consolidation Bars Inputs
consolidation_bars_default = input.int(20, title="默认震荡检测周期", minval=10)
consolidation_bars_btc = input.int(25, title="BTCUSD 震荡检测周期", minval=10)
consolidation_bars_xau = input.int(25, title="XAUUSD 震荡检测周期", minval=10)
consolidation_bars_eth = input.int(20, title="ETHUSD 震荡检测周期", minval=10)
consolidation_bars_gbp = input.int(18, title="GBPJPY 震荡检测周期", minval=10)
// Consolidation Threshold Inputs
consolidation_threshold_default = input.float(0.1, title="默认震荡阈值(%)", minval=0.1, step=0.02)
consolidation_threshold_btc = input.float(0.2, title="BTCUSD 震荡阈值(%)", minval=0.1, step=0.02)
consolidation_threshold_xau = input.float(0.3, title="XAUUSD 震荡阈值(%)", minval=0.1, step=0.02)
consolidation_threshold_eth = input.float(0.15, title="ETHUSD 震荡阈值(%)", minval=0.1, step=0.02)
consolidation_threshold_gbp = input.float(0.16, title="GBPJPY 震荡阈值(%)", minval=0.1, step=0.02)
// Activity Period Inputs
activity_period_default = input.int(14, title="默认活跃度检测周期", minval=5)
activity_period_btc = input.int(20, title="BTCUSD 活跃度检测周期", minval=5)
activity_period_xau = input.int(20, title="XAUUSD 活跃度检测周期", minval=5)
activity_period_eth = input.int(20, title="ETHUSD 活跃度检测周期", minval=5)
activity_period_gbp = input.int(12, title="GBPJPY 活跃度检测周期", minval=5)
// Activity Threshold Inputs
activity_threshold_default = input.float(1.3, title="默认活跃度阈值(ATR倍数)", minval=0.1, step=0.1)
activity_threshold_btc = input.float(1.5, title="BTCUSD 活跃度阈值(ATR倍数)", minval=0.1, step=0.1)
activity_threshold_xau = input.float(1.4, title="XAUUSD 活跃度阈值(ATR倍数)", minval=0.1, step=0.1)
activity_threshold_eth = input.float(1.4, title="ETHUSD 活跃度阈值(ATR倍数)", minval=0.1, step=0.1)
activity_threshold_gbp = input.float(1.3, title="GBPJPY 活跃度阈值(ATR倍数)", minval=0.1, step=0.1)
// Colors
col_up = input.color(color.rgb(28, 194, 216), "上涨颜色")
col_dn = input.color(color.rgb(228, 144, 19), "下跌颜色")
// Alert Settings
alert_group = "警报设置"
enable_trend_alert = input.bool(true, "启用趋势变化警报", group=alert_group)
enable_consolidation_alert = input.bool(true, "启用震荡警报", group=alert_group)
enable_activity_alert = input.bool(true, "启用市场活跃度警报", group=alert_group)
// Select Parameters Based on Trading Pair
sym = syminfo.tickerid
factor =
sym == "TICKMILL:BTCUSD" ? factor_btc :
sym == "TICKMILL:XAUUSD" ? factor_xau :
sym == "TICKMILL:ETHUSD" ? factor_eth :
sym == "TICKMILL:GBPJPY" ? factor_gbp :
factor_default
consolidation_bars =
sym == "TICKMILL:BTCUSD" ? consolidation_bars_btc :
sym == "TICKMILL:XAUUSD" ? consolidation_bars_xau :
sym == "TICKMILL:ETHUSD" ? consolidation_bars_eth :
sym == "TICKMILL:GBPJPY" ? consolidation_bars_gbp :
consolidation_bars_default
consolidation_threshold =
sym == "TICKMILL:BTCUSD" ? consolidation_threshold_btc :
sym == "TICKMILL:XAUUSD" ? consolidation_threshold_xau :
sym == "TICKMILL:ETHUSD" ? consolidation_threshold_eth :
sym == "TICKMILL:GBPJPY" ? consolidation_threshold_gbp :
consolidation_threshold_default
activity_period =
sym == "TICKMILL:BTCUSD" ? activity_period_btc :
sym == "TICKMILL:XAUUSD" ? activity_period_xau :
sym == "TICKMILL:ETHUSD" ? activity_period_eth :
sym == "TICKMILL:GBPJPY" ? activity_period_gbp :
activity_period_default
activity_threshold =
sym == "TICKMILL:BTCUSD" ? activity_threshold_btc :
sym == "TICKMILL:XAUUSD" ? activity_threshold_xau :
sym == "TICKMILL:ETHUSD" ? activity_threshold_eth :
sym == "TICKMILL:GBPJPY" ? activity_threshold_gbp :
activity_threshold_default
// }
// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
trend_line(factor)=>
src = hl2
dist = ta.hma(high-low, 200)
upperBand = src + factor * dist
lowerBand = src - factor * dist
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
int _direction = na
float trend_line = na
prevTrendLine = nz(trend_line[1])
if na(dist[1])
_direction := 1
else if prevTrendLine == prevUpperBand
_direction := close > upperBand ? -1 : 1
else
_direction := close < lowerBand ? 1 : -1
trend_line := _direction == -1 ? lowerBand : upperBand
[trend_line, _direction]
[trend_line, _direction] = trend_line(factor)
t_change = ta.cross(_direction, 0)
// Oscillation Detection
highest_recent = ta.highest(high, consolidation_bars)
lowest_recent = ta.lowest(low, consolidation_bars)
price_range = (highest_recent - lowest_recent) / lowest_recent * 100
is_consolidating = price_range < consolidation_threshold
// Market Activity Detection
atr_current = ta.atr(activity_period)
atr_avg = ta.sma(atr_current, activity_period * 2)
is_active = atr_current > atr_avg * activity_threshold
// Calculate Trend Strength
trend_strength = math.abs(close - trend_line) / trend_line * 100
if t_change
array.clear(highest)
array.clear(lowest)
start := bar_index
last_trend_change := bar_index
last_trend_price := close
if t_change and _direction == 1
line_dn := line.new(bar_index, close, na, na, color = chart.fg_color, style = line.style_dashed)
lbl_dn := label.new(bar_index, low, color = color.new(col_dn, 50), textcolor = chart.fg_color, size = size.small, style = label.style_label_up)
if t_change and _direction == -1
lbl_up := label.new(bar_index, high, color = color.new(col_up, 50), textcolor = chart.fg_color, size = size.small, style = label.style_label_down)
line_up := line.new(bar_index, close, na, na, color = chart.fg_color, style = line.style_dashed)
if not t_change and _direction == -1
array.push(highest, high)
label.set_xy(lbl_up, start + array.indexof(highest, array.max(highest))+1, array.max(highest))
line.set_xy2(line_up, start + array.indexof(highest, array.max(highest))+1, array.max(highest))
if not t_change and _direction == 1
array.push(lowest, low)
label.set_xy(lbl_dn, start + array.indexof(lowest, array.min(lowest))+1, array.min(lowest))
line.set_xy2(line_dn, start + array.indexof(lowest, array.min(lowest))+1, array.min(lowest))
if line.get_y2(line_up) > line.get_y1(line_up)
label.set_text(lbl_up, str.tostring((line.get_y2(line_up) - line.get_y1(line_up)) / line.get_y1(line_up) * 100, format.percent))
if line.get_y2(line_dn) < line.get_y1(line_dn)
label.set_text(lbl_dn, str.tostring((line.get_y2(line_dn) - line.get_y1(line_dn)) / line.get_y1(line_dn) * 100, format.percent))
t_color = _direction == -1 ? col_up : col_dn
// Track previous states for state change detection
var bool was_consolidating = false
var bool was_active = false
was_consolidating := is_consolidating
was_active := is_active
// }
// ===== 统一警报系统 =====
// 统一警报系统 - 只需添加一次警报即可捕获所有信号
// 检测所有警报条件并生成对应的JSON消息
alert_message = ""
// 趋势变化警报
if enable_trend_alert and t_change and _direction == -1
alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"价格转为上涨趋势","方向":"上涨趋势","信号":"trend_up"}'
alert(alert_message, alert.freq_once_per_bar_close)
if enable_trend_alert and t_change and _direction == 1
alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"价格转为下跌趋势","方向":"下跌趋势","信号":"trend_down"}'
alert(alert_message, alert.freq_once_per_bar_close)
// 震荡状态变化警报
// if enable_consolidation_alert and is_consolidating and not was_consolidating[1]
// alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"市场进入震荡状态","状态":"震荡","信号":"consolidation_start"}'
// alert(alert_message, alert.freq_once_per_bar_close)
// if enable_consolidation_alert and not is_consolidating and was_consolidating[1]
// direction_text = _direction == -1 ? "上涨趋势" : "下跌趋势"
// alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"市场突破震荡状态","方向":"' + direction_text + '","信号":"consolidation_break"}'
// alert(alert_message, alert.freq_once_per_bar_close)
// // 活跃度变化警报
// if enable_activity_alert and is_active and not was_active[1]
// alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"市场活跃度增加","活跃状态":"活跃","信号":"activity_increase"}'
// alert(alert_message, alert.freq_once_per_bar_close)
// if enable_activity_alert and not is_active and was_active[1]
// alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"市场活跃度降低","活跃状态":"不活跃","信号":"activity_decrease"}'
// alert(alert_message, alert.freq_once_per_bar_close)
// 综合市场分析警报
// if t_change and (enable_trend_alert or enable_consolidation_alert or enable_activity_alert)
// direction_text = _direction == -1 ? "上涨趋势" : "下跌趋势"
// status_text = is_consolidating ? "震荡" : (is_active ? "活跃" : "正常")
// alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"综合市场分析","方向":"' + direction_text + '","状态":"' + status_text + '","信号":"market_analysis"}'
// alert(alert_message, alert.freq_once_per_bar_close)
// 状态监控警报(频率较低)
if enable_trend_alert and _direction == -1
alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"价格处于上涨趋势","方向":"上涨趋势","信号":"trend_up_status"}'
alert(alert_message, alert.freq_once_per_bar)
if enable_trend_alert and _direction == 1
alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"价格处于下跌趋势","方向":"下跌趋势","信号":"trend_down_status"}'
alert(alert_message, alert.freq_once_per_bar)
if enable_consolidation_alert and is_consolidating
alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"价格处于震荡状态","状态":"震荡","信号":"consolidation_status"}'
alert(alert_message, alert.freq_once_per_bar)
if enable_activity_alert and is_active
alert_message := '{"指标名称":"MaxTrendPoints","交易对":"' + syminfo.ticker + '","周期":"' + timeframe.period + '","趋势线":"' + str.tostring(trend_line, '#.####') + '","趋势强度":"' + str.tostring(trend_strength, '#.##') + '","价格范围":"' + str.tostring(price_range, '#.####') + '","当前ATR":"' + str.tostring(atr_current, '#.####') + '","开盘价":"' + str.tostring(open, '#.####') + '","收盘价":"' + str.tostring(close, '#.####') + '","最高价":"' + str.tostring(high, '#.####') + '","最低价":"' + str.tostring(low, '#.####') + '","触发时间":"' + str.tostring(timenow) + '","时间":"' + str.tostring(time) + '","事件":"价格处于活跃状态","活跃状态":"活跃","信号":"activity_status"}'
alert(alert_message, alert.freq_once_per_bar)
// ===== 传统警报条件(保留兼容性)=====
// 注意使用统一警报系统时建议只使用上面的alert()函数
// 以下alertcondition保留用于需要单独设置警报的情况
// 创建用于警报的plot变量
plot(trend_line, title = '趋势线', display = display.none)
plot(trend_strength, title = '趋势强度', display = display.none)
plot(price_range, title = '价格范围', display = display.none)
plot(atr_current, title = '当前ATR', display = display.none)
// 趋势变化警报
alertcondition(enable_trend_alert and t_change and _direction == -1, title = '价格转为上涨趋势', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"价格转为上涨趋势","方向":"上涨趋势","信号":"trend_up"}')
alertcondition(enable_trend_alert and t_change and _direction == 1, title = '价格转为下跌趋势', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"价格转为下跌趋势","方向":"下跌趋势","信号":"trend_down"}')
// 震荡状态变化警报
alertcondition(enable_consolidation_alert and is_consolidating and not was_consolidating[1], title = '市场进入震荡状态', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"市场进入震荡状态","状态":"震荡","信号":"consolidation_start"}')
alertcondition(enable_consolidation_alert and not is_consolidating and was_consolidating[1], title = '市场突破震荡状态', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"市场突破震荡状态","信号":"consolidation_break"}')
// 活跃度变化警报
alertcondition(enable_activity_alert and is_active and not was_active[1], title = '市场活跃度增加', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"市场活跃度增加","活跃状态":"活跃","信号":"activity_increase"}')
alertcondition(enable_activity_alert and not is_active and was_active[1], title = '市场活跃度降低', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"市场活跃度降低","活跃状态":"不活跃","信号":"activity_decrease"}')
// 综合市场分析警报
alertcondition(t_change and (enable_trend_alert or enable_consolidation_alert or enable_activity_alert), title = '综合市场分析', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"综合市场分析","信号":"market_analysis"}')
// 状态监控警报
alertcondition(enable_trend_alert and _direction == -1, title = '价格处于上涨趋势', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"价格处于上涨趋势","方向":"上涨趋势","信号":"trend_up_status"}')
alertcondition(enable_trend_alert and _direction == 1, title = '价格处于下跌趋势', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"价格处于下跌趋势","方向":"下跌趋势","信号":"trend_down_status"}')
alertcondition(enable_consolidation_alert and is_consolidating, title = '价格处于震荡状态', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"价格处于震荡状态","状态":"震荡","信号":"consolidation_status"}')
alertcondition(enable_activity_alert and is_active, title = '价格处于活跃状态', message = '{"指标名称":"MaxTrendPoints","交易对":"{{ticker}}","周期":"{{interval}}","趋势线":"{{plot("趋势线")}}","趋势强度":"{{plot("趋势强度")}}","价格范围":"{{plot("价格范围")}}","当前ATR":"{{plot("当前ATR")}}","开盘价":"{{open}}","收盘价":"{{close}}","最高价":"{{high}}","最低价":"{{low}}","触发时间":"{{timenow}}","时间":"{{time}}","事件":"价格处于活跃状态","活跃状态":"活跃","信号":"activity_status"}')
// ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
plotshape(t_change ? trend_line : na, "趋势变化", style = shape.circle, location = location.absolute, color = t_color, size = size.tiny)
t_p = plot(trend_line, "趋势线", color = t_change ? color.new(t_color, 100) : t_color, linewidth = 2)
m_p = plot(hl2, color = color.new(color.gray, 100), editable = false)
fill(t_p, m_p, hl2, trend_line, color.new(t_color, 95), color.new(t_color, 90))
// Status Panel
var table panel = table.new(position.top_right, 3, 4, bgcolor=color.new(color.black, 80))
if barstate.islast
table.cell(panel, 0, 0, "市场状态", text_color=color.white, text_size=size.small)
table.cell(panel, 1, 0, "当前值", text_color=color.white, text_size=size.small)
table.cell(panel, 0, 1, "趋势方向", text_color=color.gray, text_size=size.small)
table.cell(panel, 1, 1, _direction == -1 ? "↑ 上涨" : "↓ 下跌",
text_color=_direction == -1 ? col_up : col_dn, text_size=size.small)
table.cell(panel, 0, 2, "市场状态", text_color=color.gray, text_size=size.small)
table.cell(panel, 1, 2, is_consolidating ? "震荡中" : "趋势中",
text_color=is_consolidating ? color.rgb(43, 43, 39) : color.green, text_size=size.small)
table.cell(panel, 0, 3, "活跃度", text_color=color.gray, text_size=size.small)
table.cell(panel, 1, 3, is_active ? "活跃" : "平静",
text_color=is_active ? color.rgb(60, 60, 60) : color.blue, text_size=size.small)
// }