2025年8月2日 07:50
This commit is contained in:
143
conbinined2.pine
143
conbinined2.pine
@@ -64,11 +64,15 @@ vol_filter_length = input.int(5, title='成交量过滤长度', minval=1, maxval
|
||||
vol_multiplier = input.float(1.2, title='成交量倍数', minval=0.5, maxval=5.0, step=0.01, group='VolumeFilter')
|
||||
volume_confirmation_bars = input.int(5, title='成交量确认K线数', minval=1, maxval=20, group='VolumeFilter')
|
||||
volume_strength_multiplier = input.float(1.05, title='成交量强度倍数', minval=1.0, maxval=2.0, step=0.01, group='VolumeFilter')
|
||||
volume_filter_mode = input.string('温和', title='过滤强度', options=['温和', '中等', '严格'], group='VolumeFilter')
|
||||
volume_filter_level = input.int(3, title='成交量过滤等级 (1-5级)', minval=1, maxval=5, tooltip='1级最温和(过滤明显假信号), 5级最严格', group='VolumeFilter')
|
||||
apply_volume_to_trigger = input.bool(false, title='启动条件应用成交量过滤', group='VolumeFilter')
|
||||
min_volume_ratio = input.float(0.3, title='最小成交量比率(温和模式)', minval=0.1, maxval=1.0, step=0.01, group='VolumeFilter')
|
||||
min_volume_ratio = input.float(0.3, title='最小成交量比率(1级模式)', minval=0.1, maxval=1.0, step=0.01, group='VolumeFilter')
|
||||
show_volume_debug = input.bool(true, title='显示成交量调试信息', group='VolumeFilter')
|
||||
|
||||
// ═════════ SRBR风格成交量过滤参数 ════════
|
||||
srbr_vol_divisor = input.float(2.5, title='SRBR成交量除数', minval=1.0, maxval=5.0, step=0.1, tooltip='参考SRBR源代码的Vol/2.5逻辑', group='VolumeFilter')
|
||||
volume_lookback_period = input.int(25, title='成交量回看周期', minval=5, maxval=50, tooltip='用于计算成交量梯度和阈值', group='VolumeFilter')
|
||||
|
||||
// ═════════ 价格标签配置 ════════
|
||||
labelSet = input(false, '═════════ Price Labels Configuration ════════')
|
||||
show_mean_label = input.bool(true, title='显示MEAN价格标签', group='Labels')
|
||||
@@ -137,7 +141,13 @@ upAndDownVolume() =>
|
||||
else
|
||||
0.0 // 十字星,中性成交量
|
||||
|
||||
// 成交量过滤函数(温和版本,只过滤明显假信号)
|
||||
// 成交量过滤函数(1-5级细分过滤,参考SRBR源代码逻辑)
|
||||
// 等级说明:
|
||||
// 1级:最温和 - 只过滤极明显的假信号,适合高频交易
|
||||
// 2级:温和 - 过滤明显假信号,保持较高的信号频率
|
||||
// 3级:中等 - 标准过滤强度,平衡信号质量和频率
|
||||
// 4级:严格 - 较强过滤,减少假信号但可能错过部分机会
|
||||
// 5级:最严格 - 最强过滤,参考SRBR的高低成交量阈值逻辑,信号最少但质量最高
|
||||
get_volume_filter() =>
|
||||
Vol = upAndDownVolume()
|
||||
vol_abs = math.abs(Vol)
|
||||
@@ -146,32 +156,59 @@ get_volume_filter() =>
|
||||
if not enable_volume_filter
|
||||
[true, true] // 如果未启用成交量过滤,返回true
|
||||
else
|
||||
// 根据过滤强度调整阈值
|
||||
threshold_multiplier = switch volume_filter_mode
|
||||
'温和' => vol_multiplier * 0.8 // 降低20%,更容易通过
|
||||
'中等' => vol_multiplier
|
||||
'严格' => vol_multiplier * 1.3 // 提高30%,更难通过
|
||||
// SRBR风格的成交量阈值计算(参考原始SRBR代码)
|
||||
vol_adjusted = Vol / srbr_vol_divisor // 参考SRBR的Vol/2.5逻辑
|
||||
vol_hi = ta.highest(vol_adjusted, volume_lookback_period) // 高成交量阈值
|
||||
vol_lo = ta.lowest(vol_adjusted, volume_lookback_period) // 低成交量阈值
|
||||
vol_range = vol_hi - vol_lo
|
||||
vol_mid = (vol_hi + vol_lo) / 2
|
||||
|
||||
// 根据1-5级过滤等级调整阈值(参考SRBR的分层逻辑)
|
||||
threshold_multiplier = switch volume_filter_level
|
||||
1 => vol_multiplier * 0.6 // 1级:最温和,只过滤极明显的假信号
|
||||
2 => vol_multiplier * 0.8 // 2级:温和,过滤明显假信号
|
||||
3 => vol_multiplier * 1.0 // 3级:中等,标准过滤
|
||||
4 => vol_multiplier * 1.3 // 4级:严格,较强过滤
|
||||
5 => vol_multiplier * 1.6 // 5级:最严格,最强过滤
|
||||
=> vol_multiplier
|
||||
|
||||
vol_threshold = vol_avg * threshold_multiplier
|
||||
|
||||
// 温和过滤:只要成交量方向正确且不是极低成交量即可
|
||||
// 成交量方向性过滤(结合SRBR的正负成交量概念)
|
||||
long_volume_ok = false
|
||||
short_volume_ok = false
|
||||
|
||||
if volume_filter_mode == '温和'
|
||||
// 温和模式:只过滤极低成交量的假突破
|
||||
min_volume_threshold = vol_avg * min_volume_ratio // 用户可配置的最小比率
|
||||
if volume_filter_level == 1
|
||||
// 1级:最温和过滤,只要成交量方向正确且不是极低成交量
|
||||
min_volume_threshold = vol_avg * min_volume_ratio
|
||||
long_volume_ok := Vol > 0 and vol_abs > min_volume_threshold
|
||||
short_volume_ok := Vol < 0 and vol_abs > min_volume_threshold
|
||||
else
|
||||
// 中等和严格模式:需要成交量强度超过阈值
|
||||
else if volume_filter_level == 2
|
||||
// 2级:温和过滤,需要成交量超过平均值的80%
|
||||
moderate_threshold = vol_avg * 0.8
|
||||
long_volume_ok := Vol > 0 and vol_abs > moderate_threshold
|
||||
short_volume_ok := Vol < 0 and vol_abs > moderate_threshold
|
||||
else if volume_filter_level == 3
|
||||
// 3级:中等过滤,标准阈值
|
||||
long_volume_ok := Vol > 0 and vol_abs > vol_threshold
|
||||
short_volume_ok := Vol < 0 and vol_abs > vol_threshold
|
||||
else if volume_filter_level == 4
|
||||
// 4级:严格过滤,需要成交量超过阈值且接近高成交量区间
|
||||
strict_threshold = vol_threshold * 1.2
|
||||
volume_strength_check = vol_abs > vol_mid // 需要超过中位数
|
||||
long_volume_ok := Vol > 0 and vol_abs > strict_threshold and volume_strength_check
|
||||
short_volume_ok := Vol < 0 and vol_abs > strict_threshold and volume_strength_check
|
||||
else // volume_filter_level == 5
|
||||
// 5级:最严格过滤,参考SRBR的vol_hi/vol_lo逻辑
|
||||
very_strict_threshold = vol_threshold * 1.5
|
||||
// 做多需要正成交量且接近高成交量阈值(类似SRBR的Vol > vol_hi)
|
||||
long_volume_ok := Vol > 0 and vol_abs > very_strict_threshold and vol_adjusted > vol_hi * 0.8
|
||||
// 做空需要负成交量且接近低成交量阈值(类似SRBR的Vol < vol_lo)
|
||||
short_volume_ok := Vol < 0 and vol_abs > very_strict_threshold and vol_adjusted < vol_lo * 1.2
|
||||
|
||||
[long_volume_ok, short_volume_ok]
|
||||
|
||||
// 成交量趋势确认函数(温和版本)
|
||||
// 成交量趋势确认函数(1-5级细分版本)
|
||||
volume_trend_confirmation(signal_type) =>
|
||||
if not enable_volume_filter
|
||||
true
|
||||
@@ -180,23 +217,58 @@ volume_trend_confirmation(signal_type) =>
|
||||
volume_avg = ta.sma(math.abs(Vol), volume_confirmation_bars)
|
||||
current_volume = math.abs(Vol)
|
||||
|
||||
// 根据过滤强度调整成交量强度要求
|
||||
strength_multiplier = switch volume_filter_mode
|
||||
'温和' => volume_strength_multiplier * 0.9 // 降低10%
|
||||
'中等' => volume_strength_multiplier
|
||||
'严格' => volume_strength_multiplier * 1.2 // 提高20%
|
||||
// SRBR风格的成交量分析
|
||||
vol_adjusted = Vol / srbr_vol_divisor
|
||||
vol_hi = ta.highest(vol_adjusted, volume_lookback_period)
|
||||
vol_lo = ta.lowest(vol_adjusted, volume_lookback_period)
|
||||
|
||||
// 根据1-5级过滤等级调整成交量强度要求
|
||||
strength_multiplier = switch volume_filter_level
|
||||
1 => volume_strength_multiplier * 0.8 // 1级:最宽松的强度要求
|
||||
2 => volume_strength_multiplier * 0.9 // 2级:较宽松的强度要求
|
||||
3 => volume_strength_multiplier * 1.0 // 3级:标准强度要求
|
||||
4 => volume_strength_multiplier * 1.2 // 4级:较严格的强度要求
|
||||
5 => volume_strength_multiplier * 1.5 // 5级:最严格的强度要求
|
||||
=> volume_strength_multiplier
|
||||
|
||||
volume_strength = current_volume > volume_avg * strength_multiplier
|
||||
|
||||
if signal_type == "long"
|
||||
// 做多信号:需要正成交量且成交量增强
|
||||
Vol > 0 and volume_strength
|
||||
else if signal_type == "short"
|
||||
// 做空信号:需要负成交量且成交量增强
|
||||
Vol < 0 and volume_strength
|
||||
else
|
||||
volume_strength
|
||||
// 根据过滤等级应用不同的确认逻辑
|
||||
if volume_filter_level <= 2
|
||||
// 1-2级:基础成交量方向确认
|
||||
if signal_type == "long"
|
||||
Vol > 0 and volume_strength
|
||||
else if signal_type == "short"
|
||||
Vol < 0 and volume_strength
|
||||
else
|
||||
volume_strength
|
||||
else if volume_filter_level == 3
|
||||
// 3级:标准确认逻辑
|
||||
if signal_type == "long"
|
||||
Vol > 0 and volume_strength
|
||||
else if signal_type == "short"
|
||||
Vol < 0 and volume_strength
|
||||
else
|
||||
volume_strength
|
||||
else if volume_filter_level == 4
|
||||
// 4级:严格确认,需要额外的成交量条件
|
||||
volume_momentum = current_volume > volume_avg * 1.1 // 额外的动量要求
|
||||
if signal_type == "long"
|
||||
Vol > 0 and volume_strength and volume_momentum
|
||||
else if signal_type == "short"
|
||||
Vol < 0 and volume_strength and volume_momentum
|
||||
else
|
||||
volume_strength and volume_momentum
|
||||
else // volume_filter_level == 5
|
||||
// 5级:最严格确认,参考SRBR的高低成交量阈值
|
||||
if signal_type == "long"
|
||||
// 做多需要正成交量、强度确认、且接近高成交量阈值
|
||||
Vol > 0 and volume_strength and vol_adjusted > vol_hi * 0.7
|
||||
else if signal_type == "short"
|
||||
// 做空需要负成交量、强度确认、且接近低成交量阈值
|
||||
Vol < 0 and volume_strength and vol_adjusted < vol_lo * 1.3
|
||||
else
|
||||
volume_strength and (vol_adjusted > vol_hi * 0.7 or vol_adjusted < vol_lo * 1.3)
|
||||
|
||||
// ═════════ 距离阈值切换(参考原MA200代码) ════════
|
||||
get_distance_threshold() =>
|
||||
@@ -1355,7 +1427,7 @@ if show_info_table and barstate.islast
|
||||
table.cell(info_table, 9, 2, condition4_15m_long ? "10分钟内" : condition4_15m_short ? "10分钟内" : "窗口外", text_color=color.black, bgcolor=condition4_color, text_size=text_size)
|
||||
// 成交量状态
|
||||
volume_status = current_volume > 0 ? "买盘" : current_volume < 0 ? "卖盘" : "平衡"
|
||||
volume_strength_text = enable_volume_filter ? (volume_is_strong ? "强势" : "弱势") + "|" + volume_filter_mode : "未启用"
|
||||
volume_strength_text = enable_volume_filter ? (volume_is_strong ? "强势" : "弱势") + "|" + str.tostring(volume_filter_level) + "级" : "未启用"
|
||||
table.cell(info_table, 10, 2, volume_status, text_color=color.black, bgcolor=volume_color, text_size=text_size)
|
||||
table.cell(info_table, 11, 2, volume_strength_text, text_color=color.black, bgcolor=volume_confirm_color, text_size=text_size)
|
||||
|
||||
@@ -1372,8 +1444,9 @@ if show_info_table and barstate.islast
|
||||
table.cell(info_table, 7, 3, condition2_1m_long ? "1m做多就绪" : condition2_1m_short ? "1m做空就绪" : "1m条件未满足", text_color=color.black, bgcolor=condition2_color, text_size=text_size)
|
||||
table.cell(info_table, 8, 3, condition3_5m_long ? "5m做多就绪" : condition3_5m_short ? "5m做空就绪" : "5m条件未满足", text_color=color.black, bgcolor=condition3_color, text_size=text_size)
|
||||
table.cell(info_table, 9, 3, condition4_15m_long ? "15m距离满足" : condition4_15m_short ? "15m距离满足" : "15m距离不足", text_color=color.black, bgcolor=condition4_color, text_size=text_size)
|
||||
// 成交量调试信息
|
||||
volume_debug = "Vol:" + str.tostring(current_volume, '#.##') + "|模式:" + volume_filter_mode + "|过滤:" + (long_volume_ok ? "多✓" : short_volume_ok ? "空✓" : "✗")
|
||||
// 成交量调试信息(更新为1-5级显示)
|
||||
volume_level_text = str.tostring(volume_filter_level) + "级"
|
||||
volume_debug = "Vol:" + str.tostring(current_volume, '#.##') + "|等级:" + volume_level_text + "|过滤:" + (long_volume_ok ? "多✓" : short_volume_ok ? "空✓" : "✗")
|
||||
table.cell(info_table, 10, 3, volume_debug, text_color=color.black, bgcolor=volume_color, text_size=text_size)
|
||||
alert_debug = "高级:" + (advanced_long_alert ? "多" : advanced_short_alert ? "空" : "无") + "|冷却:" + (is_cooldown_over(last_long_alert_time, alert_cooldown_minutes) and is_cooldown_over(last_short_alert_time, alert_cooldown_minutes) ? "OK" : "NO")
|
||||
table.cell(info_table, 11, 3, alert_debug, text_color=color.black, bgcolor=volume_confirm_color, text_size=text_size)
|
||||
@@ -2129,4 +2202,10 @@ if barstate.islast
|
||||
// ✓ 震荡/趋势识别
|
||||
// ✓ 窗口一:K线+MRC+MA
|
||||
// ✓ 窗口二:RSI独立显示
|
||||
// ✓ 表格化数值显示
|
||||
// ✓ 表格化数值显示
|
||||
// ✓ 1-5级成交量过滤系统(参考SRBR源代码逻辑)
|
||||
// - 1级:最温和,只过滤极明显假信号
|
||||
// - 2级:温和,过滤明显假信号
|
||||
// - 3级:中等,标准过滤强度
|
||||
// - 4级:严格,较强过滤
|
||||
// - 5级:最严格,参考SRBR高低成交量阈值
|
||||
Reference in New Issue
Block a user