OPEN-SOURCE SCRIPT
HMA ZXZ

//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 转空")
// 显式指定 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 转空")
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.