-
- //@version=5
-
- indicator(title='Market Bias (CEREBR) - 市场偏见 (CEREBR)', shorttitle='市场偏见', overlay=true)
-
-
-
- //#region -----> 输入、函数
-
-
-
- // 函数
-
- //@function 此函数强制输入时间框架不得低于当前图表时间框架
-
- FORCE_CTF(str_tf) =>
-
- i_tf_sec = timeframe.in_seconds(str_tf)
-
- ctf_sec = timeframe.in_seconds('')
-
-
-
- // 如果输入时间框架低于当前图表时间框架,返回当前时间框架
-
- i_tf_sec < ctf_sec ? '' : str_tf
-
- //
-
-
-
- // 输入
-
- ha_htf = FORCE_CTF(input.timeframe('', '时间框架', tooltip="此时间框架必须等于或大于图表时间框架", group="Heikin Ashi 市场偏见"))
-
- ha_len = input(100, '周期', group="Heikin Ashi 市场偏见")
-
- ha_len2 = input(100, '平滑', group="Heikin Ashi 市场偏见")
-
-
-
- show_ha = input.bool(true, "显示 Heikin Ashi K线", inline='ha/mb display', group='显示设置')
-
- show_mb = input.bool(true, "显示市场偏见", inline='ha/mb display', group='显示设置')
-
- col_bull = input.color(color.lime, '颜色:看涨', inline='bull/bear color', group='显示设置', display=display.none)
-
- col_bear = input.color(color.red, '看跌', inline='bull/bear color', group='显示设置', display=display.none)
-
-
-
- // 在导入数据时添加偏移以避免前视偏差
-
- indexHighTF = timeframe.in_seconds(ha_htf) == timeframe.in_seconds('') ? 0 : barstate.isrealtime ? 1 : 0
-
- indexCurrTF = timeframe.in_seconds(ha_htf) == timeframe.in_seconds('') ? 0 : barstate.isrealtime ? 0 : 1
-
-
-
- //@function 处理从其他时间框架导入数据,同时防止重绘
-
- //@param _resolution (str) : 要导入数据的目标时间框架
-
- //@param _expression (float | int) : 要导入的数据
-
- f_no_repaint_request(string _resolution, _expression) =>
-
- request.security(syminfo.tickerid, _resolution, _expression[indexHighTF])[indexCurrTF]
-
- //#endregion
-
-
-
- //#region -----> 计算
-
-
-
- // 平滑 OHLC 值
-
- o = ta.ema(open, ha_len)
-
- c = ta.ema(close, ha_len)
-
- h = ta.ema(high, ha_len)
-
- l = ta.ema(low, ha_len)
-
-
-
- // 计算 Heikin Ashi OHLC 值
-
- haclose = f_no_repaint_request(ha_htf, (o + h + l + c) / 4)
-
- xhaopen = f_no_repaint_request(ha_htf, (o + c) / 2)
-
- haopen = na(xhaopen[1]) ? (o + c) / 2 : (xhaopen[1] + haclose[1]) / 2
-
- hahigh = math.max(h, math.max(haopen, haclose))
-
- halow = math.min(l, math.min(haopen, haclose))
-
-
-
- // 平滑 Heikin Ashi K线
-
- o2 = f_no_repaint_request(ha_htf, ta.ema(haopen, ha_len2))
-
- c2 = f_no_repaint_request(ha_htf, ta.ema(haclose, ha_len2))
-
- h2 = f_no_repaint_request(ha_htf, ta.ema(hahigh, ha_len2))
-
- l2 = f_no_repaint_request(ha_htf, ta.ema(halow, ha_len2))
-
-
-
- ha_avg = (h2 + l2) / 2
-
-
-
- // 振荡器
-
- osc_len = input.int(7, "振荡器周期", group="Heikin Ashi 市场偏见")
-
- osc_bias = 100 * (c2 - o2)
-
- osc_smooth = ta.ema(osc_bias, osc_len)
-
-
-
- sigcolor = switch
-
- (osc_bias > 0) and (osc_bias >= osc_smooth) => color.new(col_bull, 35)
-
- (osc_bias > 0) and (osc_bias < osc_smooth) => color.new(col_bull, 75)
-
- (osc_bias < 0) and (osc_bias <= osc_smooth) => color.new(col_bear, 35)
-
- (osc_bias < 0) and (osc_bias > osc_smooth) => color.new(col_bear, 75)
-
- => color(na)
-
- //#endregion
-
-
-
- //#region -----> 绘图、警报
-
-
-
- // 绘图
-
- p_h = plot(h2, "偏见高点", color=color(na), display=display.data_window, editable=false)
-
- p_l = plot(l2, "偏见低点", color=color(na), display=display.data_window, editable=false)
-
- p_avg = plot(ha_avg, "偏见平均", color=color(na), display=display.data_window, editable=false)
-
- fill(p_l, p_h, show_mb ? sigcolor : na)
-
-
-
- col = o2 > c2 ? col_bear : col_bull
-
- plotcandle(o2, h2, l2, c2, title='平滑 Heikin Ashi', color=col, display=show_ha ? display.pane : display.data_window, editable=false)
-
-
-
- // 警报
-
- // 看涨趋势切换(看跌 -> 看涨)
-
- alertcondition(ta.change(ta.change(math.sign(osc_bias)) > 0),
-
- '看涨趋势切换(看跌 -> 看涨)', '{{exchange}}:{{ticker}}: 趋势现为看涨。')
-
-
-
- // 看涨趋势增强
-
- alertcondition(osc_bias > 0 and ta.change(math.sign(osc_bias - osc_smooth)) > 0,
-
- '看涨趋势增强', '{{exchange}}:{{ticker}}: 看涨趋势现更强。')
-
-
-
- // 看涨趋势减弱
-
- alertcondition(osc_bias > 0 and ta.change(math.sign(osc_bias - osc_smooth)) < 0,
-
- '看涨趋势减弱', '{{exchange}}:{{ticker}}: 看涨趋势现较弱。')
-
-
-
- // 看跌趋势切换(看涨 -> 看跌)
-
- alertcondition(ta.change(ta.change(math.sign(osc_bias)) < 0),
-
- '看跌趋势切换(看涨 -> 看跌)', '{{exchange}}:{{ticker}}: 趋势现为看跌。')
-
-
-
- // 看跌趋势增强
-
- alertcondition(osc_bias < 0 and ta.change(math.sign(osc_bias - osc_smooth)) < 0,
-
- '看跌趋势增强', '{{exchange}}:{{ticker}}: 看跌趋势现更强。')
-
-
-
- // 看跌趋势减弱
-
- alertcondition(osc_bias < 0 and ta.change(math.sign(osc_bias - osc_smooth)) > 0,
-
- '看跌趋势减弱', '{{exchange}}:{{ticker}}: 看跌趋势现较弱。')
-
- //#endregion
-
-
-
- // 自定义警报:要启用此功能,请选择并取消以下代码块的注释(Cmd (或 Ctrl) + /),从下一行开始。
-
- // // {
-
- // use_custom_alerts = input.bool(false, '使用自定义警报消息', group='警报消息', display=display.none)
-
- // i_alert_bull_trend_switch = input.text_area('新看涨趋势', '看涨趋势切换', group='警报消息', display=display.none)
-
- // i_alert_bull_trend_strengthen = input.text_area('新强看涨趋势', '看涨趋势增强', group='警报消息', display=display.none)
-
- // i_alert_bull_trend_weaken = input.text_area('新弱看涨趋势', '看涨趋势减弱', group='警报消息', display=display.none)
-
- // i_alert_bear_trend_switch = input.text_area('新看跌趋势', '看跌趋势切换', group='警报消息', display=display.none)
-
- // i_alert_bear_trend_strengthen = input.text_area('新强看跌趋势', '看跌趋势增强', group='警报消息', display=display.none)
-
- // i_alert_bear_trend_weaken = input.text_area('新弱看跌趋势', '看跌趋势减弱', group='警报消息', display=display.none)
-
-
-
- // // 看涨趋势切换(看跌 -> 看涨)
-
- // if (ta.change(ta.change(math.sign(osc_bias)) > 0))
-
- // alert(i_alert_bull_trend_switch, alert.freq_once_per_bar)
-
-
-
- // // 看涨趋势增强
-
- // if (osc_bias > 0 and ta.change(math.sign(osc_bias - osc_smooth)) > 0)
-
- // alert(i_alert_bull_trend_strengthen, alert.freq_once_per_bar)
-
-
-
- // // 看涨趋势减弱
-
- // if (osc_bias > 0 and ta.change(math.sign(osc_bias - osc_smooth)) < 0)
-
- // alert(i_alert_bull_trend_weaken, alert.freq_once_per_bar)
-
-
-
- // // 看跌趋势切换(看涨 -> 看跌)
-
- // if (ta.change(ta.change(math.sign(osc_bias)) < 0))
-
- // alert(i_alert_bear_trend_switch, alert.freq_once_per_bar)
-
-
-
- // // 看跌趋势增强
-
- // if (osc_bias < 0 and ta.change(math.sign(osc_bias - osc_smooth)) < 0)
-
- // alert(i_alert_bear_trend_strengthen, alert.freq_once_per_bar)
-
-
-
- // // 看跌趋势减弱
-
- // if (osc_bias < 0 and ta.change(math.sign(osc_bias - osc_smooth)) > 0)
-
- // alert(i_alert_bear_trend_weaken, alert.freq_once_per_bar)
-
- // // }
复制代码
Heikin Ashi 市场偏见:
使用双重 EMA 平滑(默认周期 100 和 100)计算 Heikin Ashi OHLC 值,生成平滑 K线,减少市场噪音。
振荡器(默认周期 7)基于平滑 Heikin Ashi 开收盘价差(100 * (c2 - o2))计算市场偏见,平滑后判断趋势强度。
趋势信号:
强看涨:振荡器 > 0 且大于平滑值(浅绿色,透明度 35)。
弱看涨:振荡器 > 0 但小于平滑值(深绿色,透明度 75)。
强看跌:振荡器 < 0 且小于平滑值(浅红色,透明度 35)。
弱看跌:振荡器 < 0 但大于平滑值(深红色,透明度 75)。
多时间框架支持:允许使用高于图表时间框架的数据(通过 FORCE_CTF 和 f_no_repaint_request 防止重绘)。
警报功能:支持趋势切换(看涨/看跌)、趋势增强和减弱警报,可自定义消息。
G-Channel 趋势检测:
使用 AlexGrover 的 G-Channel 算法计算动态上下轨,基于价格波动的高效极值。
看涨:价格突破上轨,仅绘制上轨到中线(默认绿色)。
看跌:价格跌破下轨,仅绘制下轨到中线(默认红色)。
供需区域:
通过枢轴点识别近期高点(HH/LH,供应区域,默认白色,提示卖出)和低点(HL/LL,需求区域,默认蓝色,提示买入)。
支持调整区域框宽度和历史保留数量。
市场结构与枢轴点:
实时显示波段结构标签(HH:更高高点,HL:更高低点,LH:更低高点,LL:更低低点)和 BOS 线。
BOS 检测价格突破 HH/HL(看涨)或 LH/LL(看跌),提示趋势延续。
显示 Zig Zag 模式,突出市场波动路径。
线性回归趋势分析:
计算短期(默认 20 周期)和长期(默认 50 周期)线性回归线,评估趋势方向和强度。
结合成交量线性回归,验证趋势是否得到支持(高成交量支持提示强劲趋势,低成交量预示反转)。
双范围过滤器(TRF):
基于快线(默认 27 周期 EMA)和慢线(默认 55 周期 EMA)的平均值,生成动态范围边界。
价格突破上轨提示买入,跌破下轨提示卖出,优于传统 ATR 设置。
成交量支持:
分析成交量回归斜率,判断趋势动能。
上升趋势中,正向斜率提示强劲动能;下降趋势中,低成交量提示反转风险。
综合信号:
高概率信号需满足:Heikin Ashi 振荡器看涨/看跌、G-Channel 突破、供需区域、线性回归趋势、TRF 信号和成交量支持一致。
示例:看涨信号需价格突破 G-Channel 上轨、在需求区域、Heikin Ashi 振荡器 > 0(强看涨优先)、短期/长期趋势线向上、TRF 上轨突破、成交量回归斜率正向。
视觉设置:
支持自定义 Heikin Ashi K线颜色(默认绿色看涨,红色看跌)、G-Channel 上下轨、供需区域(供应白色,需求蓝色)、BOS 标签、枢轴点标签、Zig Zag 线和 TRF 线颜色。
可启用/禁用 Heikin Ashi K线、Zig Zag、枢轴点标签、BOS、TRF 信号和市场偏见填充。 |