OPEN-SOURCE SCRIPT

HMA ZXZ

83
//version=5
// 显式指定 scale 绑定到价格轴
indicator("HMA 趋势提醒指标 - 织心者优化版", overlay=true, scale=scale.none)

// --- 输入参数 ---
hma_length = input.int(20, "HMA 周期长度", minval=1)
src = input(close, "价格源")
show_labels = input.bool(true, "显示买卖标签")

// --- HMA 核心算法 ---
hma_func(source, length) =>
wma_1 = ta.wma(source, math.floor(length / 2))
wma_2 = ta.wma(source, length)
ta.wma(2 * wma_1 - wma_2, math.floor(math.sqrt(length)))

hma_value = hma_func(src, hma_length)

// --- 趋势与颜色判断 ---
is_up = hma_value > hma_value[1]
line_color = is_up ? color.new(#00ff08, 0) : color.new(#ff0055, 0)

// 绘制 HMA 主线
plot(hma_value, title="HMA 主线", color=line_color, linewidth=3)

// --- 信号逻辑 ---
long_signal = is_up and not (hma_value[1] > hma_value[2])
short_signal = not is_up and (hma_value[1] > hma_value[2])

// --- 视觉标注 ---
plotshape(long_signal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="看多拐点")
plotshape(short_signal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="看空拐点")

if show_labels
if long_signal
label.new(bar_index, low, "B", color=color.green, textcolor=color.white, style=label.style_label_up, size=size.tiny)
if short_signal
label.new(bar_index, high, "S", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.tiny)

// 警报
alertcondition(long_signal, title="HMA 向上", message="HMA 转多")
alertcondition(short_signal, title="HMA 向下", message="HMA 转空")

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.